Repository navigation
fix(computer-use): reap detached macOS helper processes on teardown - #20926
Conversation
…down path The macOS helper is spawned detached and its ChildProcess handle never left startMacOSNativeProviderSocket(), so the only way to stop a running helper was a `terminate` socket message — which a wedged helper never reads. Every path that abandoned a socket left the process alive, and the next request spawned a replacement, growing without bound (#9141: ~200 helpers in 3h, 40-50GB). Thread the handle back to an owner adopted at spawn time and reap it (SIGTERM, then SIGKILL after a grace period) on every teardown path. Signals target the ChildProcess handle rather than a pid so a recycled pid can never be hit, and a WeakSet makes reaping exactly-once across overlapping paths.
📝 WalkthroughWalkthroughThe change adds owned macOS provider-process reaping. Providers receive Priority: ⬆️ High Merge Risk: 🟡 Moderate · up to A signal-delivery failure can terminate the sidecar and strand a newly spawned helper, so reaping error handling should be fixed before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides a detailed summary, explains the rationale, links issue Resolution Add the missing template sections. State N/A with a reason for Visual Proof if no UI or interaction change exists. Complete the testing and checklist items, and provide the required AI Disclosure and Agent skill upstream boundary information.
✨ 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 80bc70cf-2394-479a-909d-14feab0e779e
📒 Files selected for processing (5)
artifacts/computer-use-helper-reaping-verification.htmlsrc/main/computer/macos-native-provider-client.test.tssrc/main/computer/macos-native-provider-client.tssrc/main/computer/macos-native-provider-process-reaping.tssrc/main/computer/macos-native-provider-transport.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one teardown-path question inline, plus two small notes.
Reviewed changes
- Ownership owner (new) —
macos-native-provider-process-reaping.tsaddsMacOSProviderProcessOwner(adopt/reap) andreapMacOSProviderProcess, which sendsSIGTERMsynchronously, escalates toSIGKILLafterPROVIDER_SIGKILL_GRACE_MSif the handle has not exited, and uses a module-levelWeakSet<ChildProcess>for exactly-once reaping. - Own from spawn, escalate on failed startup —
startMacOSNativeProviderSocketadopts the helper immediately afterspawnProvider(closing the quit-during-startup window) and replaces the bareprovider.kill('SIGTERM')in its catch with the escalating reap, covering connect failures and superseded startups. - Every client teardown path reaps —
MacOSNativeProviderClientowns the provider;cleanupSocketDirectory()becomesreleaseHelperGeneration()(reap, then remove the socket dir);handleTransportErrorandinvalidateActiveSocketAfterWriteFailuremerge intoinvalidateActiveSocket. - Tests — six new cases pin SIGTERM→SIGKILL escalation, exit-clears-escalation, replacement isolation, bare socket-close reap, already-exited skip, and exactly-once reap of a superseded startup.
- Verification report — adds
artifacts/computer-use-helper-reaping-verification.html.
I also ran node_modules/.bin/vitest run src/main/computer/macos-native-provider-client.test.ts — 19 passed. An independent ownership/generation pass found no reachable interleaving where the owner or the transport catch signals a newer, healthy generation.
ℹ️ Scope: this bounds the leak, it does not reduce per-invocation respawn
The fix makes abandoned helpers die at teardown, which caps the unbounded growth described in #9141. It does not change the churn the issue thread emphasizes — macOS still starts a fresh orca-computer-use-macos per attempt rather than reusing one, where the Windows runtime moved to a single persistent helper in #17858. Worth confirming whether reaping is intended as the whole fix, or as the first step before pooling.
Technical details
# Reaping bounds accumulation; helper is still per-invocation
## Affected sites
- `src/main/computer/macos-native-provider-client.ts` — client still tears down and respawns the helper per start/timeout cycle.
- `src/main/computer/macos-native-provider-process-reaping.ts` — new reap primitives only.
## Required outcome
- A human decision on whether #9141 is considered closed by bounded accumulation alone, or whether macOS should follow the persistent-helper approach used on Windows.
## Open questions for the human
- Does the team consider the resource-cost reduction sufficient without pooling, or is pooling planned as a follow-up?ℹ️ Nitpicks
artifacts/computer-use-helper-reaping-verification.htmlintroduces a new top-levelartifacts/directory. The repo already keeps review evidence atdocs/review-evidence/pr-<n>/(e.g.pr-19217/README.md); moving the report there would match the existing convention.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (incremental)
- Verification report removed from the PR —
artifacts/computer-use-helper-reaping-verification.htmlis no longer part of the diff, so the new top-levelartifacts/directory is gone and the report-placement nitpick is addressed. The four source/test files are byte-identical to the previously reviewed revision (per-file TOC hashes unchanged), so the prior review stands.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Force pending helper reaps synchronously on owner exit, clean superseded startup directories on rejection, and honor the shared process import boundary. Add real-process sidecar shutdown regressions and 200-helper resource accounting.
There was a problem hiding this comment.
🟠 Major · Handle signal errors during provider reaping.
src/main/computer/macos-native-provider-transport.ts:111
🩺 Stability & Availability | 🟠 Major | ⚡ Quick winHandle signal errors during provider reaping.
MacOSProviderProcessOwner.adoptreaps the previousnode:child_processChildProcess.reapMacOSProviderProcesscallsprovider.kill('SIGTERM')without checking its return value or handling itserrorevent. After a successful startup, the previous provider's temporary error listener has been removed. If signal delivery fails, Node emits the error asynchronously. The surroundingtryblock cannot catch that event, and an unhandled error can prevent cleanup of the new provider andsocketDirectory.Handle the return value and asynchronous error in
reapMacOSProviderProcess. Movingadoptinto thetryblock does not contain this failure.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: e1c7d195-fa3a-4283-9518-6cadc61f8917
📒 Files selected for processing (7)
src/main/computer/macos-native-provider-client.test.tssrc/main/computer/macos-native-provider-process-reaping.test.tssrc/main/computer/macos-native-provider-process-reaping.tssrc/main/computer/macos-native-provider-reaping.integration.test.tssrc/main/computer/macos-native-provider-startup-cleanup.test.tssrc/main/computer/macos-native-provider-transport.tssrc/main/computer/sidecar-provider-reaping.integration.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/computer/macos-native-provider-client.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Exit-hook force-reap fallback —
reapMacOSProviderProcessnow tracks pending reaps in a module-levelSetand registers a singleprocess.once('exit', forcePendingReaps)while any are outstanding; onprocess.exit()it synchronously SIGKILLs any helper whose 2sunref()'d escalation never got to run. This directly addresses the prior inline concern about sidecar shutdown paths (disconnect/beforeExit, and theSIGTERM/SIGINThandlers insidecar-entry.ts) stranding aSIGSTOPped helper. EachforceReapcleans up its timer,exitlistener, and set entry in afinally, and the listener is removed once the set empties. - Unconditional failed-startup directory cleanup — the transport catch now always calls
cleanupSocketDirectory(socketDirectory), since every attempt owns its ownmkdtempSyncdirectory; the previousisCurrent(socketPath)guard and the now-redundantprovider.kill('SIGTERM')are removed. This matches CodeRabbit's already-resolved suggestion. - Shared process type — the reaping module imports
ChildProcessHandle(alias of Node'sChildProcess) from../../shared/child-process/run-processrather thannode:child_process, satisfying the repo import boundary. - New tests — a resource-bounds unit test (200 concurrent reaps share exactly one
exitlistener; listeners/timers return to baseline on both the exit and escalation paths), a real detached-child integration test (healthy / SIGTERM-ignoring / SIGSTOPped), and a real bundled-sidecar integration test that drives SIGTERM/SIGINT/disconnect and asserts the stopped, SIGTERM-resistant helper is gone.
All prior pullfrog threads are addressed. I ran the changed tests locally on Linux: 23 unit tests and 6 integration tests pass. I also neutralized forcePendingReaps and confirmed all three sidecar-provider-reaping.integration.test.ts cases fail, so that regression test genuinely exercises the exit hook rather than the escalation timer.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ablyai#20926) Reclaim detached macOS computer-use helpers on abandoned requests and transports. Keep ownership from spawn, escalate SIGTERM to SIGKILL, force pending reaps when the sidecar exits, and clean each failed startup's private socket directory. Based on stablyai#14494 by @JuuuuHong. Preserve the original helper ownership/reaping design and regression tests while retaining the upstream line-buffer optimization and adding real-process teardown and resource-bound tests. Fixes stablyai#9141. Co-authored-by: JuuuuHong <[email protected]>

Fixes #9141. Based on #14494 by @JuuuuHong (박주홍), who authored the original diagnosis, helper ownership/reaping implementation, and six regression tests. The original author is preserved in the commit history and will be included as a co-author in the squash merge.
Detached macOS computer-use helpers are owned immediately after spawn and reclaimed when requests time out, startup is superseded, or sockets close/fail. Teardown sends SIGTERM, followed by SIGKILL after two seconds if necessary. If the sidecar exits during that grace period, a shared exit hook synchronously sends SIGKILL to the pending child handles. Superseded startup failures also remove their own unique socket/token directory.
Compared with #14494, this port preserves the newer upstream line-buffer optimization, adds the owner-exit fallback and failed-startup directory cleanup, and uses the shared process type to satisfy the repository import boundary. No docs or artifacts are included in the diff.
Verification
ORCA_BACKGROUND_LAUNCH=1 ./node_modules/.bin/vitest run --config config/vitest.config.ts src/main/computer src/shared/child-process/child-process-import-boundary.test.ts— 183 passed, 4 skipped.The real-process regressions use Node child processes and the real sidecar entry; they do not reproduce the signed native helper's TCC wedge. The fallback handles normal owner exit, signals handled by the sidecar, and IPC disconnect; an owner killed with SIGKILL cannot run exit hooks.