Repository navigation
fix(serve): restart the macOS serve supervisor from the updated app - #31200
Conversation
…heir own module Move-only: the supervisor module is at its line budget, and the handoff file IO is a separate concern from the child supervision loop. Claude-Session: serve-supervisor-reexec
After a remote update on macOS, the node-mode supervisor kept running the old Orca executable, which the installer moved aside and deleted. Under a LaunchAgent the system charges every descendant's privacy permissions (Accessibility, Screen Recording, files) to that supervisor, so once its path no longer resolved, screen capture and computer use failed for the whole served tree while the permission check still reported them granted. Once the new bundle is verified on disk and no stop is pending, the supervisor now re-runs itself in place (same pid) from the installed executable instead of spawning the replacement itself. The handoff stays install-requested, so startup's existing resume path spawns, verifies and completes it. A --supervise supervisor that runs from its copy outside the app restarts through the app's own CLI entry, so it copies the new release aside again rather than mixing old scripts with the new executable. If the re-run fails it logs and starts the replacement as before. Only applies when serving our own executable on macOS; Linux, Windows, orcad and overridden executables are unchanged. Claude-Session: serve-supervisor-reexec
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to
|
Three review fixes on top of the update restart: - Decide the restart by file identity instead of which path observed the install. The supervisor records the device and inode of its executable at start; after any install wait (including resuming an interrupted update at startup) it restarts only if the installed executable is a different file. A supervisor that started on the old app before the swap now restarts too, and the process after a restart never restarts again. - A relocated --supervise supervisor releases its marker on the copy it is leaving, so the next relocation can delete that copy. Before, every update kept one more full copy of the app's scripts for the life of the service. - A failed process.execve aborts the process natively rather than throwing, so the fallback never ran. The restart now checks first that the executable can run and the script entry exists, and otherwise logs and starts the replacement directly as before. Claude-Session: serve-supervisor-reexec
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
26713cac-4fb0-4797-9434-66e77d710255
📒 Files selected for processing: 5
src/cli/runtime/launch.tssrc/cli/runtime/serve-supervisor-relocation.test.tssrc/cli/runtime/serve-supervisor-relocation.tssrc/cli/runtime/serve-update-supervisor-restart.test.tssrc/cli/runtime/serve-update-supervisor.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
…l replaced When the desktop app's Update & Restart parks an `orca serve --supervise` service for another profile, it writes no update handoff for that profile. After the install the service's outer loop just starts its next server, so neither update restart point ran and the supervisor kept the deleted executable. Every server start now runs the same identity check right after the park/stop gate and before spawning, so a supervisor whose executable was replaced restarts in place first. The check is a no-op when the executable is unchanged, so first starts and the process after a restart do not loop. The test drives the real park and commit functions, so the CLI typecheck project now includes that updater module (it imports only shared code). Claude-Session: serve-supervisor-reexec
|
Real-update check on macOS (27.0, Apple Silicon), using CI-signed builds of this branch and of main. Both builds use a throwaway app identity and profile:
The supervisor installed before the update is the one under test, because it's the process that has to survive the update.
The main build reproduces the reporter's exact signature ( The throwaway identity has no Accessibility or Screen Recording grants, so the in-terminal permission probes read denied in both runs and don't tell them apart. The earlier stand-in run in the description covers the granted-permission effect. Separately, three rounds of independent review found four reachable issues, all now fixed:
The last round found nothing actionable. |
…er start passes The restart check ran at three call sites and was threaded through the update loop as a hook, and each review round found another start path it missed. Every path (first start, resumed update, after an install, after a park or crash) spawns its server through the function spawnElectronServe builds, after its stop and park gates, so the check now lives in that spawn and nothing else carries it. The restart moves to its own module, the hook and the handoff-file move it forced are gone, and the tests drive serveOrcaApp instead of the hook. Claude-Session: serve-supervisor-reexec
|
Re-ran the real-update check on the simplified design (
A fourth review round of the restructure found no actionable issues. |
|
Desktop Update & Restart path, end to end on macOS. A registered
Gaps compared with the real desktop:
Timing note: with this branch, a The copy is slow because |
|
Timed desktop Update & Restart runs on macOS: a registered
After every run with #31200 the supervisor kept its PID, ran the installed app, and the terminal opened before the update was still alive. On a busier machine earlier, the #31200-only path took 56–65 s, almost all of it the code copy. The two PRs together bring post-update downtime back to main's level or better. |
…or-reexec-after-update # Conflicts: # src/cli/runtime/serve-supervisor-relocation.test.ts
ELI5
On a Mac,
orca servehas a small parent process that keeps the server running through updates. After an update it started the new server but kept running itself from the old copy of Orca, which the updater deletes. macOS checks that parent to decide what every process under it may do. Once its program is gone, computer use, screen capture and some file access fail for the server, its terminals and its agents, even though Orca still shows the permissions as granted. This PR makes the parent switch itself to the new copy of Orca as part of the update.What Changed
permission_denied),screencapturefailed, and the system log repeatedproc_pidpath_audittoken() failed ... No such file or directory. It lasted until someone restarted the supervisor, and it recurred on every update.spawnElectronServe(launch.ts). That covers the first start, resuming an update interrupted at startup, the restart after a remote install, and the next attempt after the desktop app's Update & Restart paused a--superviseservice. It runs after each path's stop and pause checks, while no server child is alive.orca servere-runs with its original arguments.orca serve --superviseruns from a copy of the CLI code outside the app (feat(serve): run the --supervise supervisor from a copy outside the app #28007). It re-runs through the app's own CLI entry, so the new release is copied aside, and it releases its claim on the copy it leaves.process.execveaborts the process instead of throwing, so on a failed check it logs and keeps the old executable, as before.serve-replaced-app-restart.ts.serve-update-supervisor.tsis unchanged.Why
macOS charges the permissions of every process a launchd job starts to that job's process, and resolves it by executable path. The supervisor is that process for the whole serve tree, so its executable has to stay valid. Alternatives considered:
Replacing the process in place uses the same mechanism #28007 already ships, and keeps every descendant's parent.
A stand-in check on a real Mac, using a signed Orca copy run as a launchd job with a child that probes permissions without prompting:
A middle process whose own executable was deleted kept its permissions while the supervisor stayed valid. That's why terminal services started by the old server recover without a restart.
Linked Issue
Fixes #31022
Visual Proof
N/A: no UI change. The evidence is the process and permission checks above, plus the real-update check in Testing.
Testing
New tests drive everything through
serveOrcaApp, with the exec call stubbed (launch-serve-replaced-app-restart.test.ts). They cover:serve-supervisor-relocation.test.tscovers:--supervisesupervisor re-running from the app's CLI entry;Mutation checks:
src/cli/runtimepasses in full (310 tests).tc:cli,tc:node, oxlint, oxfmt and the changed-code quality gate are clean. Four rounds of independent review: the first three found four reachable gaps, all fixed; the fourth, on the final design, found none.Real update on macOS (results in the PR comment): CI-signed builds of main and of this branch, each running
orca serveunder a LaunchAgent with a throwaway identity and profile, through a real installer swap.codesign --hosting→ "No such file or directory").codesign --hostingvalid), keeps its PID, and completes the update; the terminal opened before the update survives.Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)