Skip to content

fix(daemon): sweep hand-typed agent descendants on teardown - #17507

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
sta-5947-fix
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
sta-5947-fix

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16

Summary

  • classify teardown as agent-owned when a recognized agent is live in the foreground, even when the session was not launched by Orca
  • route graceful and immediate teardown through the existing descendant sweep while preserving plain-shell behavior
  • add regressions for hand-typed agent and shell foreground paths

Testing

  • pnpm test src/main/daemon (1700 passed, 3 skipped; 2 files skipped)
  • cold pnpm tc:node
  • pnpm run check:code-quality:changed
  • safe zsh reproduction confirmed jobs -p empty while the recorded sleep child survived and was reparented to PID 1; the PID was terminated afterward
  • ablation restored the old launch-only gates and the three new regressions failed; production files were byte-verified restored

Linear

STA-5947

No Electron/UI evidence applies; this is a daemon process-teardown change.

@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown

Greptile Summary

This 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.

  • Adds a shared foreground-agent teardown evidence predicate.
  • Applies that predicate to graceful and immediate session termination.
  • Adds regression coverage for hand-typed agents while preserving plain-shell behavior.

Confidence Score: 5/5

The 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.

Important Files Changed

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]
Loading

Reviews (1): Last reviewed commit: "fix(daemon): sweep hand-typed agent desc..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 68ba7021-c62c-4286-909c-e1687b9ad2ff

📥 Commits

Reviewing files that changed from the base of the PR and between 3d341c1 and f4041a8.

📒 Files selected for processing (5)
  • src/main/daemon/agent-teardown-evidence.ts
  • src/main/daemon/session-termination-controller.ts
  • src/main/daemon/session.test.ts
  • src/main/daemon/terminal-session-teardown.test.ts
  • src/main/daemon/terminal-session-teardown.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Added hasAgentTeardownEvidence to recognize launch agents and recognized foreground agent processes. Updated session termination to use descendant-aware sweeping when evidence exists. Added tests for shell foreground processes, hand-typed claude processes, graceful kills, and immediate kills on Linux.

Merge Risk: 🔵 Low · up to f4041

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: sweeping descendants of hand-typed agent processes during daemon teardown.
Description check ✅ Passed 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…
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • hasAgentTeardownEvidence helper — new predicate that treats "recognized agent live in the foreground" as teardown evidence alongside launchAgent, reusing the shared recognizeAgentProcess mapper.
  • SessionTerminationController.kill() — swaps the !launchAgent gate 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 and launchAgent sessions keep their prior behavior.
  • Regression tests — session.test.ts (shell foreground stays plain, recognized agent foreground sweeps) and terminal-session-teardown.test.ts (it.each graceful/immediate hand-typed agent), both using the real recognizeAgentProcess so they fail under the old launchAgent-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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing: #33317 fixed this on main (descendants are swept on graceful close of shells without launch metadata).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant