Repository navigation
fix(computer): supervise Linux and Windows desktop providers from main - #11468
Conversation
Greptile SummaryMoves Linux and Windows desktop-provider process ownership from the computer sidecar into Electron main's
Confidence Score: 5/5Safe to merge. The security boundary enforcement is well-reasoned and the process lifecycle is handled correctly at every edge. The supervisor's dual callback+exit synchronization, cancellation-at-every-async-checkpoint, timeout escalation, and stale-response suppression are all exercised by deterministic tests with fake timers and mock deps. The request validator uses per-tool allowed-key whitelists that prevent injection of command, path, args, env, or timeout fields, and the owner-generation guard in the host correctly drops responses from operations that span a shutdown/reattach boundary. No incorrect behavior was found. Files Needing Attention: No files require special attention. The highest-complexity code — desktop-script-provider-supervisor.ts and desktop-script-provider-request-validation.ts — has direct test coverage for every documented edge case.
|
| Filename | Overview |
|---|---|
| src/main/computer/desktop-script-provider-supervisor.ts | New 320-line supervisor owning the full operation lifecycle: async directory creation, child spawning, deadline/force-kill escalation, confirmed-exit requirement before resolving, and idempotent cleanup. The dual callback+exit synchronization logic and cancellation-at-every-async-checkpoint are correct and well-tested. |
| src/main/computer/desktop-script-provider-request-validation.ts | New 277-line whitelist validator covering per-tool allowed-key sets, element/frame shapes, key/modifier syntax, paste limit, and a 17 MiB cap with WeakMap serialization caching to avoid double-JSON on large payloads. Logic is thorough and the tests exercise injection paths and size limits. |
| src/main/computer/computer-provider-supervisor-protocol.ts | Adds the desktop.execute request variant and SupervisedDesktopProviderResult type with strict shape validators. Also fixes messageRecord to reject arrays. |
| src/main/computer/computer-provider-supervisor-host.ts | Adds DesktopScriptProviderSupervisor integration with owner-generation tracking so responses from operations spanning a shutdown+reattach cycle are silently dropped. |
| src/main/computer/computer-provider-supervisor-client.ts | Adds executeDesktopProvider with a 40-second method-specific timeout and validates the returned result shape via isSupervisedDesktopProviderResult before resolving. |
| src/main/computer/desktop-script-provider-bridge.ts | Replaced ~80 lines of local execFile/timeout/kill/temp-file logic with a single executeSupervisedDesktopProvider call. withoutUndefinedValues strips optional undefined fields before the IPC hop. |
| src/main/computer/desktop-script-provider-client.ts | Removes constructor parameters, temp-dir mkdtemp/writeFile/rm calls, and platform/scriptPath helpers — those responsibilities moved to the supervisor. |
| src/main/computer/desktop-script-provider-process-invocation.ts | New file extracting the execution plan, argument construction, and result-shape normalization into pure functions, plus the injectable deps interface for testability. |
| src/main/computer/desktop-script-provider-supervisor.test.ts | New 317-line deterministic test suite covering callback/exit ordering, pre-spawn cancellation, timeout escalation, force-kill cancellation, Windows path, shutdown with live children, and pid-less child handling. |
| src/main/computer/desktop-script-provider-test-harness.ts | Replaces execFile/fs mocks with a mock of executeSupervisedDesktopProvider. The inspectOperation callback now receives the BridgeRequest object directly instead of parsed JSON from the operation file. |
Reviews (2): Last reviewed commit: "test(computer): flush stale supervisor r..." | Re-trigger Greptile
📝 WalkthroughWalkthroughAdds validated 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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: 2
🧹 Nitpick comments (4)
src/main/computer/desktop-script-provider-request-validation.ts (1)
10-10: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winHidden cross-file coupling via
SERIALIZED_REQUESTScache.
isWithinRequestLimit(a size-check predicate) has the side effect of populatingSERIALIZED_REQUESTS, whichserializeDesktopScriptProviderRequestlater consumes when called fromdesktop-script-provider-supervisor.ts'sprepareAndSpawn. This only works because the exact sameBridgeRequestobject reference is threaded from validation through to serialization — nothing documents or enforces that invariant, so a future refactor that clones/copies the request between those two points would silently degrade to a redundantJSON.stringifywith no visible symptom, making the coupling easy to miss.Consider either removing the implicit caching (letting both call sites stringify independently, since payload sizes here are small) or making the reuse explicit (e.g., a short comment stating the invariant, or a dedicated
getOrSerialize(request)accessor used by both sites instead of two loosely-related functions touching a shared WeakMap).Also applies to: 81-88, 218-231
src/main/computer/desktop-script-provider-supervisor.ts (1)
46-73: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
execute()can throw synchronously instead of returning a rejected promise.
desktopProviderExecutionPlan(this.deps)(Line 47) can throw aRuntimeClientErrorbefore thePromiseexecutor is even constructed. Sinceexecute()isn'tasync, that throw escapes as a synchronous exception rather than a promise rejection. It happens to be safely wrapped today because the only caller (dispatchincomputer-provider-supervisor-host.ts) isasync, but that's the caller's accident, not a guarantee of this method's own API contract — any.then()/.catch()-style caller added later would get an uncaught exception instead of a rejection.🛡️ Proposed fix to always return a rejected promise
execute(request: BridgeRequest): Promise<SupervisedDesktopProviderResult> { - const plan = this.executionPlan ?? desktopProviderExecutionPlan(this.deps) - this.executionPlan = plan + let plan: DesktopProviderExecutionPlan + try { + plan = this.executionPlan ?? desktopProviderExecutionPlan(this.deps) + } catch (error) { + return Promise.reject(error) + } + this.executionPlan = plansrc/main/computer/desktop-script-provider-supervisor.test.ts (2)
30-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFixed 8-iteration microtask flush is a fragile magic number.
flushPreparationassumes exactly enough microtask hops to drain the mkdtemp/chmod/writeFile await chain inprepareAndSpawn. It works today, but if the implementation gains anotherawait, this constant would need to grow, and until then assertions could silently run before state fully settles rather than failing clearly.
134-151: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest name promises "environment" reuse coverage that isn't asserted.
This test only checks
platform/resolveScriptPathcall counts andexecFilecall count; it doesn't verify that the cached plan'senv(or the plan object itself) is actually reused across the twoexecute()calls, despite the test description. Consider asserting that bothexecFilecalls received the sameenvreference to actually validate the "caches immutable execution plans" contract.✅ Proposed strengthening
expect(deps.platform).toHaveBeenCalledTimes(1) expect(deps.resolveScriptPath).toHaveBeenCalledTimes(1) expect(deps.execFile).toHaveBeenCalledTimes(2) + const firstEnv = vi.mocked(deps.execFile).mock.calls[0][2]?.env + const secondEnv = vi.mocked(deps.execFile).mock.calls[1][2]?.env + expect(secondEnv).toBe(firstEnv)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5d04aa2f-e4bf-45c3-a281-993b8c8c961a
📒 Files selected for processing (14)
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.test.tssrc/main/computer/computer-provider-supervisor-protocol.tssrc/main/computer/desktop-script-provider-bridge.tssrc/main/computer/desktop-script-provider-client.tssrc/main/computer/desktop-script-provider-errors.test.tssrc/main/computer/desktop-script-provider-process-invocation.tssrc/main/computer/desktop-script-provider-request-validation.tssrc/main/computer/desktop-script-provider-supervisor.test.tssrc/main/computer/desktop-script-provider-supervisor.tssrc/main/computer/desktop-script-provider-test-harness.ts
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a68f851a-b3b0-4569-9ef6-00e2d1707cd7
📒 Files selected for processing (4)
src/main/computer/computer-provider-supervisor-host.test.tssrc/main/computer/desktop-script-provider-bridge.tssrc/main/computer/desktop-script-provider-errors.test.tssrc/main/computer/desktop-script-provider-test-harness.ts
💤 Files with no reviewable changes (1)
- src/main/computer/desktop-script-provider-errors.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/computer/computer-provider-supervisor-host.test.ts
stablyai#11468) * fix(computer): supervise desktop providers from main * fix(computer): remove unreachable provider timeout mapping * test(computer): flush stale supervisor response
Summary
Moves Linux and Windows desktop-provider process ownership out of the long-lived computer sidecar and into Electron main's domain-specific computer-provider supervisor.
This is the next prerequisite after #10256 and #11441 for replacing the trusted Electron-as-Node computer sidecar with a worker without allowing Python or PowerShell operations to survive worker termination.
What changed
Fixed supervisor boundary
desktop.executesupervisor method;BridgeRequest— never a command, executable path, script path, environment, argument list, timeout, output limit, or temporary path;{ stdout, stderr, error }result again in the sidecar;Main-owned operation lifecycle
orca-computer-use-*directory, mode-0600 operation file, 20 MiBexecFileoutput cap, child handle, deadline, termination, confirmed reap, and cleanup;execFilecallback and confirmed child exit before returning a normal result;SIGTERMtoSIGKILLon POSIX, and uses immediate forceful termination on Windows where Node's process termination is already forceful;Sidecar responsibilities retained
The sidecar still owns capability caching, snapshot state, action verification, rendering, JSON response parsing, and provider error mapping. It now sends the domain request to main instead of creating temporary files and spawning Python/PowerShell itself.
Performance notes
Failure and concurrency coverage
New deterministic tests cover:
errorevents;Verification
pnpm vitest run src/main/computer src/main/ipc/pty.test.ts— 24 files, 577 tests passedpnpm typecheckpnpm lint— includes oxlint, type-aware/native audits, reliability gates, max-lines ratchet, skill manifests, and localization checkspnpm verify:computer-native— 44 macOS provider tests, Linux syntax, native argument guardrails, and bundle/signature verification passed; local Windows PowerShell checks were skipped becausepwshis unavailablegit diff --check