Skip to content

fix(provider-process): kill a provider group its SIGKILLed supervisor leaves behind - #30997

Merged
nwparker merged 4 commits into
mainfrom
nwparker/provider-supervisor-orphan-cleanup
Oct 20, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/provider-supervisor-orphan-cleanup

Conversation

@nwparker

@nwparker nwparker commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​739 $\color{#cf222e}{\Huge{\mathbf{−}}}$​54 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​685
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​372 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​355

ELI5

Orca starts helper programs (for example a short-lived OpenCode server it asks which models are set up) through a small "babysitter" process. The babysitter stops the helper when the job is done, when it times out, or when Orca quits or crashes. The one case it could not handle was being killed itself with kill -9 (or by the system's out-of-memory killer): then nothing was left to stop the helper, and it kept running in the background forever. Now Orca itself steps in when that happens and stops the leftover helper, after checking it really is the same process it started.

What Changed

Before: on macOS and Linux, if the babysitter process was force-killed, the helper and anything it started kept running with no owner, holding memory and a port until the user found and killed it.

After: Orca stops that leftover helper within a moment of seeing the babysitter die.

How it works:

  • When Orca starts a babysitter, it now opens a small message channel to it. Right after starting the helper, the babysitter sends the helper's process ID over that channel and closes it.
  • Orca immediately looks that process up once, and records it only if the babysitter is still its parent and it still leads its own process group. That parent check proves the ID had not been reused by some other program. Orca also records the process's start time. On Linux it reads that from /proc, which is precise to one clock tick. On macOS, ps reports start times only to the whole second, so if the helper started in the same second as the lookup, Orca checks again after that second ends that the babysitter is still the parent and the group still matches. Otherwise a different process that reused the ID within that second could show the same start time. If the babysitter is gone by then, Orca records nothing.
  • When the babysitter exits for any reason, Orca checks whether the helper's process group still exists. Normally it doesn't, because the babysitter already cleaned up, and nothing more runs. If the group is still there, Orca kills it only if its leader is still running with the recorded start time and group. If the leader is gone, the lookup fails, or the process can't be signalled, Orca leaves the group alone.
  • The babysitter gives the helper /dev/null in place of the channel, so on Linux the helper does not inherit it and keep it open.
  • This covers every launch that already used the babysitter: the OpenCode model check, managed agent sessions (Codex, Claude, ACP, JSON-lines agents, model catalog), Codex app-server sessions, source-control commit-message generation, and the Codex backfill recovery server. The Codex app-server session launcher used to rebuild the spawn options with only three pipes, which dropped the new channel, so it now passes the managed launch's stdio through. If a babysat launch on macOS or Linux ever arrives without the channel, Orca logs a warning once, so a dropped channel can't slip past unnoticed.

Why

Options considered:

  • Orca records each helper and cleans up when the babysitter dies (chosen). Orca is alive in exactly the case the babysitter can't cover, and it can check identity while it still knows for sure the process is its own. Together with the babysitter's existing handling of Orca dying, a helper now needs both Orca and its babysitter killed independently at the same moment before it can be left behind.
  • Sweep at the next Orca launch using a command-line and environment marker. This would only help after a restart, would have to read other processes' environments (expensive, and limited on macOS), and has a higher risk of touching a user's own opencode serve. It also leaves the helper running for the whole session.
  • Learn the helper's ID from a process-table scan or an extra stderr line. A scan has to race the helper's start, and a stderr line would need filtering at every place that reads stderr. A plain extra pipe at a fixed file-descriptor number turned out to be unsafe: when a caller doesn't open that pipe, that number can belong to one of Node's own internal descriptors. A Node message channel is set up only when the caller asks for it, so the babysitter can tell reliably whether anyone is listening.

Windows: there is no babysitter on Windows; providers are started directly and stopped with a tree kill. So the gap this PR fixes does not exist there, and the new code only runs when a babysitter was started (groupReportStdio is empty on win32).

SSH and WSL: the babysitter only runs for local launches on macOS and Linux. Remote providers go through the relay and are not affected. Orca never treats a failed or timed-out lookup as proof that a process exited or is safe to kill.

Linked Issue

N/A (maintainer change).

Visual Proof

N/A: this only affects background process cleanup, so there is nothing new to see in the UI.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New provider-group-orphan-guard.integration.test.ts (POSIX) runs a real babysitter and a helper with a SIGTERM-ignoring grandchild, SIGKILLs the babysitter, and checks that Orca kills both the helper and the grandchild. Instead of fixed sleeps, the test polls until Orca has proven the helper's identity, with a generous timeout. It also checks that a normal stop leaves nothing to clean up, and that the channel closes while the helper is still running (which is what the Linux inheritance fix depends on).

  • New provider-group-guard-launch-paths.test.ts starts a real babysitter through every production launch path and checks that Orca is watching each one. This test failed against the old Codex session launcher.

  • New provider-process-row-read.test.ts covers parsing Linux /proc/<pid>/stat and reading a live process the same way twice.

  • New provider-group-orphan-guard.test.ts unit tests cover: a same-second replacement (the ID points to a stranger once the start second ends, so Orca records nothing and kills nothing), Linux start times skipping the wait, the warn-once for a missing channel, group already gone, matching leader, a leader-less group being left alone, a reused process ID with a different start time or group, a failed lookup, a group this user can't signal, a reported process the babysitter no longer parents, a start in the lookup's own second being looked up again after that second ends (and never recorded if it stays ambiguous), a malformed report, and a launch with no channel.

  • Updated the existing stdio assertions for the extra channel. The provider-process, OpenCode, text-generation, Codex backfill, ACP, and JSON-lines suites pass, including the existing babysitter integration tests. pnpm tc:node, oxlint, and pnpm run check:code-quality:changed pass. I ran these on macOS only; Linux and Windows are covered by CI.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Performance: each babysat launch runs one extra single-process lookup, /proc on Linux and ps on macOS. When the babysitter exits, Orca makes one kill(-pgid, 0) check, and runs a second lookup only if the group is still alive.
  • Compatibility: the babysitter sends its report only when the channel exists, so launches without it behave as before.

Known limits (each one fails safe, meaning Orca kills nothing):

  • If the babysitter is killed before Orca finishes its identity lookup (within the first second or so after launch, or slightly longer when the helper started in the same second as the lookup), the lookup no longer finds the babysitter as the parent. Orca then records nothing and kills nothing for that launch.
  • The identity lookup runs ps asynchronously once per babysat launch on macOS (Linux reads /proc instead), plus one re-read after the start second ends when the start time is ambiguous.
  • If the helper itself has already exited but processes it started are still running in its group, Orca leaves them alone, because with no leader left nothing proves the group is still the one Orca started.
  • If Orca and the babysitter are both killed independently at the same moment, nothing is left to clean up the helper.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The supervisor now reports supervised POSIX provider process-group IDs over IPC. A new guard validates reported groups and sweeps proven orphaned groups after supervisor exit. Codex recovery, OpenCode preflight, managed provider, and source-control agent launches pass the report channel and register the guard. Tests cover sweep outcomes, supervisor behavior, integration scenarios, and platform-specific stdio expectations.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to d3052

The CLI typecheck fails in CI because two new provider-process modules are missing from the shared TypeScript file list. This blocks the build and typecheck workflow until both files are added, but the fix is a small configuration change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 31.03% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: cleaning up a provider process group left behind when its supervisor receives SIGKILL.
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.
Description check Passed The pull request follows the required template and provides clear ELI5, change, rationale, scope, testing, compatibility, security, and checklist details. It correctly marks visual proof as not applic…
Full details: Description check

Explanation

The pull request follows the required template and provides clear ELI5, change, rationale, scope, testing, compatibility, security, and checklist details. It correctly marks visual proof as not applicable and states that the author is a maintainer for the linked issue exception. Manual testing and several full validation commands were not completed locally, but the description documents the tested commands and CI coverage.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7d091b1e-5701-462e-a045-48019b3a401b
📥 Commits

Reviewing files that changed from the base of the PR and between c09af97 and 41176e4.

📒 Files selected for processing: 14
  • src/main/acp/acp-agent-connection.test.ts
  • src/main/codex/codex-state-db-backfill-recovery-process.ts
  • src/main/jsonl-rpc/agent-connection.test.ts
  • src/main/opencode/opencode-launch-model-context.ts
  • src/main/provider-process/managed-provider-process.ts
  • src/main/provider-process/provider-group-orphan-guard.integration.test.ts
  • src/main/provider-process/provider-group-orphan-guard.test.ts
  • src/main/provider-process/provider-group-orphan-guard.ts
  • src/main/provider-process/provider-process-supervisor.test.ts
  • src/main/provider-process/provider-process-supervisor.ts
  • src/main/text-generation/commit-message-text-generation-model-discovery.test.ts
  • src/main/text-generation/source-control-agent-launch.test.ts
  • src/main/text-generation/source-control-agent-launch.ts
  • src/main/text-generation/source-control-local-process.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1c623145-6448-41ff-9b00-5d53f472b849
📥 Commits

Reviewing files that changed from the base of the PR and between 41176e4 and d3052d5.

📒 Files selected for processing: 12
  • src/main/codex/codex-app-server-client.test.ts
  • src/main/codex/codex-app-server-session.ts
  • src/main/codex/codex-state-db-backfill-recovery-process.ts
  • src/main/opencode/opencode-launch-model-context.ts
  • src/main/provider-process/managed-provider-process.ts
  • src/main/provider-process/provider-group-guard-launch-paths.test.ts
  • src/main/provider-process/provider-group-orphan-guard.integration.test.ts
  • src/main/provider-process/provider-group-orphan-guard.test.ts
  • src/main/provider-process/provider-group-orphan-guard.ts
  • src/main/provider-process/provider-process-row-read.test.ts
  • src/main/provider-process/provider-process-row-read.ts
  • src/main/text-generation/source-control-agent-launch.ts

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

@@ -0,0 +1,221 @@
import { hasUnambiguousStartTime } from '../pty-descendant-termination'
import { recordSelfInitiatedTreeKill } from '../crash-reporting/self-initiated-tree-kill-log'
import { readPosixProcessRow, type ProcessRowRead } from './provider-process-row-read'

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
fd -a 'tsconfig.*cli.*json' config
rg -n 'provider-group-orphan-guard|provider-process-row-read|pty-process-table-parser|pty-descendant-termination|self-initiated-tree-kill-log' config/tsconfig*.json

Repository: stablyai/orca

Length of output: 541


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- config/tsconfig.cli.json ---'
nl -ba config/tsconfig.cli.json | sed -n '1,140p'
printf '%s\n' '--- config/tsconfig.tc.cli.json ---'
nl -ba config/tsconfig.tc.cli.json | sed -n '1,140p'
printf '%s\n' '--- direct imports ---'
rg -n -F --glob '*.ts' -e "provider-group-orphan-guard" -e "provider-process-row-read" -e "managed-provider-process" src/main/provider-process config
printf '%s\n' '--- managed-provider-process import block ---'
nl -ba src/main/provider-process/managed-provider-process.ts | sed -n '1,90p'
printf '%s\n' '--- guard import block ---'
nl -ba src/main/provider-process/provider-group-orphan-guard.ts | sed -n '1,35p'

Repository: stablyai/orca

Length of output: 18891


🏁 Script executed:

#!/bin/bash
set -e
rg -n -F --glob 'tsconfig.cli.json' -e '../src/main/provider-process/managed-provider-process.ts' -e '../src/main/provider-process/provider-executable-missing.ts' -e '../src/main/provider-process/provider-spawn-failure-report.ts' -e '../src/main/provider-process/provider-process-close.ts' config

Repository: stablyai/orca

Length of output: 529


Add both provider-process modules to the CLI TypeScript project.

managed-provider-process.ts imports provider-group-orphan-guard.ts, which imports provider-process-row-read.ts. Add both files to the shared CLI file list so the extended CLI typecheck project includes the complete import chain.

Proposed fix
     "../src/main/provider-process/managed-provider-process.ts",
+    "../src/main/provider-process/provider-group-orphan-guard.ts",
+    "../src/main/provider-process/provider-process-row-read.ts",
     "../src/main/provider-process/provider-executable-missing.ts",
🧰 Tools
🪛 GitHub Actions: PR 30997 | source 1300592aae78a16db276f08571250836a76877af | workflow 1300592aae78a16db276f08571250836a76877af | unit full / 13_static analysis and typecheck.txt

[error] 3-3: TypeScript TS6307: Imported file 'provider-process-row-read.ts' is not listed in project 'config/tsconfig.tc.cli.json'. Update the project's file list or include pattern.


[error] 3-3: TypeScript project configuration error: 'provider-group-orphan-guard.ts' is not listed in 'config/tsconfig.tc.cli.json'. Projects must list all files or use an include pattern.

🪛 GitHub Actions: PR 30997 | source 1300592aae78a16db276f08571250836a76877af | workflow 1300592aae78a16db276f08571250836a76877af | unit full / static analysis and typecheck

[error] 3-3: TypeScript TS6307: Imported file 'src/main/provider-process/provider-process-row-read.ts' is not listed in config/tsconfig.tc.cli.json. Add the file to the project file list or use an include pattern.

Source: Pipeline failures

@nwparker
nwparker merged commit 85e690f into main Oct 20, 2026
36 checks passed
nwparker added a commit that referenced this pull request Oct 20, 2026
…rt stacks (#31216)

Fixes bugs found reviewing #30270, #30605, #30885, #30417, #31113, #30415,
#30992 and #30997, and removes code those PRs made unnecessary.

Co-authored-by: Claude <[email protected]>
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