Repository navigation
fix(computer): bind macOS helper to supervised peer pid - #11475
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (13)
📝 WalkthroughWalkthroughThe macOS agent now receives a required expected peer PID and authorizes connections by comparing it with the kernel-reported peer PID. Supervisor ownership and native helper startup propagate validated process IDs through the sidecar and reject untrusted protocol PID fields. Sidecar startup validates child PIDs and uses a shared termination helper for graceful and forced shutdown. Native, TypeScript, source-safety, routing, lifecycle, and invalid-input tests were expanded accordingly. 🚥 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 |
Greptile SummaryThis PR replaces the macOS helper's previous
Confidence Score: 5/5Safe to merge. The change is macOS-only, well-bounded, and the security model is correctly implemented end-to-end. The PID flows correctly from kernel (fork return value) through TypeScript validation layers and down to the Swift helper's getsockopt(LOCAL_PEERPID) comparison — the sidecar has no opportunity to supply or override the PID value. Each layer validates the pid independently as a positive signed 32-bit integer before mutating any state or spawning processes, and invalid fork PIDs are reaped before attach() is called. The random session token remains a mandatory second factor. Test coverage is thorough: exact argument parsing, out-of-range PIDs, sidecar-supplied peerPid rejection, replacement-generation PID forwarding, and the reap-before-attach path are all exercised. The guardrail checks in verify-computer-native.mjs close the regression path back to /bin/ps or string-matching authorization. No behavioral change on Linux, Windows, or any non-macOS path. Files Needing Attention: No files require special attention. All changed files are straightforward and the most security-critical path — the kernel peer-PID comparison in AgentPeerAuthorization.swift — is the simplest function in the diff.
|
| Filename | Overview |
|---|---|
| native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/AgentPeerAuthorization.swift | New file: defines AgentLaunchArguments.parse() with strict 6-argument enforcement and isAuthorizedAgentPeer() that compares the kernel-reported peer PID directly against the main-selected PID. Logic is simple, correct, and well-tested. |
| native/computer-use-macos/Sources/OrcaComputerUseMacOS/main.swift | Removes all /bin/ps subprocess execution, command-substring, parent-PID, and bundle-ID authorization; threads expectedPeerProcessId through AgentRuntime → SocketListener → isAuthorizedAgentPeer(). Argument parsing replaced with AgentLaunchArguments.parse() strict validator. |
| src/main/computer/computer-sidecar-process.ts | Captures child.pid after fork and validates it (positive signed 32-bit integer) before calling attach(); invalid PIDs trigger failActiveChild + throw before any request is accepted. send() now wraps ensureStarted() in try/catch to convert synchronous throws to rejected promises. |
| src/main/computer/computer-provider-supervisor-host.ts | attach() now takes and validates ownerProcessId; ownerProcessId is captured alongside ownerGeneration in handle() and forwarded to dispatch() → macOS.start(). shutdown() correctly nulls ownerProcessId alongside sender. |
| src/main/computer/macos-native-provider-supervisor.ts | start() takes and validates expectedPeerProcessId, then passes it as --peer-pid string argument to the signed helper. Validation rejects before any private state (temp dir, token file, spawn) is created. |
| src/main/computer/computer-sidecar-termination.ts | New file: direct extraction of the graceful-SIGTERM → SIGKILL escalation function from computer-sidecar-process.ts; no behavioral change, improves modularity. |
| native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/AgentPeerAuthorizationTests.swift | New test file: covers exact argument parsing, rejects missing/reordered/extra args, rejects invalid PIDs (0, -1, overflow), and verifies only exact expected PID is authorized. |
| native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/AgentEntrypointSourceSafetyTests.swift | Adds a source-level guardrail test verifying the exact kernel-peer-PID call site is present and that /bin/ps and computer-sidecar.js strings are absent from the entrypoint source. |
| src/main/computer/computer-provider-supervisor-host.test.ts | Tests updated with ownerProcessId 4321/5432 in all attach() calls; new tests verify replacement-generation PID forwarding and rejection of invalid PIDs (0, -1, 1.5, NaN, 0x80000000). |
| src/main/computer/computer-provider-supervisor-protocol.test.ts | Adds a test confirming that a sidecar-supplied peerPid field in macos.start params causes the protocol validator to reject the message. |
| src/main/computer/macos-native-provider-supervisor.test.ts | All start() calls updated with pid 7654; new test verifies invalid PIDs are rejected before mkdtempSync/spawn are called. |
| src/main/computer/sidecar-client.test.ts | FakeChildProcess gains a pid constructor parameter; supervisorAttachedPids array tracks attach() calls; new test verifies that a fork with undefined pid is rejected and the child is reaped without calling attach(). |
| config/scripts/verify-computer-native.mjs | Adds a guardrail check ensuring AgentLaunchArguments.parse and the kernel peer-PID call site are present and /bin/ps and computer-sidecar.js are absent from the macOS source. |
Sequence Diagram
sequenceDiagram
participant EM as Electron Main
participant SP as ComputerSidecarProcess
participant SH as ComputerProviderSupervisorHost
participant MN as MacOSNativeProviderSupervisor
participant H as macOS Helper (Swift)
EM->>SP: call("capabilities", ...)
SP->>SP: fork() → child
Note over SP: child.pid captured from kernel<br/>(validated: >0, ≤0x7FFFFFFF)
SP->>SH: attach(sender, childPid)
SH->>SH: "validate ownerProcessId > 0 ≤ 0x7FFFFFFF"
Note over SP: sidecar sends macos.start {}
SP->>SH: "handle({ method:"macos.start", params:{} })"
SH->>SH: capture ownerProcessId from attach()
SH->>MN: start(ownerProcessId)
MN->>MN: validate pid bounds
MN->>MN: write token file (mode 0o600)
MN->>H: spawn --agent sock --token-file path --peer-pid pid
Note over H: AgentLaunchArguments.parse()<br/>strict 6-arg validation
H->>H: "getsockopt(LOCAL_PEERPID) == expectedPeerProcessId?"
H->>H: token file match?
H-->>MN: session claimed
MN-->>SH: StartedSupervisedMacOSProvider
SH-->>SP: response forwarded to sidecar
Reviews (1): Last reviewed commit: "fix(computer): bind macOS helper to supe..." | Re-trigger Greptile
Summary
This completes phase 5 of the computer-use process-boundary rollout: authorize the macOS helper against an exact peer PID selected and supervised by Electron main.
The macOS helper previously inspected every connecting process with
/bin/psand authorized it when its command containedcomputer-sidecar.jsunder a trusted Orca/Electron application. That command-substring dependency prevented converting the trusted, long-lived Electron-as-Node sidecar into a lower-RSS worker, because a worker's socket peer is the Electron main process.This change keeps the native helper as the OS automation and crash-isolation boundary while making peer identity explicit:
child.pidreturned byfork()and generation-binds it to the active sidecar.macos.startremains an exact, empty IPC request; the sidecar cannot provide or override its authorized PID.--peer-pidwhen spawning the signed macOS helper./bin/ps, command-substring, parent-process, and bundle-ID authorization are removed from the connection path.This PR does not convert the sidecar to a worker yet. It removes the macOS identity blocker while preserving the helper's session ownership, unclaimed deadline, disconnect self-reap, and main-owned cleanup. Cross-platform owner-death fault injection remains the final gate before the worker migration.
Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm test— ran the more focused computer/main IPC suite instead:pnpm vitest run src/main/computer src/main/ipc/pty.test.ts(24 files, 589 tests)pnpm build— ran the affected native build instead:pnpm build:computer-macospnpm verify:computer-native(49 Swift tests, source guardrails, rebuilt signed helper verification)git diff --checkFocused coverage includes:
peerPidfields;/bin/psorcomputer-sidecar.jsauthorization.AI Review Report
The final staged diff was reviewed in authority-flow order: PID provenance, IPC validation, generation persistence, helper launch, kernel credential comparison, and cleanup/reaping.
No correctness, security, or maintainability findings remain. The review specifically verified:
child.pid;A speculative timer-only cleanup was explicitly rejected during review: confirmed process exit remains the lifecycle ownership invariant.
Security Audit
macos.startaccepts only an exact empty object. Unknown keys, includingpeerPid, are rejected. Both TypeScript and Swift validate the main-selected PID as a positive signed 32-bit integer./bin/psexecution and command/bundle string matching from each incoming socket connection.No follow-up security work is required for this phase. The planned cross-platform owner-death fault-injection gate remains required before replacing the sidecar process with a worker.
Notes