Skip to content

feat(serve): run the --supervise supervisor from a copy outside the app - #28007

Merged
OrcaWin merged 5 commits into
mainfrom
np/d1e-supervisor-stable-path
Oct 12, 2026
Merged

OrcaWin merged 5 commits into
mainfrom
np/d1e-supervisor-stable-path

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​163 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​163
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​227 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​211

ELI5

orca serve --supervise is the small process a background service runs to keep Orca's server alive. It runs Orca's command-line code straight out of the installed app, and loads parts of that code only when it first needs them. When the desktop app installs an update, it replaces the whole app while the supervisor keeps running. From then on, any code the supervisor loads comes from the new release while the code already loaded is from the old one, all in one process. This PR makes the supervisor run from its own copy of that code, kept outside the app, so an update never changes it underneath.

What Changed

  • Before: the service unit runs the app's orca launcher, which runs …/Resources/app.asar.unpacked/out/cli/index.js with the app's executable in Node mode. The CLI is compiled module by module, not bundled, so it require()s files lazily from the app for the whole life of the supervisor.
  • After: only with --supervise, and only from a packaged app (ELECTRON_RUN_AS_NODE=1, no ORCA_APP_EXECUTABLE override, running from app.asar.unpacked):
    1. The supervisor copies Resources/app.asar.unpacked and Resources/node_modules into <profile>/serve-supervisor/<release id>/. The layout is kept, so bare require()s still find node_modules. The release id hashes the compiled package stamp (version and commit) and the executable's size and mtime.
      • The copy uses copy-on-write cloning where the filesystem has it (APFS, and reflink on Linux), so on a Mac it costs almost no time or space.
      • It is built in a temporary folder and renamed into place. A finished copy is reused.
    2. It replaces itself with process.execve: the same executable, the copy's index.js, and the same arguments. The pid stays the same, so launchd and systemd keep tracking it.
    3. The re-run supervisor is told the real app root (ORCA_SERVE_SUPERVISOR_APP_ROOT). The server it starts, the orcad runtime selection, and the working directory all still come from the app, so the server itself updates exactly as before. The marker is removed from the environment of every child process.
    4. Each copy records the supervisor pids that run from it. Copies from older releases are removed once no live supervisor uses them.
  • Failure is safe: if the copy or the re-exec fails (disk full, a read-only profile, a runtime without execve), the supervisor logs one line and supervises from the app itself, as today.
  • Plain orca serve, dev and overridden launches, and Windows (which refuses --supervise) are unchanged.

Why

The owner accepted this as the B6 follow-up (D1 Q6): run the supervisor from a stable path outside the app. Alternatives considered:

  • Eagerly loading every module at startup: fragile. Any later code path, such as an error branch, could still load a file from the new release.
  • Bundling the CLI into one file: a much larger build change that affects every CLI user, not just supervised services.
  • Copying the whole app, or using the downloadable Node runtime: copying the app is heavy on Linux. The Node runtime may need a network download, and it would make the supervisor run on a different runtime than the CLI does today.
  • Copy the code, keep the runtime: the code the CLI can load is exactly app.asar.unpacked plus Resources/node_modules, because Node mode can't read inside app.asar. Copying just those is complete and small. The executable itself is mapped into memory when the process starts, so replacing it on disk doesn't affect the running supervisor.

This keeps the update park protocol (#27722) as it is. The served child still runs from the app and is still parked during an install.

Linked Issue

Part of the headless-serve robustness work (D1, B6 follow-up), toward #14732.

Visual Proof

N/A. This changes background service behavior, with no UI.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • serve-supervisor-relocation.test.ts covers:

    • a packaged supervisor re-runs from the copy with the same arguments and the app root passed along;
    • the copy keeps the node_modules layout;
    • a finished copy is reused, and a relocated supervisor never relocates twice;
    • dev, overridden and non-packaged launches stay in place;
    • a failed copy or re-exec stays in place and logs;
    • old copies are removed unless a live supervisor still uses them.
  • launch-serve-supervise.test.ts: once relocated, the server starts with the app's root as its working directory, and the marker doesn't reach the server's environment. This failed before the change.

  • Local smoke test with plain Node, not Electron, in a temporary folder: real process.execve into the copy kept the pid, loaded index.js and a dependency from the copy, and passed the arguments and app root through.

  • The full src/cli suite, pnpm tc, oxlint, pnpm run check:code-quality:changed and pnpm lint pass locally.

  • Not run: a real LaunchAgent or systemd service across a desktop update. That is real-host test 2 in the design.

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

  • Disk: one copy per release per supervised profile, usually around 90 MB. On a Mac it is a clone that shares blocks with the app. Older copies are removed.
  • Mixed versions: after a desktop update, the supervisor stays on its own release until the service restarts. The supervisor-child protocol (orca:serve-ready, handoff v1) is unchanged, so an older supervisor and a newer server already work together.
  • SSH: a supervised service runs on the machine where it's installed. Nothing is routed.
  • Linux: an AppImage's mount stays alive while its runtime process runs, so the copy is taken from it at start. Deb and rpm installs copy from /opt.
  • Windows: unchanged; --supervise is still refused there.

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)

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 21605dec-566a-425d-99b4-25b7307a7806

📥 Commits

Reviewing files that changed from the base of the PR and between fe01cd2 and 9705373.


📒 Files selected for processing (4)
  • src/cli/runtime/launch-serve-supervise.test.ts
  • src/cli/runtime/launch.ts
  • src/cli/runtime/serve-supervisor-relocation.test.ts
  • src/cli/runtime/serve-supervisor-relocation.ts

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

Eligible packaged supervisors now create or reuse a release snapshot and replace the current process with the copied CLI. Snapshot cleanup checks PID markers before removing older copies. Supervised startup uses the preserved app-root environment value, and child environments remove that value.


Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to fe01c

Unused supervisor copies may remain on disk after a failed relocation. This is a bounded storage risk to address before or shortly after merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the main change: running the supervised serve process from a copy outside the app.
Description check Passed The description is complete and directly matches the changes. It includes the user impact, implementation details, rationale, linked issue reference, testing, cross-platform considerations, visual pro…

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch np/d1e-supervisor-stable-path

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

@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: 116995b6-1df1-44f7-a158-aa0c00c4d911
📥 Commits

Reviewing files that changed from the base of the PR and between cef4d29 and fe01cd2.

📒 Files selected for processing (4)
  • src/cli/runtime/launch-serve-supervise.test.ts
  • src/cli/runtime/launch.ts
  • 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; 1 remain after this review.

Comment on lines +72 to +73
await mkdir(usersDir(root, id), { recursive: true })
await writeFile(join(usersDir(root, id), String(pid)), '')

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.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '34,202p' src/cli/runtime/serve-supervisor-relocation.ts
sed -n '48,143p' src/cli/runtime/serve-supervisor-relocation.test.ts

Repository: stablyai/orca

Length of output: 10148


🏁 Script executed:

nl -ba src/cli/runtime/serve-supervisor-relocation.ts | sed -n '60,175p'
nl -ba src/cli/runtime/serve-supervisor-relocation.test.ts | sed -n '1,35p;85,145p'

Repository: stablyai/orca

Length of output: 9816


Remove the marker whenever relocation falls back to the app.

buildSnapshot creates the marker before copying. Copy, rename, cleanup, and execve failures can all return 'in-place' while leaving that marker. Remove it from both outer failure paths.

A PID-only marker also cannot distinguish a stale marker from an unrelated process that later reuses the PID. Dead-marker cleanup alone does not fix that case. Do not delete a marker solely because of a racy PID-liveness check; use a process identity stronger than the PID if cleanup must handle PID reuse.

Suggested failure-path fix
   } catch (error) {
+    await rm(join(usersDir(root, id), String(deps.pid)), { force: true }).catch(
+      () => undefined
+    )
     deps.log(
       `[serve] Supervising from the app itself; could not copy it aside: ${error instanceof Error ? error.message : String(error)}`
     )
     return 'in-place'
   }
...
   } catch (error) {
+    await rm(join(usersDir(root, id), String(deps.pid)), { force: true }).catch(
+      () => undefined
+    )
     deps.log(
       `[serve] Supervising from the app itself; could not restart from the copy: ${error instanceof Error ? error.message : String(error)}`
     )

…ble-path

# Conflicts:
#	src/cli/runtime/launch.ts
@OrcaWin
OrcaWin merged commit cb92b6c into main Oct 12, 2026
43 checks passed
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