Skip to content

revert: restore pre-worker process boundaries - #11481

Merged
nwparker merged 1 commit into
mainfrom
nwparker/revert-worker-boundary-merges
Jul 30, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/revert-worker-boundary-merges

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

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

  • The main-thread hang watchdog returns to the ELECTRON_RUN_AS_NODE child used by feat(main): record main-thread hangs so we can measure them #10256, including its plain-Node entry and asarUnpack configuration.
  • The computer-use sidecar again directly owns macOS helper and Linux/Windows provider process startup, timeouts, and temporary files.
  • The macOS helper returns to command/bundle-based peer authorization and explicit termination rather than main-selected peer PID authorization and authenticated-session self-reap.
  • The main-process computer-provider supervisor protocol and lifecycle owners are removed.

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 tests
  • pnpm typecheck
  • pnpm verify:computer-native — 38 Swift tests, native guardrails, helper bundle/signature verification
  • pnpm lint
  • git diff --check
  • Pre-commit oxlint and formatting hooks

AI Review Report

The revert was audited against the six GitHub merge commits and applied in reverse dependency order. Review checked that:

  • all six effort commits are ancestors of current main;
  • no unrelated same-day PRs are included;
  • the inverse patches applied without conflict;
  • later unrelated main commits remain present;
  • watchdog child entry/build/packaging wiring is restored together;
  • computer provider callers, clients, transport, sidecar lifecycle, native helper, tests, and guardrails return together rather than leaving half-migrated imports or protocols;
  • macOS, Linux, and Windows code typechecks after the aggregate removal.

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:

  • main-owned fixed-command provider supervision;
  • exact main-selected macOS peer-PID authorization;
  • authenticated-session helper self-reap and unclaimed deadline;
  • confirmed-exit lifecycle coverage introduced with the supervisor work.

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.

@nwparker
nwparker merged commit 8ad9448 into main Jul 30, 2026
47 checks passed
@nwparker
nwparker deleted the nwparker/revert-worker-boundary-merges branch July 30, 2026 03:01
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 53892916-97d3-4525-8238-41e5de8dc8ae

📥 Commits

Reviewing files that changed from the base of the PR and between fa2f5de and 4888fd9.

📒 Files selected for processing (46)
  • build-plugins/plain-node-entry-guard.ts
  • config/electron-builder.config.cjs
  • config/scripts/electron-builder-config.test.mjs
  • config/scripts/verify-computer-native.mjs
  • electron.vite.config.ts
  • native/computer-use-macos/Sources/OrcaComputerUseMacOS/main.swift
  • native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/AgentPeerAuthorization.swift
  • native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/AgentSessionOwnership.swift
  • native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/AgentEntrypointSourceSafetyTests.swift
  • native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/AgentPeerAuthorizationTests.swift
  • native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/AgentSessionOwnershipTests.swift
  • src/main/computer/computer-provider-supervisor-client.test.ts
  • src/main/computer/computer-provider-supervisor-client.ts
  • 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-provider-supervisor-protocol.ts
  • src/main/computer/computer-sidecar-process.ts
  • src/main/computer/computer-sidecar-termination.ts
  • src/main/computer/desktop-script-provider-bridge.ts
  • src/main/computer/desktop-script-provider-client.ts
  • src/main/computer/desktop-script-provider-errors.test.ts
  • src/main/computer/desktop-script-provider-process-invocation.ts
  • src/main/computer/desktop-script-provider-request-validation.ts
  • src/main/computer/desktop-script-provider-supervisor.test.ts
  • src/main/computer/desktop-script-provider-supervisor.ts
  • src/main/computer/desktop-script-provider-test-harness.ts
  • src/main/computer/macos-native-provider-client.test.ts
  • src/main/computer/macos-native-provider-client.ts
  • src/main/computer/macos-native-provider-paste-validation.test.ts
  • src/main/computer/macos-native-provider-supervisor.test.ts
  • src/main/computer/macos-native-provider-supervisor.ts
  • src/main/computer/macos-native-provider-transport.ts
  • src/main/computer/sidecar-client.test.ts
  • src/main/computer/sidecar-client.ts
  • src/main/computer/sidecar-entry.ts
  • src/main/hang-watchdog/hang-watchdog-child-loop.test.ts
  • src/main/hang-watchdog/hang-watchdog-child-loop.ts
  • src/main/hang-watchdog/hang-watchdog-entry-path.ts
  • src/main/hang-watchdog/hang-watchdog-worker-path.test.ts
  • src/main/hang-watchdog/hang-watchdog-worker-path.ts
  • src/main/hang-watchdog/hang-watchdog-worker-protocol.ts
  • src/main/hang-watchdog/main-thread-hang-watchdog-entry.test.ts
  • src/main/hang-watchdog/main-thread-hang-watchdog-entry.ts
  • src/main/hang-watchdog/main-thread-hang-watchdog.test.ts
  • src/main/hang-watchdog/main-thread-hang-watchdog.ts

📝 Walkthrough

Walkthrough

The 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 execFile with timeout escalation. Computer sidecar IPC management is implemented inline, while obsolete supervisor protocols, lifecycle modules, and associated tests are removed.

✨ Finishing Touches
📝 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.

Comment on lines +1 to +17
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')
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Comment on lines 3632 to 3695
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines 3745 to 3747
if let expectedToken, request.token != expectedToken {
return ["id": request.id, "ok": false, "error": ["code": "permission_denied", "message": "invalid computer-use agent token"]]
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

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

  • Hang watchdog returns to a fork-based ELECTRON_RUN_AS_NODE child process (from worker threads), with a new resolveHangWatchdogEntryPath that correctly rewrites app.asar → app.asar.unpacked for packaged builds; asarUnpack and the builder test are updated to match.
  • macOS helper reverts to command/bundle-based peer authorization (via /bin/ps) and loses the unclaimed-session deadline and authenticated-session self-reap; the sidecar again owns spawn, socket directory lifecycle, and cleanup.
  • Linux/Windows desktop bridge reverts from supervisor IPC to direct execFile with SIGTERM+SIGKILL escalation; DesktopScriptProviderClient constructor now resolves platform and script path eagerly via temp-directory-based operation files.

Confidence Score: 4/5

Mechanically 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).

Important Files Changed

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

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