Repository navigation
feat(serve): run the --supervise supervisor from a copy outside the app - #28007
Conversation
|
Warning Review limit reachedYou'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. View limit details
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to 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 |
|
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:
116995b6-1df1-44f7-a158-aa0c00c4d911
📒 Files selected for processing (4)
src/cli/runtime/launch-serve-supervise.test.tssrc/cli/runtime/launch.tssrc/cli/runtime/serve-supervisor-relocation.test.tssrc/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.
| await mkdir(usersDir(root, id), { recursive: true }) | ||
| await writeFile(join(usersDir(root, id), String(pid)), '') |
There was a problem hiding this comment.
🚀 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.tsRepository: 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
ELI5
orca serve --superviseis 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
orcalauncher, which runs…/Resources/app.asar.unpacked/out/cli/index.jswith the app's executable in Node mode. The CLI is compiled module by module, not bundled, so itrequire()s files lazily from the app for the whole life of the supervisor.--supervise, and only from a packaged app (ELECTRON_RUN_AS_NODE=1, noORCA_APP_EXECUTABLEoverride, running fromapp.asar.unpacked):Resources/app.asar.unpackedandResources/node_modulesinto<profile>/serve-supervisor/<release id>/. The layout is kept, so barerequire()s still findnode_modules. The release id hashes the compiled package stamp (version and commit) and the executable's size and mtime.process.execve: the same executable, the copy'sindex.js, and the same arguments. The pid stays the same, so launchd and systemd keep tracking it.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.execve), the supervisor logs one line and supervises from the app itself, as today.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:
app.asar.unpackedplusResources/node_modules, because Node mode can't read insideapp.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.tscovers:node_moduleslayout;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.execveinto the copy kept the pid, loadedindex.jsand a dependency from the copy, and passed the arguments and app root through.The full
src/clisuite,pnpm tc, oxlint,pnpm run check:code-quality:changedandpnpm lintpass 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
Notes
orca:serve-ready, handoff v1) is unchanged, so an older supervisor and a newer server already work together./opt.--superviseis still refused there.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)