Skip to content

fix(computer): bind macOS helper to supervised peer pid - #11475

Merged
nwparker merged 1 commit into
mainfrom
nwparker/computer-macos-peer-pid
Jul 30, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/computer-macos-peer-pid

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

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/ps and authorized it when its command contained computer-sidecar.js under 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:

  • Electron main captures the actual child.pid returned by fork() and generation-binds it to the active sidecar.
  • macos.start remains an exact, empty IPC request; the sidecar cannot provide or override its authorized PID.
  • Main passes the fixed PID as --peer-pid when spawning the signed macOS helper.
  • The helper accepts only the exact six launch arguments, validates a positive signed 32-bit PID, and compares it directly with the kernel-reported socket peer PID.
  • The existing random session token remains independently required.
  • /bin/ps, command-substring, parent-process, and bundle-ID authorization are removed from the connection path.
  • Replacement sidecars receive their own PID generation; stale responses remain fenced.
  • A fork that does not report a valid PID is rejected and reaped before any provider request can be accepted.

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 lint
  • pnpm typecheck
  • pnpm 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-macos
  • Added or updated high-quality regression tests
  • pnpm verify:computer-native (49 Swift tests, source guardrails, rebuilt signed helper verification)
  • git diff --check

Focused coverage includes:

  • exact helper launch-argument parsing and PID bounds;
  • exact kernel peer-PID matching;
  • rejection of sidecar-supplied peerPid fields;
  • main-to-helper PID forwarding;
  • replacement sidecar generations receiving replacement PIDs;
  • stale response fencing across shutdown/restart;
  • invalid/missing fork PID rejection and reap;
  • preservation of graceful-to-force sidecar/helper termination;
  • native source guardrails forbidding a return to /bin/ps or computer-sidecar.js authorization.

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:

  • authority originates only from Electron main's child.pid;
  • no sidecar-controlled message can select the PID;
  • the PID and sender are captured from the same owner generation;
  • shutdown and replacement fence stale async responses and events;
  • invalid fork PIDs trigger the existing confirmed-exit-aware termination path;
  • helper sessions remain owned until confirmed exit;
  • the independent random token is still mandatory;
  • macOS-only spawn behavior remains behind the existing provider path;
  • Linux and Windows provider routing and lifecycle behavior are unchanged;
  • no keyboard, label, path-separator, shell, SSH, folder-workspace, or git-worktree behavior is altered.

A speculative timer-only cleanup was explicitly rejected during review: confirmed process exit remains the lifecycle ownership invariant.

Security Audit

  • Input/IPC: macos.start accepts only an exact empty object. Unknown keys, including peerPid, are rejected. Both TypeScript and Swift validate the main-selected PID as a positive signed 32-bit integer.
  • Authentication: a client must match both the kernel-reported socket peer PID and the existing per-session random token. PID matching does not replace token authentication.
  • Command execution: the helper executable and complete argument list remain constructed by Electron main. The sidecar supplies no executable, path, argument, environment, or PID.
  • Process inspection: removes /bin/ps execution and command/bundle string matching from each incoming socket connection.
  • Paths/secrets: private socket-directory and token-file modes, token removal on claim, and existing directory cleanup are unchanged. No token or path is added to telemetry or logs.
  • Lifecycle: invalid children are reaped; replacement generations cannot inherit the prior sidecar's PID; existing claim deadlines, disconnect handling, graceful termination, force escalation, and confirmed-exit ownership remain intact.
  • Dependencies: no dependencies were added.

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

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b949057c-3d89-4d2e-b6e9-d5b9053169ea

📥 Commits

Reviewing files that changed from the base of the PR and between 6b1139f and 0e1d221.

📒 Files selected for processing (13)
  • config/scripts/verify-computer-native.mjs
  • native/computer-use-macos/Sources/OrcaComputerUseMacOS/main.swift
  • native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/AgentPeerAuthorization.swift
  • native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/AgentEntrypointSourceSafetyTests.swift
  • native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/AgentPeerAuthorizationTests.swift
  • src/main/computer/computer-provider-supervisor-host.test.ts
  • src/main/computer/computer-provider-supervisor-host.ts
  • src/main/computer/computer-provider-supervisor-protocol.test.ts
  • src/main/computer/computer-sidecar-process.ts
  • src/main/computer/computer-sidecar-termination.ts
  • src/main/computer/macos-native-provider-supervisor.test.ts
  • src/main/computer/macos-native-provider-supervisor.ts
  • src/main/computer/sidecar-client.test.ts

📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: binding the macOS helper to the supervised peer PID.
Description check ✅ Passed The description follows the template and includes the required sections with substantive details, testing, review, security, and notes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces the macOS helper's previous /bin/ps + command-substring peer authorization with direct kernel-PID matching. Electron main captures the child.pid returned by fork(), validates it as a positive signed 32-bit integer, and passes it as --peer-pid to the signed helper, which then compares it against the kernel-reported getsockopt(LOCAL_PEERPID) value on every new socket connection. The random session token remains a mandatory second factor.

  • AgentPeerAuthorization.swift (new): defines AgentLaunchArguments.parse() with strict 6-argument enforcement and isAuthorizedAgentPeer() for the direct PID comparison, replacing all /bin/ps subprocess calls and bundle-ID/command-substring checks.
  • TypeScript layer: ComputerSidecarProcess, ComputerProviderSupervisorHost, and MacOSNativeProviderSupervisor each validate the PID independently as a positive signed 32-bit integer; invalid fork PIDs are rejected and the child is reaped before any provider request can be accepted.
  • computer-sidecar-termination.ts (new): extracts the graceful-to-SIGKILL termination helper into its own module, reducing the surface of computer-sidecar-process.ts.

Confidence Score: 5/5

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

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "fix(computer): bind macOS helper to supe..." | Re-trigger Greptile

@nwparker
nwparker merged commit 1f2f809 into main Jul 30, 2026
48 checks passed
@nwparker
nwparker deleted the nwparker/computer-macos-peer-pid branch July 30, 2026 02:49
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

1 participant