Repository navigation
revert: restore pre-worker process boundaries - #11481
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (46)
📝 WalkthroughWalkthroughThe change replaces worker-thread and supervised-provider paths with forked or directly spawned child processes. The hang watchdog now uses IPC and an unpacked entry file. macOS native provider startup uses detached helpers, token files, peer inspection, and temporary-directory cleanup. Desktop provider calls now execute platform-specific scripts through ✨ Finishing Touches📝 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 |
| import { existsSync } from 'node:fs' | ||
| import { join } from 'node:path' | ||
|
|
||
| export function resolveHangWatchdogEntryPath( | ||
| appPath: string, | ||
| isPackaged: boolean, | ||
| pathExists: (candidate: string) => boolean = existsSync | ||
| ): string { | ||
| // Why: ELECTRON_RUN_AS_NODE bypasses asar integration, so the packaged entry must be forked from app.asar.unpacked. | ||
| const basePath = isPackaged ? appPath.replace('app.asar', 'app.asar.unpacked') : appPath | ||
| const adjacentBuildEntry = join(basePath, 'main-thread-hang-watchdog-entry.js') | ||
| // Why: electron-vite's unpackaged appPath is already out/main; appending out/main again would silently disable the watchdog in dev and E2E builds. | ||
| if (!isPackaged && pathExists(adjacentBuildEntry)) { | ||
| return adjacentBuildEntry | ||
| } | ||
| return join(basePath, 'out', 'main', 'main-thread-hang-watchdog-entry.js') | ||
| } |
There was a problem hiding this comment.
Entry-path resolver has no unit tests after old test deletion
hang-watchdog-worker-path.test.ts (which covered packaged, adjacent-dev, and project-root scenarios) was deleted, and main-thread-hang-watchdog.test.ts now mocks fork entirely — it never exercises resolveHangWatchdogEntryPath or checks the first argument passed to fork. The new function introduces a meaningful behavioural change for packaged builds: it replaces app.asar with app.asar.unpacked, which is necessary for ELECTRON_RUN_AS_NODE but was absent from the old worker-path logic. If this substitution were regressed (e.g., the replace call dropped), the watchdog would silently fail to spawn on every packaged build, with no test failing to catch it.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| return result == 0 && pid > 0 ? pid : nil | ||
| } | ||
|
|
||
| private func isAuthorizedAgentPeer(_ pid: pid_t) -> Bool { | ||
| guard let command = processCommand(pid), | ||
| command.contains("/out/main/computer-sidecar.js") | ||
| || command.contains("/Contents/Resources/app.asar.unpacked/out/main/computer-sidecar.js") | ||
| else { | ||
| return false | ||
| } | ||
| if isTrustedOrcaApplication(pid) { | ||
| return true | ||
| } | ||
| guard let parentPid = parentProcessId(pid) else { return false } | ||
| return isTrustedOrcaApplication(parentPid) | ||
| } | ||
|
|
||
| private func isTrustedOrcaApplication(_ pid: pid_t) -> Bool { | ||
| guard let app = NSRunningApplication(processIdentifier: pid), | ||
| let bundleId = app.bundleIdentifier | ||
| else { | ||
| return false | ||
| } | ||
| // Why: dev validation runs from per-worktree wrapper apps with stable | ||
| // Orca-owned bundle ids; the sidecar peer check must still authorize them. | ||
| return bundleId == "com.stablyai.orca" || | ||
| bundleId.hasPrefix("com.stablyai.orca.dev.") || | ||
| bundleId == "com.github.Electron" | ||
| } | ||
|
|
||
| private func parentProcessId(_ pid: pid_t) -> pid_t? { | ||
| guard let output = processField(pid: pid, field: "ppid=") else { | ||
| return nil | ||
| } | ||
| let trimmed = output.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| guard let parentPid = pid_t(trimmed), parentPid > 1 else { | ||
| return nil | ||
| } | ||
| return parentPid | ||
| } | ||
|
|
||
| private func processCommand(_ pid: pid_t) -> String? { | ||
| return processField(pid: pid, field: "command=") | ||
| } | ||
|
|
||
| private func processField(pid: pid_t, field: String) -> String? { | ||
| let process = Process() | ||
| let pipe = Pipe() | ||
| process.executableURL = URL(fileURLWithPath: "/bin/ps") | ||
| process.arguments = ["-p", "\(pid)", "-o", field] | ||
| process.standardOutput = pipe | ||
| process.standardError = Pipe() | ||
| do { | ||
| try process.run() | ||
| process.waitUntilExit() | ||
| guard process.terminationStatus == 0 else { return nil } | ||
| let data = pipe.fileHandleForReading.readDataToEndOfFile() | ||
| return String(data: data, encoding: .utf8) | ||
| } catch { | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| @MainActor |
There was a problem hiding this comment.
isAuthorizedAgentPeer spawns /bin/ps synchronously per connection
Each incoming socket connection now blocks its handling thread on process.waitUntilExit() for a /bin/ps call. The PR description acknowledges this as a deliberately restored pre-effort tradeoff. Worth noting: the check is also susceptible to command-line spoofing — any process whose argument list contains /out/main/computer-sidecar.js passes the processCommand guard. The removed AgentLaunchArguments/exact-PID approach was not susceptible to this. Both facts are documented in the PR's security audit.
| if let expectedToken, request.token != expectedToken { | ||
| return ["id": request.id, "ok": false, "error": ["code": "permission_denied", "message": "invalid computer-use agent token"]] | ||
| } |
There was a problem hiding this comment.
Peer-auth guard widens when
expectedToken is nil
The condition changed from if !authorizedPeer to if expectedToken != nil && !authorizedPeer, which means that if expectedToken is ever nil, both the token check (if let expectedToken, …) and the peer check are skipped — allowing any connecting process to issue requests with no authentication. The startup guard (exit code 2 on missing/empty token) prevents this in practice today, but it is a latent no-auth path if runAgent is ever called with token: nil.
Greptile SummaryThis PR reverts six PRs (#11344, #11425, #11428, #11441, #11468, #11475) that migrated process supervision to Electron's main process, applied in reverse dependency order with inverse patches that applied cleanly. All reverted machinery (supervisor protocol, host/client, session ownership, exact-PID peer auth) is removed together, and the pre-effort direct-spawn/sidecar-owned lifecycle is fully restored.
Confidence Score: 4/5Mechanically clean revert with all six effort commits fully inverted; acknowledged tradeoffs are intentional rollbacks documented in the PR. The revert is structurally complete with no half-migrated imports and a passing test suite. The new resolveHangWatchdogEntryPath introduces a critical app.asar to app.asar.unpacked substitution for packaged builds that has no dedicated unit test after the old tests were deleted; a silent regression there would disable the watchdog on all packaged builds undetected. Files Needing Attention: src/main/hang-watchdog/hang-watchdog-entry-path.ts (no unit test for the new path resolver) and native/computer-use-macos/Sources/OrcaComputerUseMacOS/main.swift (restored command-line peer auth and expectedToken nil widening).
|
| Filename | Overview |
|---|---|
| src/main/hang-watchdog/hang-watchdog-entry-path.ts | New path resolver correctly replaces app.asar with app.asar.unpacked for packaged builds; no dedicated test replaces the deleted hang-watchdog-worker-path.test.ts, and the integration test no longer verifies the path argument to fork. |
| src/main/hang-watchdog/main-thread-hang-watchdog.ts | Reverted from Worker thread to ELECTRON_RUN_AS_NODE child process via fork(); IPC channel, heartbeat interval, and will-quit cleanup are correct. |
| src/main/hang-watchdog/main-thread-hang-watchdog-entry.ts | Entry point migrated from worker_threads to child_process; disconnect handler ensures the watchdog exits when the parent dies. |
| src/main/computer/sidecar-client.ts | ComputerSidecarProcess inlined from deleted computer-sidecar-process.ts; fork, IPC, queue, timeout, and error recovery logic are correct. process.once('exit', shutdown) removed but this restores pre-effort behavior. |
| src/main/computer/macos-native-provider-transport.ts | Supervision reverted to direct spawn from sidecar; socket directory and token file lifecycle is consistent across success, superseded, and failure paths. |
| native/computer-use-macos/Sources/OrcaComputerUseMacOS/main.swift | Peer authorization reverted to command-line inspection via /bin/ps; session ownership and unclaimed-deadline self-reap removed. handleRequest guard change is safe since token is required at startup. |
| src/main/computer/desktop-script-provider-bridge.ts | Bridge reverted from supervisor IPC to direct execFile; dual timeout and SIGTERM+SIGKILL escalation interact correctly. |
| src/main/computer/desktop-script-provider-client.ts | Constructor resolves platform and scriptPath eagerly; temp-directory operation file and finally-block cleanup are correct. |
| config/electron-builder.config.cjs | Adds main-thread-hang-watchdog-entry.js to asarUnpack, consistent with ELECTRON_RUN_AS_NODE fork requirement. |
| config/scripts/electron-builder-config.test.mjs | Test correctly inverted to assert the watchdog entry is in asarUnpack. |
| native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/AgentPeerAuthorization.swift | Deleted: AgentLaunchArguments struct and exact-PID isAuthorizedAgentPeer removed, replaced by command/bundle-based check in main.swift. |
Reviews (1): Last reviewed commit: "revert: restore pre-worker process bound..." | Re-trigger Greptile
Summary
Reverts every PR merged by the coding agent as part of the worker-thread/process-boundary effort. This PR is intentionally left open for the repository owner to review and merge or close.
Reverted in reverse dependency order:
The inverse patches applied cleanly on current
main. Later unrelated commits are preserved.Resulting behavior
ELECTRON_RUN_AS_NODEchild used by feat(main): record main-thread hangs so we can measure them #10256, including its plain-Node entry andasarUnpackconfiguration.This deliberately restores the pre-effort performance and lifecycle state. It therefore also restores the approximately 47 MiB watchdog child cost and the lifecycle gaps those follow-up PRs addressed; those tradeoffs are called out so the revert is reviewed with full context.
Screenshots
No visual change.
Testing
pnpm vitest run --config config/vitest.config.ts src/main/hang-watchdog src/main/computer config/scripts/electron-builder-config.test.mjs— 24 files, 188 testspnpm typecheckpnpm verify:computer-native— 38 Swift tests, native guardrails, helper bundle/signature verificationpnpm lintgit diff --checkAI Review Report
The revert was audited against the six GitHub merge commits and applied in reverse dependency order. Review checked that:
main;maincommits remain present;No unresolved mechanical revert finding remains.
Security Audit
This PR adds no new dependency, input, command, path, or network surface. It does intentionally remove hardening delivered by the reverted PRs:
Those removals are the requested rollback, not newly designed security behavior. The code returns to the state that existed before #11344/#11425 and the subsequent boundary-migration PRs.
Notes
This PR will not be merged by the coding agent. Merge authority remains with the repository owner.