Repository navigation
fix(computer): supervise macOS helper from main - #11441
Conversation
492536e to
e13a637
Compare
📝 WalkthroughWalkthroughThe change adds a supervisor IPC protocol and host/client implementation for supervised macOS provider sessions. A macOS supervisor now starts, claims, releases, and cleans up detached helpers while reporting termination events. Socket transport and native provider client lifecycle handling use session identifiers instead of direct directory cleanup. Sidecar orchestration moves into 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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
🧹 Nitpick comments (7)
src/main/computer/computer-provider-supervisor-host.test.ts (1)
68-77: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest asserts less than its name claims. The "detaches delivery" half is unverified —
sendis attached but never asserted against.♻️ Assert detachment after shutdown
host.shutdown() expect(macOS.shutdown).toHaveBeenCalledTimes(1) + expect( + host.handle({ + channel: COMPUTER_PROVIDER_SUPERVISOR_CHANNEL, + kind: 'request', + id: 2, + method: 'macos.start', + params: {} + }) + ).toBe(true) + await vi.waitFor(() => expect(macOS.start).toHaveBeenCalledTimes(1)) + expect(send).not.toHaveBeenCalled()(make the test
asyncfor thewaitFor.)src/main/computer/computer-provider-supervisor-client.test.ts (1)
99-111: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider covering the
ok: falseresponse path. No test asserts that an error response rejects with the supervisor'scode/message, or thatshutdown()rejects in-flight requests.src/main/computer/macos-native-provider-supervisor.ts (2)
150-162: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
onErrorcan leave a permanent map entry. Whenspawnfails, Node emits'error'with no subsequent'exit', sofinishSessionnever runs and the session lingers inthis.sessionswith its listeners attached.♻️ Reap the session on the error path
this.emitTermination(session, `native macOS helper app failed: ${error.message}`) session.terminating = true - this.deps.clearTimer(session.claimTimer) - this.removeSocketDirectory(session.socketDirectory) try { child.kill('SIGKILL') } catch {} + this.finishSession(session)
235-243: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse the exported channel constant instead of the literal. Import
COMPUTER_PROVIDER_SUPERVISOR_CHANNELfrom./computer-provider-supervisor-protocol(this file already type-imports from it) so the channel has one source of truth.♻️ Proposed change
this.emitEvent({ - channel: 'orca:computer-provider-supervisor', + channel: COMPUTER_PROVIDER_SUPERVISOR_CHANNEL, kind: 'event',-import type { - ComputerProviderSupervisorEvent, - StartedSupervisedMacOSProvider -} from './computer-provider-supervisor-protocol' +import { + COMPUTER_PROVIDER_SUPERVISOR_CHANNEL, + type ComputerProviderSupervisorEvent, + type StartedSupervisedMacOSProvider +} from './computer-provider-supervisor-protocol'src/main/computer/macos-native-provider-supervisor.test.ts (1)
191-219: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a case for
'error'on a registered session. The suite covers the pre-registration error (line 202) but not a live session emitting'error', which is the path that emitssessionTerminatedand where the session is currently left in the map (see theonErrorcomment onmacos-native-provider-supervisor.ts).src/main/computer/macos-native-provider-client.ts (1)
184-204: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winConsider re-checking the generation after the await before adopting the session.
isCurrentis evaluated insidestartMacOSNativeProviderSocket, but the assignments here happen a microtask later. Ifshutdown()(which bumpssocketStartGenerationand clearssocketStartPromise) lands in that gap, this method still installssocketSessionId/socketfor a session nobody will release — leaking the helper process. A guard here makes the ownership handoff self-contained.♻️ Suggested guard
}) + if (this.socketStartGeneration !== startGeneration) { + started.socket.destroy() + void releaseMacOSNativeProviderSocketSession(started.sessionId).catch(() => undefined) + throw new RuntimeClientError( + 'accessibility_error', + 'native macOS provider startup was superseded' + ) + } this.socketSessionId = started.sessionIdsrc/main/computer/computer-sidecar-process.ts (1)
138-146: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winPiped
stdout/stderrare never consumed.
stdio: ['ignore', 'pipe', 'pipe', 'ipc']creates pipes that nothing reads in this class, so a chatty sidecar can fill the OS pipe buffer (~64KB) and block on write. Either drain them into a logger or use'ignore'/'inherit'.♻️ Option: drain to the main-process logs
const child = fork(this.entryPath, [], { stdio: ['ignore', 'pipe', 'pipe', 'ipc'],…then after
fork:child.stdout?.resume() child.stderr?.resume()
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8adfccc1-c2e4-4ac8-80f8-79c635846a10
📥 Commits
Reviewing files that changed from the base of the PR and between b339fe0 and 492536e0c0c9e600bc8de3eab9e8dbd2ec9e5bc7.
📒 Files selected for processing (15)
src/main/computer/computer-provider-supervisor-client.test.tssrc/main/computer/computer-provider-supervisor-client.tssrc/main/computer/computer-provider-supervisor-host.test.tssrc/main/computer/computer-provider-supervisor-host.tssrc/main/computer/computer-provider-supervisor-protocol.tssrc/main/computer/computer-sidecar-process.tssrc/main/computer/macos-native-provider-client.test.tssrc/main/computer/macos-native-provider-client.tssrc/main/computer/macos-native-provider-paste-validation.test.tssrc/main/computer/macos-native-provider-supervisor.test.tssrc/main/computer/macos-native-provider-supervisor.tssrc/main/computer/macos-native-provider-transport.tssrc/main/computer/sidecar-client.test.tssrc/main/computer/sidecar-client.tssrc/main/computer/sidecar-entry.ts
e13a637 to
7f0e9a9
Compare
|
Follow-up review resolution:
One suggestion was intentionally not applied: a registered session is not removed immediately on child Post-fix local verification: 552 computer + PTY tests, typecheck, lint/reliability/max-lines, and diff checks all pass. |
Greptile SummaryThis PR moves ownership of the native macOS computer-use helper process from the long-lived Electron sidecar into the Electron main process, introducing a typed three-operation IPC protocol (
Confidence Score: 5/5Safe to merge. The ownership transfer is well-bounded and every failure path in the PR matrix is exercised by tests. The supervision contract is enforced at every boundary: main chooses the executable and all fixed arguments, session IDs and tokens are generated in main, the protocol validator rejects extra fields, and each lifecycle transition is tested with a dedicated case. The three pre-publish fixes are all present and covered. No logic gaps or unhandled races were found. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/main/computer/macos-native-provider-supervisor.ts | New file: core supervision logic. Owns spawn, PID registration, claim-timer deadline, SIGTERM to SIGKILL escalation, and cleanup. Handles no-PID spawn, pre-spawn token failure, async error listener, and retained-until-exit ownership after forced kill. |
| src/main/computer/computer-sidecar-process.ts | New file: extracted ComputerSidecarProcess with integrated ComputerProviderSupervisorHost. Adds SIGTERM to SIGKILL escalation for the sidecar itself and switches stdio from pipe to ignore to prevent unconsumed-buffer backpressure. |
| src/main/computer/computer-provider-supervisor-host.ts | New file: main-process IPC host routing only the three fixed supervisor operations. Returns false and drops requests after shutdown via sender=null guard. |
| src/main/computer/computer-provider-supervisor-client.ts | New file: sidecar-side IPC client with request timeout, early-termination event buffering capped at 32 entries, and session state tracking. |
| src/main/computer/computer-provider-supervisor-protocol.ts | New file: protocol type definitions with strict runtime validators blocking arbitrary executable/args injection at the IPC boundary. |
| src/main/computer/macos-native-provider-transport.ts | Refactored to delegate spawn/token/dir management to the supervisor client. Adds post-claim isCurrent check for the shutdown-mid-claim race. |
| src/main/computer/macos-native-provider-client.ts | Updated to use sessionId instead of socketDirectory for cleanup. Adds generation check after startMacOSNativeProviderSocket returns for the microtask-queue superseded race. |
| src/main/computer/sidecar-client.ts | Simplified by extracting ComputerSidecarProcess. Adds process.once exit handler for app.exit() safety. |
| src/main/computer/sidecar-entry.ts | Adds supervisor message routing and correct shutdown ordering: providers shut down before supervisor client. |
Reviews (2): Last reviewed commit: "fix(computer): harden supervisor deadlin..." | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5df5ac17-bf6b-4314-9e82-e92bfc535d96
📥 Commits
Reviewing files that changed from the base of the PR and between e13a637ab4864165d05ff216399b058b17bec280 and 7f0e9a9.
📒 Files selected for processing (15)
src/main/computer/computer-provider-supervisor-client.test.tssrc/main/computer/computer-provider-supervisor-client.tssrc/main/computer/computer-provider-supervisor-host.test.tssrc/main/computer/computer-provider-supervisor-host.tssrc/main/computer/computer-provider-supervisor-protocol.tssrc/main/computer/computer-sidecar-process.tssrc/main/computer/macos-native-provider-client.test.tssrc/main/computer/macos-native-provider-client.tssrc/main/computer/macos-native-provider-paste-validation.test.tssrc/main/computer/macos-native-provider-supervisor.test.tssrc/main/computer/macos-native-provider-supervisor.tssrc/main/computer/macos-native-provider-transport.tssrc/main/computer/sidecar-client.test.tssrc/main/computer/sidecar-client.tssrc/main/computer/sidecar-entry.ts
|
Final review disposition: Greptile rated the change safe to merge. Its map-clearing suggestion was rejected because sessions must remain owned until confirmed child exit; its timer-initialization observation cannot publish partial state because timer setup precedes registration. The sidecar SIGTERM and disconnect observations concern pre-existing general sidecar lifecycle behavior: this change synchronously reaps all registered native helpers before signaling the sidecar, and preserving natural disconnect drainage avoids cutting off the sidecar direct terminate fallback after an unexpected parent loss. No remaining finding changes this PR. |
Move native macOS helper process ownership into Electron main while preserving the sidecar as the authenticated socket peer. Add fixed lifecycle IPC, bounded claim and release handling, confirmed-exit tracking, sidecar and helper force-kill escalation, cleanup across failure paths, and focused lifecycle coverage.
Summary
This moves ownership of the native macOS computer-use helper from the long-lived computer sidecar into the Electron main process.
The sidecar can now request only three fixed lifecycle operations:
macos.startmacos.claimmacos.releaseMain resolves the signed helper executable, creates the private socket directory and token, spawns the helper, registers its PID before replying, owns the unclaimed-start deadline, and reaps every registered helper if the sidecar dies. The sidecar remains the socket peer and continues to own the provider protocol/state, preserving the current peer-authorization boundary until the later sidecar worker migration.
This is prerequisite work for replacing the approximately 47 MiB Electron-as-Node computer sidecar with a worker without letting worker termination orphan native descendants. It does not add another process or change when computer use starts.
Ownership and race contract
exit; it is not forgotten merely becauseSIGKILLwas requested.exitsynchronously shuts down the sidecar and supervisor because Electronapp.exit()skips normal quit events.Failure matrix
spawn()returns no PID and later emitserrorSIGTERM, removes private state, then escalates toSIGKILLafter 1 secondSIGKILLto every registered helper and removes private stateScreenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm test— ran the complete computer subsystem suite insteadpnpm build— no bundle configuration or entry-point changesAdditional verification:
pnpm vitest run src/main/computer— 22 files, 554 tests passed (including the PTY integration suite)pnpm verify:computer-nativepwshis unavailable on this hostgit diff --checkCoverage includes protocol allowlisting, malformed metadata, request timeouts, early helper termination, setup/spawn failure, asynchronous spawn errors, claim/release behavior, unclaimed deadlines, graceful-to-force escalation, owner-death cleanup, sidecar queue invalidation, response-delivery failure, stale child/socket events, and large paste validation before startup.
AI Review Report
The review traced authority, IPC validation, session registration, cleanup, concurrency, stale state, partial startup, response delivery, and shutdown ordering.
It flagged and fixed three issues before publishing:
spawn()failure can return no PID and emiterrorasynchronously. Without a temporary listener that would become an unhandled main-process exception. Failed/unowned children now retain a no-op error listener.SIGKILL. Sessions now stay registered until the child actually emitsexit, preserving the supervision contract.Cross-platform review confirmed this new supervisor path is macOS-specific and runtime-selected. Existing Linux and Windows providers,
windowsHide, SSH execution, and folder-workspace behavior are unchanged. New filesystem paths use Node path APIs; no shortcut, label, shell, Git, or provider-specific review behavior changed.Security Audit
0700and token files mode0600.Notes
This PR intentionally preserves the sidecar process and current macOS socket-peer identity. Linux/Windows operation supervision, cross-platform death injection, the sidecar worker conversion, and packaged memory benchmarks remain separate follow-ups in the reviewed boundary migration sequence.