Skip to content

fix(serve): restart the macOS serve supervisor from the updated app - #31200

Merged
Jinwoo-H merged 6 commits into
mainfrom
jinwoo/serve-supervisor-reexec-after-update
Oct 21, 2026
Merged

Jinwoo-H merged 6 commits into
mainfrom
jinwoo/serve-supervisor-reexec-after-update

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​353 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​352
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​122 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​114

ELI5

On a Mac, orca serve has 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

  • Before: after a remote or automatic update, the supervisor stayed on the deleted executable. Computer use failed (permission_denied), screencapture failed, and the system log repeated proc_pidpath_audittoken() failed ... No such file or directory. It lasted until someone restarted the supervisor, and it recurred on every update.
  • After: once an update has replaced the app, the supervisor replaces itself in place (same process id) with the newly installed executable before it starts any server. Nothing about launchd or the running terminals and agents changes, and their permissions work again.
    • One check, at the one place every server start passes: the spawn function in 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 --supervise service. It runs after each path's stop and pause checks, while no server child is alive.
    • "Replaced" means the executable file changed (device and inode) since this process started. After the restart they match, so it can't loop.
    • The update record stays "install requested" across the restart. The existing startup resume path then starts the new server, checks its version and completes the update.
    • Plain orca serve re-runs with its original arguments.
    • orca serve --supervise runs 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.
    • Before exec it checks that the installed executable can run and that the CLI entry exists. A failed process.execve aborts the process instead of throwing, so on a failed check it logs and keeps the old executable, as before.
    • Applies only on macOS when serving Orca's own executable. Linux, Windows, AppImage, orcad and overridden executables are unchanged.
    • The restart lives in serve-replaced-app-restart.ts. serve-update-supervisor.ts is 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:

  • Exit and let launchd restart the supervisor. This only works when the LaunchAgent sets KeepAlive, it can race the app swap, and no process is left to report whether the update succeeded.
  • Run the supervisor's executable from a stable copy outside the app. The whole app would need copying, and copies need lifetime bookkeeping so cleanup never deletes one in use, which brings the same bug back. That's a much larger change for the same result.

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:

Step Child's Accessibility / Screen Recording
Supervisor running from its bundle granted / granted
Bundle moved aside and deleted, as the installer does denied / denied
Supervisor replaced itself in place from the new bundle granted / granted, for children started before and after

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

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New tests drive everything through serveOrcaApp, with the exec call stubbed (launch-serve-replaced-app-restart.test.ts). They cover:

  • the first start, and the restart after a remote install. The update record is still "install requested" when the restart runs.
  • no restart and no spawn while a stop is pending;
  • resuming an interrupted update, with a real file swap during the wait. The process restarts when its executable was replaced, and doesn't restart once it's already on the installed one.
  • a supervised service's next attempt after its app was replaced (the desktop Update & Restart path);
  • no restart when serving an executable other than Orca's own.

serve-supervisor-relocation.test.ts covers:

  • a relocated --supervise supervisor re-running from the app's CLI entry;
  • one code copy kept across three updates under one live PID;
  • the pre-exec check falling back, both for an executable that can't run and for a missing CLI entry.

Mutation checks:

  • with the check removed from the spawn, 5 tests fail;
  • with the start identity taken per attempt instead of at process start, the next-attempt test fails.

src/cli/runtime passes 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 serve under a LaunchAgent with a throwaway identity and profile, through a real installer swap.

  • With main installed, the supervisor is left on the deleted executable (codesign --hosting → "No such file or directory").
  • With this branch installed, it runs the installed app (codesign --hosting valid), keeps its PID, and completes the update; the terminal opened before the update survives.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Cross-platform: macOS only, gated on an update record, which exists only for a macOS app bundle, and on serving Orca's own executable.
  • SSH / remote: this is the remote-server update path; paired clients see the same update flow and result.
  • Backwards compatibility: the update record format is unchanged. A supervisor from an older release finishes its update the old way.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7831d7c8-8b1e-43fe-bdee-c94d5a9a47ee
📥 Commits

Reviewing files that changed from the base of the PR and between 7204ff8 and 7c8bad7.

📒 Files selected for processing: 2
  • src/cli/runtime/serve-supervisor-relocation.test.ts
  • src/cli/runtime/serve-supervisor-relocation.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The serve supervisor now records its startup executable identity and checks whether the installed executable has changed during eligible macOS update launches. When it detects a replacement, it validates the executable and CLI entry, then replaces its process with reconstructed arguments and environment. Relocated supervisors release their previous snapshot claim. The changes also add tests for restart conditions, launch ordering, handoff behavior, and shutdown.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 7c8ba

The supervisor restart path is consistent with the intended macOS update behavior, and no merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: restarting the macOS serve supervisor from the updated app.
Description check Passed The description follows the required template and provides clear ELI5, change, rationale, issue, visual proof, testing, compatibility, and checklist details. It reports that the full pnpm checks will …
Linked Issues check Passed Issue #31022 requires the macOS serve supervisor to stop running from the deleted pre-update bundle after an update. serveOrcaApp records the startup executable identity. spawnElectronServe checks…
Out of Scope Changes check Passed The reviewed changes are limited to the serve launch path, supervisor relocation support, and related automated tests. The relocation cleanup and argument handling support re-execution after an app up…
Full details: Description check

Explanation

The description follows the required template and provides clear ELI5, change, rationale, issue, visual proof, testing, compatibility, and checklist details. It reports that the full pnpm checks will be covered by CI, and the empty Review section is non-critical.

Full details: Linked Issues check

Explanation

Issue #31022 requires the macOS serve supervisor to stop running from the deleted pre-update bundle after an update. serveOrcaApp records the startup executable identity. spawnElectronServe checks for a replaced identity before each server start when serving Orca's own executable. restartServeSupervisorIfReplaced validates the installed executable and CLI entry, then re-execs in place with execve, preserving the PID. The implementation clears relocation state and releases the old snapshot for relocated supervisors. The tests cover remote and interrupted updates, supervised restarts, ordering, fallback checks, and executable filtering.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to the serve launch path, supervisor relocation support, and related automated tests. The relocation cleanup and argument handling support re-execution after an app update. The changes do not demonstrate unrelated product behavior.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 26713cac-4fb0-4797-9434-66e77d710255
📥 Commits

Reviewing files that changed from the base of the PR and between 8e668c6 and c609bf5.

📒 Files selected for processing: 5
  • src/cli/runtime/launch.ts
  • src/cli/runtime/serve-supervisor-relocation.test.ts
  • src/cli/runtime/serve-supervisor-relocation.ts
  • src/cli/runtime/serve-update-supervisor-restart.test.ts
  • src/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
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

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:

  • orca serve runs under a LaunchAgent;
  • a terminal is opened before the update;
  • the update record is written the way the server writes it;
  • the real installer (ShipIt) swaps the app and deletes the old one.

The supervisor installed before the update is the one under test, because it's the process that has to survive the update.

Check after the update main installed this branch installed
Supervisor PID unchanged unchanged
Supervisor's running executable ShipIt's deleted temp copy (…/T/com.stablyai.orca.hangtest.ShipIt.*/Orca.app/…) the installed app (inode matches the installed executable)
codesign --hosting <supervisor pid> No such file or directory valid
codesign --verify on the supervisor PID No such file or directory dynamically valid
New server reports the target version yes yes
Update record completed and removed completed and removed
Terminal shell started before the update still alive still alive
Dialogs raised none none

The main build reproduces the reporter's exact signature (codesign --hosting → "No such file or directory"). With this branch the supervisor is on the installed app after the update, and nothing is interrupted.

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:

  • a supervisor that started on the old app mid-update;
  • one leftover code copy per update with --supervise;
  • a failed exec aborting instead of falling back;
  • a desktop Update & Restart parking the service.

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
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Re-ran the real-update check on the simplified design (7204ff8). The single check now runs just before every server start. CI-signed builds again, with a LaunchAgent and the real installer swap.

After the update main installed this branch installed
Supervisor PID unchanged unchanged
Supervisor's running executable ShipIt's deleted temp copy the installed app
codesign --hosting <pid> No such file or directory valid
New server reports the target version yes yes
Update record completed completed
Terminal shell started before the update alive alive
Dialogs none none

A fourth review round of the restructure found no actionable issues.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Desktop Update & Restart path, end to end on macOS. A registered orca serve --supervise service (launchd label com.stablyai.orca.serve.*) is parked during the install. Setup:

  • the supervisor is real in each build;
  • the park handshake is the real file protocol, with the desktop side ported line for line from serve-supervisor-install-park.ts;
  • the real installer swap runs, and no update record is written;
  • isolation was checked: a throwaway home, and your real profile and desktop app's coordination folder untouched.
After the desktop update main installed this branch installed
Supervisor PID unchanged unchanged
Supervisor's running executable the deleted old copy the installed app
codesign --hosting <pid> No such file or directory valid
Park handshake acked, committed, no handoff acked, committed, no handoff
Next server reports the target version yes yes
Terminal shell started before the update alive alive
Dialogs none none

Gaps compared with the real desktop:

  • the installer runs without relaunching the app, so no window opens;
  • running apps are listed with lsappinfo instead of the desktop's script call;
  • the installer is started directly instead of through the updater.

Timing note: with this branch, a --supervise service is back about 40 s later after an update than on main. The re-executed supervisor copies the new release's code aside again, which is the #28007 relocation; that copy is about 35 s of the gap. Main skipped that copy only by staying on the deleted executable. Plain orca serve doesn't relocate and isn't affected.

The copy is slow because fs.cp goes file by file, about 5,900 files, under launchd's default throttled class. A single whole-tree clone takes 1 to 6 s. That's a follow-up for the relocation module, and it also speeds up every first start.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Timed desktop Update & Restart runs on macOS: a registered orca serve --supervise service under a LaunchAgent, parked during the install, then the real installer swap. Builds are CI-signed with a throwaway identity, and the runs were back to back under the same machine load.

Update target Swap to serving again
#31200 only (file-by-file code copy) 19 s
#31200 + #31303 (one clone per folder) 8 s and 9 s
main, for reference (no re-launch, permissions broken) 14 s

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
@Jinwoo-H
Jinwoo-H merged commit d7ef774 into main Oct 21, 2026
46 checks passed
@Jinwoo-H
Jinwoo-H deleted the jinwoo/serve-supervisor-reexec-after-update branch October 21, 2026 02:02
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.

[Bug]: macOS supervised orca serve keeps running from the deleted pre-update bundle after a remote update, which breaks TCC attribution for computer use

1 participant