Repository navigation
fix(notifications): harden credentials retrieval, cooldown memory leak, malformed segment validation, and health observability - #14260
Conversation
…tion and health - Retrieve OpenAI and OMI integration credentials dynamically rather than failing fatally on module import - Evict expired notification cooldown timestamps during session buffer cleanup to prevent memory leaks - Filter and normalize segment payloads against None and non-dict/non-string items - Add fail-fast fallback handling in get_openai_response when OpenAI client is unconfigured - Validate recipient UID and message payload before dispatching OMI notifications - Modularize webhook trigger and question processing to remain within architecture limits - Expose /health and /status endpoints and sanitize setup-status exception details - Expand test suite with 15 hermetic hardening tests (22 total tests passing in 0.028s)
|
Reviewed in depth and verified against the actual files at the head commit - this is a genuinely useful hardening pass on the notifications plugin, and the expanded hermetic tests (22/22 pass with credentials stripped) lock in every claimed fix. What I verified:
Two non-blocking notes for a follow-up, neither worth blocking on:
One behavior change maintainers should be aware of (not a defect): without credentials the plugin now boots and answers with a canned fallback instead of failing fast. That is the right trade-off for this sub-app, and the new Coverage suggestions if you want to strengthen further: a two-call test asserting buffer reset semantics after dispatch ( Thanks for the clean, well-scoped fix and the disciplined test work. This feedback is from an automated review assistant acting for the maintainers; human maintainer sign-off is still required before merge (credential-handling behavior change). by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Reviewed both files at head 9f4279e. Verdict: approve.
- Lazy credential handling (
get_openai_client/get_omi_credentials) replaces the import-timeraise ValueErrors — the plugins service can now boot without OPENAI/HEY_OMI env set, and unconfigured calls degrade toFALLBACK_OPENAI_RESPONSE/ False instead of crashing. - Memory:
cleanup_old_sessionsnow also prunesnotification_cooldowns(incl. orphaned timestamps) alongside expired buffers — the cooldown dict previously grew forever. _extract_segments_textdrops non-dict/non-str/empty segments before processing; webhook validates session_id and strips ids.setup_statusno longer echoes raw exception text into a 500; health/status/setup report only booleans, no secret material. Retry semantics unchanged (decorator moved onto_dispatch_openai_completion, still caught → fallback).- Trigger/question-aggregation logic is behavior-preserving vs the #13545 fix; the trigger-step skip is expressed via
was_detected_beforeinstead ofcontinue, equivalent. - Verified locally at head:
python3 plugins/notifications/test_hey_omi_extraction.py→ 22/22 OK (hermetic; requests/openai stubbed before import). Suite is CI-wired viahey-omi-question-extraction-tests.
CI green on this head, merge-tree clean, no review threads.
Fixes #14259
Summary
Hardens
plugins/notifications(hey_omi.py) with dynamic and lazy credential access, memory leak elimination for session cooldowns, malformed segment filtering, OpenAI fallback protection, validated notification dispatch, and service health observability.Root Cause & Operational Fixes
Fatal Import-Time Exception on Unconfigured Environment Variables:
raise ValueError(...)and eagerOpenAI(...)client instantiation with dynamic accessors (get_openai_api_key,get_openai_client,get_omi_credentials).plugins/main.pyfrom crashing on startup in test or container environments lacking production credentials.printstatements to prevent stdout log pollution.Session Cooldown Memory Leak Elimination:
MessageBuffer.cleanup_old_sessions()to prune matching session cooldown timestamps fromnotification_cooldownsalongside buffers, and sweep any orphaned cooldown records older than 1 hour.Malformed Segment Defense:
_extract_segments_textto cleanly filterNone, non-dict objects, non-string text values, and whitespace-only segments, preventing unhandledAttributeErrorand HTTP 500 errors.Fail-Fast OpenAI Dispatch:
get_openai_responseto immediately return safe fallback when OpenAI client is unconfigured, eliminating thread-blocking exponential retry cycles.Notification Dispatch Validation & Timeout Protection:
send_omi_notificationto verify non-emptyuidandmessagepayloads and valid credentials before dispatching network requests.Observability & Sanity Endpoints:
GET /healthendpoint returning service status and credential readiness.GET /statusendpoint with active session counts, uptime, and configuration status.GET /webhook/setup-status.Comprehensive Hermetic Test Suite:
plugins/notifications/test_hey_omi_extraction.pywith 15 new test cases inHeyOmiHardeningTestscovering all hardening paths.python3 -Sin 0.020s with zero third-party dependencies.Verification
python3 -S plugins/notifications/test_hey_omi_extraction.py: 22 tests passed in 0.020s.python3 -S plugins/oauth/test_client_log_safety.py: 5 tests passed in 1.598s (zero banned logging tokens).bash scripts/pr-preflight --lane ci: 15/15 checks passed in 56.80s with 0 warnings and 0 errors.Failure class (fixes)
Failure-Class: none
Bounty Reward Requested: $50.00 USD
Bounty Payout Destination (PayPal): [email protected]