Skip to content

fix(computer-use): reap detached macOS helper processes on teardown - #20926

Merged
nwparker merged 9 commits into
mainfrom
nwparker/computer-use-spawns-200-unmanaged-helper-process
Sep 16, 2026
Merged

nwparker merged 9 commits into
mainfrom
nwparker/computer-use-spawns-200-unmanaged-helper-process

Conversation

@nwparker

@nwparker nwparker commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​479 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​476
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​107 $\color{#cf222e}{\Huge{\mathbf{−}}}$​31 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​76

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

  • Local macOS: 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.
  • Real detached processes: healthy helpers exit on SIGTERM; stopped and SIGTERM-resistant helpers exit on SIGKILL.
  • Real bundled sidecar entry with an injected faulting provider: SIGTERM, SIGINT, and IPC disconnect leave no running helper. All three regressions fail with the exit fallback disabled, and pass with it restored.
  • Two real-filesystem startup-cleanup tests fail before the cleanup fix and pass afterward; the replacement token remains intact.
  • 200 simultaneous pending helpers share one exit listener; listeners and timers return to baseline after exit or escalation.
  • Node typecheck, changed-code-quality gate, process import-boundary tests, and diff checks pass.
  • Independent adversarial review of the final fixes found no further proven defect.

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.

JuuuuHong and others added 8 commits September 15, 2026 18:00
…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.
@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The change adds owned macOS provider-process reaping. Providers receive SIGTERM and, when necessary, SIGKILL after a two-second grace period. Process-exit handling force-reaps pending providers during sidecar shutdown. Socket startup adopts providers immediately and cleans failed startup directories. Client shutdown, socket close, and transport failure paths release helper processes. Unit and integration tests cover escalation, replacement, stale startups, sidecar shutdown, and cleanup.

Priority: ⬆️ High

Merge Risk: 🟡 Moderate · up to 3af36

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description provides a detailed summary, explains the rationale, links issue #9141, and documents extensive verification. However, it omits several template sections, including explicit ELI5, What… 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 informatio…
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #9141 requires helper processes to be reused or properly reclaimed. This PR implements the reclamation path. MacOSProviderProcessOwner adopts spawned ChildProcess handles, reaps prior genera…
Out of Scope Changes check ✅ Passed The process-reaping module, client and transport integration, startup cleanup, and regression tests directly support issue #9141. The changes do not add unrelated product behavior.
Title check ✅ Passed The title clearly and concisely describes the main change: reaping detached macOS helper processes during teardown.
Full details: Description check

Explanation

The description provides a detailed summary, explains the rationale, links issue #9141, and documents extensive verification. However, it omits several template sections, including explicit ELI5, What Changed, Why, Visual Proof or N/A, AI Disclosure, Review, Notes, Agent skill upstream boundary, and Checklist content.

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.

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

@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: 80bc70cf-2394-479a-909d-14feab0e779e

📥 Commits

Reviewing files that changed from the base of the PR and between ea7902c and 5edfbc1.

📒 Files selected for processing (5)
  • artifacts/computer-use-helper-reaping-verification.html
  • src/main/computer/macos-native-provider-client.test.ts
  • src/main/computer/macos-native-provider-client.ts
  • src/main/computer/macos-native-provider-process-reaping.ts
  • src/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.

@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 critical issues — one teardown-path question inline, plus two small notes.

Reviewed changes

  • Ownership owner (new) — macos-native-provider-process-reaping.ts adds MacOSProviderProcessOwner (adopt/reap) and reapMacOSProviderProcess, which sends SIGTERM synchronously, escalates to SIGKILL after PROVIDER_SIGKILL_GRACE_MS if the handle has not exited, and uses a module-level WeakSet<ChildProcess> for exactly-once reaping.
  • Own from spawn, escalate on failed startup — startMacOSNativeProviderSocket adopts the helper immediately after spawnProvider (closing the quit-during-startup window) and replaces the bare provider.kill('SIGTERM') in its catch with the escalating reap, covering connect failures and superseded startups.
  • Every client teardown path reaps — MacOSNativeProviderClient owns the provider; cleanupSocketDirectory() becomes releaseHelperGeneration() (reap, then remove the socket dir); handleTransportError and invalidateActiveSocketAfterWriteFailure merge into invalidateActiveSocket.
  • 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.html introduces a new top-level artifacts/ directory. The repo already keeps review evidence at docs/review-evidence/pr-<n>/ (e.g. pr-19217/README.md); moving the report there would match the existing convention.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@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 (incremental)

  • Verification report removed from the PR — artifacts/computer-use-helper-reaping-verification.html is no longer part of the diff, so the new top-level artifacts/ 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.

Pullfrog  | Fix it ➔ | View workflow run | Using 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.

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

⚠️ Outside the diff (1)

🟠 Major · Handle signal errors during provider reaping.

src/main/computer/macos-native-provider-transport.ts:111
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Handle signal errors during provider reaping.

MacOSProviderProcessOwner.adopt reaps the previous node:child_process ChildProcess. reapMacOSProviderProcess calls provider.kill('SIGTERM') without checking its return value or handling its error event. After a successful startup, the previous provider's temporary error listener has been removed. If signal delivery fails, Node emits the error asynchronously. The surrounding try block cannot catch that event, and an unhandled error can prevent cleanup of the new provider and socketDirectory.

Handle the return value and asynchronous error in reapMacOSProviderProcess. Moving adopt into the try block 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2abad72 and 3af3683.

📒 Files selected for processing (7)
  • src/main/computer/macos-native-provider-client.test.ts
  • src/main/computer/macos-native-provider-process-reaping.test.ts
  • src/main/computer/macos-native-provider-process-reaping.ts
  • src/main/computer/macos-native-provider-reaping.integration.test.ts
  • src/main/computer/macos-native-provider-startup-cleanup.test.ts
  • src/main/computer/macos-native-provider-transport.ts
  • src/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.

@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

  • Exit-hook force-reap fallback — reapMacOSProviderProcess now tracks pending reaps in a module-level Set and registers a single process.once('exit', forcePendingReaps) while any are outstanding; on process.exit() it synchronously SIGKILLs any helper whose 2s unref()'d escalation never got to run. This directly addresses the prior inline concern about sidecar shutdown paths (disconnect/beforeExit, and the SIGTERM/SIGINT handlers in sidecar-entry.ts) stranding a SIGSTOPped helper. Each forceReap cleans up its timer, exit listener, and set entry in a finally, 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 own mkdtempSync directory; the previous isCurrent(socketPath) guard and the now-redundant provider.kill('SIGTERM') are removed. This matches CodeRabbit's already-resolved suggestion.
  • Shared process type — the reaping module imports ChildProcessHandle (alias of Node's ChildProcess) from ../../shared/child-process/run-process rather than node:child_process, satisfying the repo import boundary.
  • New tests — a resource-bounds unit test (200 concurrent reaps share exactly one exit listener; 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.

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

@nwparker
nwparker merged commit 07c7606 into main Sep 16, 2026
33 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…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]>
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.

computer-use spawns ~200 unmanaged helper processes/3h, causing 40-50GB+ memory usage and forced restarts

2 participants