feat(cli) : background RCA email notifications via SMTP#2657
Conversation
Greptile code reviewThis repo uses Greptile for automated review. Before merge, aim for Confidence Score: 5/5 with zero unresolved review threads — see CONTRIBUTING.md. Run a review — add a PR comment with: Give it ~5-10 minutes (sometimes longer) for results, then fix feedback and re-trigger until you reach Confidence Score: 5/5. Optional: automate with the greploop skill. |
|
@greptile review |
Greptile SummaryThis PR introduces session-local background investigations in the interactive REPL and SMTP-based RCA completion notifications. The monkey-patch approach for
Confidence Score: 5/5The change is safe to merge. The architectural shift from global monkeypatching to explicit parameters is well-contained, and the background thread model correctly avoids the dict-lookup race that existed in earlier iterations. All three subsystems (background runner, SMTP delivery, pipeline refactor) are well-isolated and have corresponding tests. The removal of _render_report_patch_lock solves the serialization problem without introducing new shared state. Error handling in _connect_client, send_smtp_report, and the worker thread is symmetric and complete. The only inaccuracy found is that the email stats section may report 0 for tool-call count and loop count because those fields aren't forwarded through the publish_findings event, but this is cosmetic and doesn't affect RCA delivery. app/cli/investigation/investigate.py — the render=False event-collection loop is new, untested by unit tests (only integration-level LLM tests cover it), so any future change to the synthetic event schema in runners.py could silently break background state collection. Important Files Changed
Sequence DiagramsequenceDiagram
participant User as REPL User
participant REPL as Interactive Shell
participant Runner as background_runner
participant Worker as Worker Thread
participant Pipeline as astream_investigation
participant Notify as deliver_background_notifications
participant SMTP as SMTP Server
User->>REPL: /background on
REPL->>REPL: "session.background_mode_enabled = True"
User->>REPL: free-text alert or /investigate
REPL->>Runner: start_background_text_investigation()
Runner->>Runner: create TaskRecord + BackgroundInvestigationRecord
Runner->>Worker: thread.start() (daemon)
Runner-->>REPL: task_id (immediate return)
REPL-->>User: background investigation started
Worker->>Pipeline: "run_fn(render=False, suppress_editor=True)"
Pipeline->>Pipeline: astream_investigation events
Pipeline-->>Worker: final_state
Worker->>Worker: "record.status = completed"
Worker->>Notify: deliver_background_notifications(record, channels)
Notify->>Notify: resolve_effective_integrations()
Notify->>SMTP: send_smtp_report(subject, body)
SMTP-->>Notify: ok/error
Notify-->>Worker: email result
Worker->>Worker: task.mark_completed()
Worker->>REPL: console print complete
User->>REPL: /background use bg-xxx
REPL->>REPL: "session.last_state = record.final_state"
REPL-->>User: background RCA active
Reviews (3): Last reviewed commit: "Fix background runner startup race" | Re-trigger Greptile |
Greptile SummaryThis PR adds session-local background RCA investigations to the interactive REPL and wires up SMTP as the first notification channel, so users can run investigations asynchronously and receive an email summary when they complete.
Confidence Score: 3/5Background investigations share a global threading lock with foreground investigations, meaning a running background job will block the REPL; plus a small race window on /reset can silently kill a worker thread. Two concrete defects in the concurrency model affect the core value of background mode. The global
Important Files Changed
Sequence DiagramsequenceDiagram
participant User as User (REPL)
participant Exec as execution.py
participant Runner as background_runner.py
participant Thread as Daemon Thread
participant Pipeline as astream_investigation
participant Lock as _render_report_patch_lock
participant Notify as background_notifications.py
participant SMTP as smtp_delivery.py
User->>Exec: free-text alert (background mode on)
Exec->>Runner: start_background_text_investigation()
Runner->>Thread: "threading.Thread(target=_worker).start()"
Runner-->>User: background investigation started — task bg-xxx
Thread->>Pipeline: run_investigation_for_session_background()
Pipeline->>Lock: acquire (held for full _merge() duration)
Note over Lock: Foreground investigations block here
Pipeline-->>Thread: final_state dict
Lock-->>Pipeline: release
Thread->>Notify: deliver_background_notifications(record, channels)
Notify->>SMTP: send_smtp_report(body, subject, smtp_ctx)
SMTP-->>Notify: (ok, error)
Notify-->>Thread: results dict
Thread->>User: console.print(background investigation complete — task bg-xxx ready)
Reviews (2): Last reviewed commit: "Add background RCA email notifications v..." | Re-trigger Greptile |
|
@greptile review |
|
🚀 |
Fixes #2654
Describe the changes you have made in this PR -
/background on|off|status|list|show|use|notify .../investigatelaunches into session-local background tasks when background mode is enabled/background use <task_id>smtpintegration with CLI setup, env bootstrap, strict config validation, andopensre integrations verify smtpDemo/Screenshot for feature changes and bug fixes -
Terminal + local Mailpit verification:
{"total":1,"messages":[{"Subject":"OpenSRE RCA complete: bg-local-1","To":[{"Address":"team@example.com"}],"From":{"Address":"opensre@example.com"}}]}Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
smtplib+email.message) so users can plug in any existing relay instead of OpenSRE owning a mail server.background_cmds.pyfor the REPL command surfacebackground_runner.pyfor launching non-rendering background investigations and storing summariessmtp_delivery.pyfor formatting/sending plain-text RCA emailssmtpserviceChecklist before requesting a review
Validation run summary:
make lint✅make format-check✅make typecheck✅make verify-integrations SERVICE=smtp✅make test-covANTHROPIC_API_KEYrequired by existing live routing tests); no change-specific failures were observed before those environment errors