Repository navigation
fix(daemon): sweep hand-typed agent descendants on teardown - #17507
brennanb2025 wants to merge 1 commit into
Conversation
Greptile SummaryThis PR broadens daemon teardown classification so a recognized agent currently running in the foreground receives the existing descendant-sweep cleanup even when Orca did not launch it.
Confidence Score: 5/5The PR appears safe to merge, with teardown remaining scoped by the existing session and process-root ownership safeguards. The change reuses the established descendant-sweep path only when launch metadata or recognized foreground-process evidence identifies an agent, while ordinary shell sessions retain their previous termination path.
|
| Filename | Overview |
|---|---|
| src/main/daemon/agent-teardown-evidence.ts | Introduces a shared predicate combining launch metadata with recognized foreground-process evidence. |
| src/main/daemon/session-termination-controller.ts | Routes hand-typed foreground agents through the existing ownership-guarded descendant sweep. |
| src/main/daemon/terminal-session-teardown.ts | Applies foreground-agent classification consistently to graceful and immediate host teardown. |
| src/main/daemon/session.test.ts | Covers recognized-agent and ordinary-shell foreground behavior through Session.kill(). |
| src/main/daemon/terminal-session-teardown.test.ts | Covers both graceful and immediate teardown for agents typed into otherwise plain shell sessions. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Session teardown requested] --> B{Launch agent recorded?}
B -->|Yes| E[Run descendant sweep]
B -->|No| C[Read foreground process]
C --> D{Recognized agent?}
D -->|Yes| E
D -->|No| F[Use plain-shell termination]
E --> G[Verify root ownership]
G --> H[Terminate descendants and root]
Reviews (1): Last reviewed commit: "fix(daemon): sweep hand-typed agent desc..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughAdded Merge Risk: 🔵 Low · up to Recognized hand-typed agents will now receive descendant cleanup during teardown, improving process cleanup while preserving plain-shell behavior. A bounded POSIX PID-reuse race could occasionally signal an unrelated same-user process, so the PR is mergeable with explicit owner awareness or follow-up to add stable identity checks before the initial termination pass. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description explains the change and motivation, identifies the linked issue, documents testing and reproduction steps, and states why visual proof is not applicable. The content is mostly complete despite omitting several optional template headings and checklist items.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
hasAgentTeardownEvidencehelper — new predicate that treats "recognized agent live in the foreground" as teardown evidence alongsidelaunchAgent, reusing the sharedrecognizeAgentProcessmapper.SessionTerminationController.kill()— swaps the!launchAgentgate for the helper, so a hand-typed agent routes through the descendant sweep instead of the synchronous plain path.TerminalSessionTeardown.killSession()— same swap, covering both graceful and immediate teardown; plain-shell andlaunchAgentsessions keep their prior behavior.- Regression tests —
session.test.ts(shell foreground stays plain, recognized agent foreground sweeps) andterminal-session-teardown.test.ts(it.eachgraceful/immediate hand-typed agent), both using the realrecognizeAgentProcessso they fail under the oldlaunchAgent-only gate.
The change is sound: Boolean(launchAgent) short-circuits so launched-agent sessions never call getForegroundProcess(); the sync getForegroundProcess() is the right choice for the synchronous kill() path; and the Windows immediate path still claims termination before the sweep via beginTermination(). Tests pass (pnpm test src/main/daemon), typecheck and the changed-code quality gate are clean. The recognition is best-effort (an agent under a wrapper must be resolved by the foreground tracker first, and an already-exited agent won't be caught), but that is a documented, pre-existing limitation of the foreground tracker rather than a defect here.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Closing: #33317 fixed this on main (descendants are swept on graceful close of shells without launch metadata). |

Summary
Testing
pnpm test src/main/daemon(1700 passed, 3 skipped; 2 files skipped)pnpm tc:nodepnpm run check:code-quality:changedjobs -pempty while the recordedsleepchild survived and was reparented to PID 1; the PID was terminated afterwardLinear
STA-5947
No Electron/UI evidence applies; this is a daemon process-teardown change.