Skip to content

fix(daemon): stop giving new terminals to a daemon whose AppImage files are gone - #28011

Merged
OrcaWin merged 5 commits into
mainfrom
fix/daemon-severed-appimage-quarantine
Oct 12, 2026
Merged

OrcaWin merged 5 commits into
mainfrom
fix/daemon-severed-appimage-quarantine

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​602 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​600
Prod 24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​615 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​596

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

  • Before: after an AppImage update, or after the window that started it closed, the new window adopted a daemon whose program files were gone, as long as it answered a health check. New terminals kept landing on it until it SIGBUSed ([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).
  • After (Linux AppImage only):
    • When Orca adopts a daemon, it reads /proc/<pid>/exe and 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:
    • These reads never touch the FUSE filesystem, so a dead server cannot hang them. A permission error, an exited pid or a recycled pid gives unknown, and unknown changes nothing.
    • A severed daemon with no live sessions is replaced. Telemetry records this under a new reason, severed_host_image.
    • A severed daemon with live sessions, or whose session count is unknown, is kept, because its terminals keep running. It is quarantined: fresh terminals go to the local provider. A health check that passes does not undo this, because a severed daemon passes health checks. Only a new daemon incarnation clears the quarantine.
    • The check runs in the one helper that every adoption path now uses: the preflight, the failed-health branch, the endpoint race and the post-failure rescue. A daemon from a previous mount, which always looks like a "different app path", cannot slip past it.
    • Status and restart, for headless servers and scripts:
      • New runtime RPC methods terminalDaemon.severedStatus and terminalDaemon.restartSevered.
      • CLI commands orca terminal-daemon status and orca terminal-daemon restart --yes.
      • The restart re-reads the host's evidence right before it acts. It proceeds only if the pid, start ticks and boot id still match what status reported. Otherwise it refuses: replaced when another daemon now owns the endpoint, unverifiable when the host cannot verify the process.
      • The CLI text says that a restart ends running processes, that agents which support resume can be resumed, and that shells cannot.
  • macOS, Windows and deb/rpm Linux: no behaviour change. Off Linux the probe returns 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

  • Every adoption path can keep a daemon, so the quarantine has to be enforced in the one helper they all share. A check in only one branch would leave the others open.
  • A plain health check cannot detect this failure: the daemon answers RPCs until it touches a code page that is no longer resident.
  • Alternatives considered:
    • Killing a severed daemon automatically would end live agents without warning. The accepted design is never to kill silently.
    • Migrating sessions to a new daemon is not possible with live processes.

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

Notes

  • SSH: unaffected. Remote orcad runs the daemon from its own runtime slot, so the probe returns not-ephemeral. The RPC can still report status for a paired Linux AppImage host.
  • Wire: two new RPC methods. An old server answers "unknown method", and old clients never call them.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for screenshots (no UI in this PR)
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered
  • pnpm lint, pnpm typecheck pass locally; CI covers the rest

m4air and others added 2 commits October 12, 2026 08:04
…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]>
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: da8bcabf-ed70-40cd-9de9-5c3418e9cda9

📥 Commits

Reviewing files that changed from the base of the PR and between cdb2202 and 70b878a.


📒 Files selected for processing (1)
  • src/shared/host-operation-ownership.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.



📝 Walkthrough

Walkthrough

The changes add Linux daemon host-image inspection and severed-daemon state tracking. Startup and replacement paths quarantine retained severed daemons from fresh terminals and use local fallback routing until a replacement is verified. New RPC methods expose status and incarnation-checked restart operations. The diagnostics CLI adds status and restart commands, including explicit restart confirmation.


Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 70b87

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 | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 39 functions across 30 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preventing new terminals from using a daemon whose AppImage files are gone.
Description check Passed The description is detailed and covers the main template sections, including the user impact, implementation, rationale, linked issues, testing, compatibility notes, and checklist. The AI Disclosure, …
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.

  • Fix all pre-merge checks with AI
✨ 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.

@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: 587fae5c-7dd2-4aed-b853-be78ad434f00
📥 Commits

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

⛔ Files ignored due to path filters (1)
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (24)
  • src/cli/handler-group-manifest.ts
  • src/cli/handlers/diagnostics.ts
  • src/cli/handlers/terminal-daemon.test.ts
  • src/cli/handlers/terminal-daemon.ts
  • src/cli/specs/index.ts
  • src/cli/specs/terminal-daemon.ts
  • src/main/daemon/daemon-appimage-launch.ts
  • src/main/daemon/daemon-host-image-state.ts
  • src/main/daemon/daemon-host-image.test.ts
  • src/main/daemon/daemon-host-image.ts
  • src/main/daemon/daemon-init-dependency-mocks.ts
  • src/main/daemon/daemon-init-mock-types.ts
  • src/main/daemon/daemon-init-severed-host-image.test.ts
  • src/main/daemon/daemon-out-of-process-launcher.ts
  • src/main/daemon/daemon-provider-init.ts
  • src/main/daemon/daemon-provider-restart.ts
  • src/main/daemon/daemon-replacement-preflight.ts
  • src/main/daemon/daemon-severed-restart.test.ts
  • src/main/daemon/daemon-severed-restart.ts
  • src/main/daemon/daemon-spawner.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/runtime/rpc/methods/terminal-daemon.ts
  • src/shared/daemon-lifecycle-telemetry.ts
  • src/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.

m4air and others added 2 commits October 12, 2026 08:16
…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]>

@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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 042bf1b5-0f48-40a3-85ba-7755fa35c086
📥 Commits

Reviewing files that changed from the base of the PR and between ee29143 and cdb2202.

📒 Files selected for processing (9)
  • src/main/daemon/daemon-host-image-state.ts
  • src/main/daemon/daemon-init-restart-sequence.test.ts
  • src/main/daemon/daemon-protocol-cleanup.test.ts
  • src/main/daemon/daemon-protocol-cleanup.ts
  • src/main/daemon/daemon-provider-restart.ts
  • src/main/daemon/daemon-severed-restart.test.ts
  • src/main/daemon/daemon-severed-restart.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/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.

Comment on lines +49 to +55
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> {

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.

🎯 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.ts

Repository: 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)

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.

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

@OrcaWin
OrcaWin merged commit fde0fe3 into main Oct 12, 2026
52 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