Repository navigation
Conversation
|
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)
🚧 Files skipped from review as they are similar to previous changes (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe change adds Merge Risk: ⚪ Minimal · up to This change extends terminal cleanup to hand-typed agent sessions while preserving the existing shell teardown path; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description covers the required core sections, including ELI5, changes, rationale, linked issue, visual proof, testing, AI disclosure, and review context. The omitted Notes and Checklist sections are non-critical because their relevant concerns are addressed elsewhere. Full details: Linked Issues checkExplanation The implementation satisfies issue
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 |
|
I independently reproduced the related #17276 failure on macOS before changing code: non-interactive I linked #17276 to this PR instead of opening a duplicate. The branch is substantially behind current |
…essions Daemon teardown gated the descendant sweep on launchAgent, which is only set by Orca's explicit agent-launch path. A claude/codex the user typed into a plain shell got root-only teardown on tab close, so its detached MCP children (and on the graceful path the whole agent tree) survived as orphans invisible to the orphan reaper. Gate the sweep on teardown evidence instead: launchAgent OR a recognized agent in the live foreground, reusing the foreground tracker that already resolves agents under wrappers. Mirrors the in-process provider's launchAgent-or-recognition union.
06027cb to
b5b6655
Compare
|
Thanks for reproducing this independently — good to have the macOS behavior confirmed on a second machine. Rebase: agreed, and done. The branch was 264 commits behind; it rebases onto current On #17276 — I'd keep it separate from this PR. I don't think this change reaches that population, and I'd rather the issue not read as covered here. Every path this PR touches routes into
#17276 reports its 37 Where this PR does help a #17276-shaped leak is the case where the escaped child is still transitively parented to the PTY root: that now gets swept on tab close for a hand-typed agent, which it didn't before. But the failure #17276 actually reports sits outside the ppid walk by construction, and its ask — provenance for descendants that escape mid-session, visibility on high-resource survivors, and termination on stop/cancel/timeout rather than only on close — needs containment this doesn't provide (a per-session pgid or job object the children can't leave, or a recorded ownership tag). That's a materially bigger change than this teardown gate, so I'd rather land #16714's fix here and take #17276 as a follow-up. For triage: this PR still declares only |
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Greptile SummaryThe PR broadens daemon terminal teardown so sessions with either launch metadata or a recognized foreground agent receive the existing descendant sweep.
Confidence Score: 5/5The PR appears safe to merge, with no concrete changed-code failure identified. The new classification gate reuses guarded descendant termination, preserves the plain-shell path when no agent is recognized, and is covered across both termination entry points.
|
| Filename | Overview |
|---|---|
| src/main/daemon/agent-teardown-evidence.ts | Adds the shared predicate that combines explicit launch metadata with foreground-process recognition. |
| src/main/daemon/session-termination-controller.ts | Routes graceful termination through the existing descendant sweep when agent evidence is present. |
| src/main/daemon/terminal-session-teardown.ts | Applies the same evidence gate to graceful and immediate daemon session teardown. |
| src/main/daemon/session.test.ts | Covers recognized foreground agents and verifies ordinary shell termination remains on the plain path. |
| src/main/daemon/terminal-session-teardown.test.ts | Covers graceful and immediate teardown of hand-typed foreground agents without launch metadata. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Terminal teardown requested] --> B{Launch metadata or recognized foreground agent?}
B -->|Yes| C[Snapshot and terminate descendants]
C --> D[Signal or force-kill PTY root]
B -->|No| E[Use plain-shell teardown path]
Reviews (1): Last reviewed commit: "fix(terminal): sweep descendants when te..." | Re-trigger Greptile
|
Thanks @PeaceTis for the detailed write-up and the leak measurements! This is now fixed on main by #33317 (9b23bd6), which closed #16714. The daemon no longer decides on |
ELI5
If you open a plain terminal in Orca, type
claudeyourself, and later close the tab, the claude process and its MCP servers keep running forever. Orca only knew how to fully clean up agents it launched itself. Now closing the tab cleans up hand-typed agents the same way.What Changed
src/main/daemon/agent-teardown-evidence.ts: teardown treats a session as an agent session whenlaunchAgentis set or a recognized agent is live in the foreground (recognizeAgentProcessover the daemon's existing foreground tracker, which already resolves agents running under wrappers).terminal-session-teardown.tsroutes evidence-bearing sessions throughkillAgentSession(descendant snapshot → SIGTERM → SIGKILL survivors) for both graceful and immediate kills, instead of the root-only / tty-killpgplain-shell paths.session-termination-controller.tsapplies the same gate to the gracefulkill()primitive.terminal-session-teardown.test.tsandsession.test.ts(hand-typed agent foreground → sweep; shell foreground → plain path unchanged).Why
The daemon gated the descendant sweep on
session.launchAgent, which only Orca's explicit agent-launch path sets. A hand-typedclaude/codexgot root-only teardown on tab close:killpgover the controlling tty misses MCP servers thatsetsid()'d away.The leaked sessions still carry agent-ownership evidence, so the Resource Manager's "Kill N orphan terminals" deliberately skips them (#8459 guard) — they're unreclaimable from the UI. The in-process fallback provider already unions
launchAgent || startupAgentRecognitionbefore sweeping (local-pty-provider.ts); this brings the daemon path — where real tab closes land — to the same rule, reusing the existing foreground tracker rather than adding a new probe.Observed on a real workstation: 45
connecteddaemon sessions vs ~12 visible tabs; ~4GB RSS of leakedclaudeCLIs plus ~1.2GB of orphaned MCP servers, some alive 5+ days.Linked Issue
Fixes #16714
Visual Proof
N/A — daemon process-teardown change with no UI or interaction change. Verifiable via
ps/orca terminal listbefore/after closing a tab running a hand-typedclaude(steps below).Testing
Automated:
pnpm test src/main/daemon— 141 files / 1655 tests pass, including new regression tests for the hand-typed-agent sweep (graceful + immediate) and the unchanged plain-shell path.pnpm tc:nodeandoxlintclean.Manual repro for reviewers (macOS): open a plain terminal tab, run
claude(with MCP servers configured), close the tab, then checkps aux | grep -E 'claude|mcp'— before this change the tree survives; after, it is swept.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Implemented with Claude Code (Fable 5); diagnosis, fix, and tests reviewed by the submitter.
Review
Ready for review — no open findings; CodeRabbit reported no actionable comments (merge risk: minimal). The remaining docstring-coverage warning is the generic threshold check, consistent with prior PRs.
Agent skill upstream boundary
N/A — daemon teardown change only; no agent skill files touched.