Repository navigation
fix(daemon): stop giving new terminals to a daemon whose AppImage files are gone - #28011
Conversation
…es are gone On Linux AppImage, a terminal daemon can outlive the mount it runs from and keep answering health checks until it SIGBUSes. Orca now reads the daemon's /proc exe link and mount table at adoption: an idle severed daemon is replaced; a busy one is kept for its sessions but quarantined, so fresh terminals use the local provider and a healthy RPC never re-admits them. Status and a verified restart are available over RPC and as `orca terminal-daemon status|restart`. Co-Authored-By: Claude <[email protected]>
…ndpoint Co-Authored-By: Claude <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to A concurrent replacement during restart can leave fallback terminals shut down even though the restart is refused. Address or explicitly accept this risk before 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:
587fae5c-7dd2-4aed-b853-be78ad434f00
⛔ Files ignored due to path filters (1)
src/shared/rpc-contract/rpc-params-catalog.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing (24)
src/cli/handler-group-manifest.tssrc/cli/handlers/diagnostics.tssrc/cli/handlers/terminal-daemon.test.tssrc/cli/handlers/terminal-daemon.tssrc/cli/specs/index.tssrc/cli/specs/terminal-daemon.tssrc/main/daemon/daemon-appimage-launch.tssrc/main/daemon/daemon-host-image-state.tssrc/main/daemon/daemon-host-image.test.tssrc/main/daemon/daemon-host-image.tssrc/main/daemon/daemon-init-dependency-mocks.tssrc/main/daemon/daemon-init-mock-types.tssrc/main/daemon/daemon-init-severed-host-image.test.tssrc/main/daemon/daemon-out-of-process-launcher.tssrc/main/daemon/daemon-provider-init.tssrc/main/daemon/daemon-provider-restart.tssrc/main/daemon/daemon-replacement-preflight.tssrc/main/daemon/daemon-severed-restart.test.tssrc/main/daemon/daemon-severed-restart.tssrc/main/daemon/daemon-spawner.tssrc/main/runtime/rpc/methods/index.tssrc/main/runtime/rpc/methods/terminal-daemon.tssrc/shared/daemon-lifecycle-telemetry.tssrc/shared/rpc-contract/terminal-daemon-params.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.
…ever stops a replacement The restart re-checks the authenticated endpoint owner before any teardown and again at shutdown, and never falls back to a pid kill when targeted. Status counts the local fallback terminals the restart also ends. Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
042bf1b5-0f48-40a3-85ba-7755fa35c086
📒 Files selected for processing (9)
src/main/daemon/daemon-host-image-state.tssrc/main/daemon/daemon-init-restart-sequence.test.tssrc/main/daemon/daemon-protocol-cleanup.test.tssrc/main/daemon/daemon-protocol-cleanup.tssrc/main/daemon/daemon-provider-restart.tssrc/main/daemon/daemon-severed-restart.test.tssrc/main/daemon/daemon-severed-restart.tssrc/main/daemon/degraded-daemon-pty-provider.test.tssrc/main/daemon/degraded-daemon-pty-provider.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/daemon/daemon-host-image-state.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
| export async function restartDaemon( | ||
| options: { expectedDaemonPid?: number } = {} | ||
| ): Promise<RestartDaemonResult> { | ||
| return runCoalescedDaemonRestart(() => runRestartDaemon(options.expectedDaemonPid)) | ||
| } | ||
|
|
||
| async function runRestartDaemon(): Promise<RestartDaemonResult> { | ||
| async function runRestartDaemon(expectedDaemonPid?: number): Promise<RestartDaemonResult> { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,115p' src/main/daemon/daemon-provider-restart.ts
rg -n 'restartDaemon\(|restartSeveredDaemon|coalesce|runCoalesced' src/main/daemon src/main/runtime/rpc/methods/terminal-daemon.tsRepository: stablyai/orca
Length of output: 11297
🏁 Script executed:
set -u
printf '%s\n' '--- daemon-restart-state.ts ---'
nl -ba src/main/daemon/daemon-restart-state.ts
printf '%s\n' '--- daemon-severed-restart.ts ---'
nl -ba src/main/daemon/daemon-severed-restart.ts
printf '%s\n' '--- daemon-host-image-state.ts ---'
nl -ba src/main/daemon/daemon-host-image-state.ts
printf '%s\n' '--- terminal-daemon.ts ---'
nl -ba src/main/runtime/rpc/methods/terminal-daemon.ts
printf '%s\n' '--- restart implementation remainder ---'
nl -ba src/main/daemon/daemon-provider-restart.ts | sed -n '45,240p'
printf '%s\n' '--- restart entrypoint references ---'
rg -n -F --glob '*.{ts,tsx}' -- 'restartDaemon(' src/main src/renderer src || test "$?" -eq 1
printf '%s\n' '--- severed restart references ---'
rg -n -F --glob '*.{ts,tsx}' -- 'restartSeveredDaemon' src || test "$?" -eq 1
printf '%s\n' '--- coalescer and targeted restart tests ---'
nl -ba src/main/daemon/daemon-init-restart-sequence.test.ts | sed -n '490,570p'
nl -ba src/main/daemon/daemon-severed-restart.test.ts | sed -n '1,150p'Repository: stablyai/orca
Length of output: 32578
🏁 Script executed:
set -u
printf '%s\n' '--- ordinary restart caller ---'
nl -ba src/main/ipc/pty-management.ts | sed -n '165,220p'
printf '%s\n' '--- RPC core dispatch references ---'
rg -n -F --glob '*.ts' -- 'defineMethod' src/main/runtime/rpc
rg -n -F --glob '*.ts' -- 'TERMINAL_DAEMON_METHODS' src/main
printf '%s\n' '--- cleanup implementation ---'
rg -n -F --glob '*.ts' -- 'function cleanupDaemonForProtocol' src/main
cleanup=$(rg -l -F --glob '*.ts' -- 'function cleanupDaemonForProtocol' src/main | head -n 1)
if [ -n "$cleanup" ]; then nl -ba "$cleanup"; fi
printf '%s\n' '--- ownership and restart tests ---'
rg -n -F --glob '*.test.ts' -- 'DaemonEndpointOwnershipError' src/main/daemon
rg -n -F --glob '*.test.ts' -- 'expectedDaemonPid' src/main/daemon
nl -ba src/main/daemon/daemon-init-restart-sequence.test.ts | sed -n '1,135p'Repository: stablyai/orca
Length of output: 42101
🏁 Script executed:
set -u
printf '%s\n' '--- RPC dispatcher candidates ---'
rg --files src/main/runtime/rpc | rg '/(dispatcher|server|transport|index)\.ts$'
rg -n -F --glob '*.ts' -- 'method.handler' src/main/runtime/rpc
rg -n -F --glob '*.ts' -- 'handler(request' src/main/runtime/rpc
printf '%s\n' '--- RPC method registration ---'
nl -ba src/main/runtime/rpc/methods/index.ts | sed -n '1,115p'
printf '%s\n' '--- RPC core definition ---'
nl -ba src/main/runtime/rpc/core.ts | sed -n '150,205p'
printf '%s\n' '--- IPC registration context ---'
nl -ba src/main/ipc/pty-management.ts | sed -n '1,45p'Repository: stablyai/orca
Length of output: 19645
Make restart coalescing target-aware.
runCoalescedDaemonRestart returns any in-flight restart, regardless of expectedDaemonPid. If an ordinary restart starts first, terminalDaemon.restartSevered receives its result without running assertDaemonEndpointOwner. The targeted flow then reports status: 'restarted' and clears severed state.
Reject a concurrent restart with different targeting semantics, or wait and revalidate ownership before returning the targeted result.
Suggested fix
diff --git a/src/main/daemon/daemon-restart-state.ts b/src/main/daemon/daemon-restart-state.ts
@@
let restartInFlight: Promise<RestartDaemonResult> | null = null
+let restartInFlightExpectedDaemonPid: number | null = null
export function runCoalescedDaemonRestart(
- run: () => Promise<RestartDaemonResult>
+ run: () => Promise<RestartDaemonResult>,
+ expectedDaemonPid?: number
): Promise<RestartDaemonResult> {
if (restartInFlight) {
+ if ((expectedDaemonPid ?? null) !== restartInFlightExpectedDaemonPid) {
+ return Promise.reject(new Error('A restart with different targeting is already in flight'))
+ }
return restartInFlight
}
+ restartInFlightExpectedDaemonPid = expectedDaemonPid ?? null
restartInFlight = run().finally(() => {
restartInFlight = null
+ restartInFlightExpectedDaemonPid = null
})
return restartInFlight
}
diff --git a/src/main/daemon/daemon-provider-restart.ts b/src/main/daemon/daemon-provider-restart.ts
@@
export async function restartDaemon(
options: { expectedDaemonPid?: number } = {}
): Promise<RestartDaemonResult> {
- return runCoalescedDaemonRestart(() => runRestartDaemon(options.expectedDaemonPid))
+ return runCoalescedDaemonRestart(
+ () => runRestartDaemon(options.expectedDaemonPid),
+ options.expectedDaemonPid
+ )
}| let info: Awaited<ReturnType<DaemonSpawner['ensureRunning']>> | ||
| try { | ||
| await cleanupDaemonForProtocol(runtimeDir, PROTOCOL_VERSION) | ||
| await cleanupDaemonForProtocol(runtimeDir, PROTOCOL_VERSION, expectedDaemonPid) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
Keep local terminals alive when the final ownership check refuses restart.
If a replacement claims the endpoint while shutdownFallbackSessions() awaits, cleanupDaemonForProtocol rejects the targeted restart. By then, restart has ended fallback terminals and sent synthetic exits. A refused restart can therefore end live processes. For targeted restarts, perform the final ownership check before irreversible local teardown, and keep fallback sessions intact when that check fails.
Co-Authored-By: Claude <[email protected]>
ELI5
On Linux, the AppImage version of Orca runs from a temporary disk that disappears when the window that created it closes. The terminal daemon is the background process that keeps your terminals alive, and it can keep running from that vanished disk for hours. Then it crashes and takes every terminal with it. Orca now notices when this has happened. If the daemon has no work, Orca replaces it. If it has running terminals, Orca keeps it for those terminals, opens new terminals somewhere else, and lets you restart it when you are ready.
What Changed
/proc/<pid>/exeand the daemon's own mount table, after checking the pid's start ticks and boot id against the pid record. A daemon is severed when either of these holds:.mount_*) is no longer mounted, or its extract directory (appimage_extracted_*) was deleted;/orca-ide, which is what [Bug]: AppImage squashfs is unmounted before helper children finish exiting — SIGBUS in node::Exit, and the surviving daemon is left mapped to a dead mount #18200 reported.unknown, andunknownchanges nothing.severed_host_image.terminalDaemon.severedStatusandterminalDaemon.restartSevered.orca terminal-daemon statusandorca terminal-daemon restart --yes.replacedwhen another daemon now owns the endpoint,unverifiablewhen the host cannot verify the process.not-ephemeral. On Linux it only judges daemons whose recorded or actual executable lives under an AppImage mount or extract directory. An in-place package upgrade, where the executable shows as(deleted)outside those roots, is still handled by the existing stale-bundle policy.The persistent desktop banner with Restart terminal daemon is the next PR in this stack. It reads the same state and calls the same verified restart.
Why
Linked Issue
Part of #18200 (adoption of a daemon on a dead mount). Prevents the trigger behind #23648, but does not close it.
Visual Proof
N/A. This PR is main-process policy plus CLI text. The banner comes in the next PR.
Testing
/orca-ide);mismatchis kept and quarantined;severed_host_image;Notes
not-ephemeral. The RPC can still report status for a paired Linux AppImage host.Checklist
pnpm lint,pnpm typecheckpass locally; CI covers the rest