Skip to content

fix(orchestration): remote worker liveness reports exited when the host proves the agent gone - #29276

Merged
nwparker merged 1 commit into
mainfrom
nwparker/remote-worker-liveness
Oct 16, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/remote-worker-liveness

Conversation

@nwparker

@nwparker nwparker commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​290 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​289
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​154 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​145

ELI5

When Orca runs agents on another machine, it asks that machine "is this agent still running?". In two cases the answer never became "no" even though the agent was gone, so the coordinator waited forever. Now the remote machine answers "exited" whenever it can prove the agent is gone.

What Changed

Before

  • Agent killed but its terminal still open: the worker kept showing live, because only the terminal was checked and the shell had taken the prompt back.
  • Host rebooted: the terminal was gone, so the worker showed unverifiable / host_indeterminate forever, with nextAction: none.

After

  • In both cases the worker shows exited, and nextAction becomes recover (read the transcript, then stop or abandon).

Mechanism

  • This is a host-side change only. A new observeRemoteAttachmentLiveness wraps the existing inspectRemoteAttachment, and it feeds orchestration.federationFleetSnapshot and orchestration.federationShow.
  • Live terminal: the host asks its own hook-server store, through the new runtime method checkTerminalAgentPresence(handle, exitedSince), which reuses recheckHookAgentPresenceForPty. The store compares the agent's hook-captured PID and start time against the process table.
  • The hook store now also keeps the time it proved each pane's agent ended (agentExitedAtByPaneKey), whether the proof came from a SessionEnd hook or a probe. That exit stays readable after the row is reconciled away. A new agent's hook in the same pane clears it. The reader ignores exits from before the Dispatch attached, so an earlier agent's exit in a reused pane cannot count.
  • Missing terminal (reboot) or a different terminal in its place: the host checks its terminal process table for the recorded process, using the existing inspectTerminalProcessIncarnationLiveness that worker-release already trusts. It reports exited only when the table was read and the process is absent.
  • Release, read and stop paths are unchanged.

Why

  • The execution host owns status, so the proof has to come from that host's own process table and hook store, never from the home side.
  • Loss of contact still never produces exited. Every case where the host cannot check still returns the current answer: no process identity from a hook, a probe that fails, or a process table that cannot be read.
  • host_indeterminate is a reason under the unverifiable verdict, not a fourth verdict, so the live/unverifiable/exited vocabulary already holds. The bug was that no proof was ever looked for.
  • I did not add a per-Dispatch boot ID (one of the issue's suggestions). The process table already answers "is that exact terminal process gone" without a schema or wire change.
  • Wire compatibility: hosts already publish status: 'exited', exactWorker: true, and every shipped client understands it. No new field or opcode.

Linked Issue

Fixes #24353

Visual Proof

N/A. CLI/RPC verdict change with no UI.

Testing

  • Added federation-agent-death-liveness.test.ts, plus retained agent exit cases in server-agent-presence.test.ts (exit read after SessionEnd or probe reconcile, an exit from before attach ignored, a new agent clears it). Two of its four tests fail on main (agent killed in a live PTY; reboot). The other two lock in the safe fallbacks: no hook identity or an unverifiable probe stays live, and an unreadable process table stays unverifiable.

  • Re-ran the existing federation liveness, fleet-snapshot and federation suites plus agent-prompt-submission-runtime.test.ts.

  • pnpm tc:node and check:code-quality:changed pass.

  • I manually tested these changes locally

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

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

  • Limitation: the retained exit time is held in memory. After an orca serve restart the verdict falls back to the terminal's (live) for an agent that died before the restart.
  • Not covered: worker-stop after a reboot still reports stop_unknown; worker-abandon remains the exit route that recover points to.

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 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The hook server now retains timestamped agent-exit evidence across pane aliases and authority transfers, and clears it when new process activity is reported. Terminal runtime checks can query that evidence from a specified time. Federation snapshot and show observations now use agent-presence and process-incarnation checks to report proven exits.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 84a44

A remote worker may continue to appear live after its agent exits. Move exit-evidence clearing to accepted status writes before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 18 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: reporting remote worker liveness as exited when the host proves the agent is gone.
Description check Passed The description is mostly complete. It covers the user impact, implementation, rationale, linked issue, testing, limitations, and checklist. Visual proof is correctly marked N/A for a CLI/RPC change. …
Linked Issues check Passed [#24353] The host-side observer upgrades a live PTY to exited only when the hook store proves the agent is absent after attachment. It upgrades a missing terminal only when the readable host process…
Out of Scope Changes check Passed The retained exit records, pane-alias handling, runtime method plumbing, federation observer, and tests directly support [#24353]. The reviewed changes do not show an unrelated behavior change or unre…
  • 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: 4f7b0170-51a5-46a2-9716-2766eec5f63b
📥 Commits

Reviewing files that changed from the base of the PR and between de2a371 and de8c8a5.

📒 Files selected for processing: 17
  • src/main/agent-hooks/agent-hook-runtime-deps.ts
  • src/main/agent-hooks/server-agent-presence.test.ts
  • src/main/agent-hooks/server/server-agent-presence.ts
  • src/main/agent-hooks/server/server-authority-aliases.ts
  • src/main/agent-hooks/server/server-cleanup.ts
  • src/main/agent-hooks/server/server-ingest-terminal.ts
  • src/main/agent-hooks/server/server-state.ts
  • src/main/agent-hooks/server/server-status-update.ts
  • src/main/runtime/construction/runtime-construction-dependencies.ts
  • src/main/runtime/orchestration/worker-terminal-release-runtime.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-agent-death-liveness.test.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-attachment-observation.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-control.ts
  • src/main/runtime/terminal/adoption/adopt-terminal-orphans-from-inventory.ts
  • src/main/runtime/terminal/driver/terminal-driver-resources.ts
  • src/main/runtime/terminal/input/terminal-agent-status-and-submission.ts
  • src/main/runtime/terminal/output/terminal-title-tracker.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 +90 to +115

/** The fleet and show verdict: the terminal's, upgraded to `exited` only on this host's proof. */
export async function observeRemoteAttachmentLiveness(
runtime: WorkerTerminalReleaseRuntime,
dispatchId: string
): Promise<Awaited<ReturnType<typeof inspectRemoteAttachment>>> {
const observation = await inspectRemoteAttachment(runtime, dispatchId)
const db = runtime.getOrchestrationDb()
const attachment = db.getRemoteDispatchAttachment(dispatchId)
const incarnation = attachment?.process_incarnation
if (!attachment?.terminal_handle || !incarnation) {
return observation
}
if (
(observation.status === 'missing' || observation.status === 'identity_changed') &&
// Why: a legacy `${runtimeId}:${ptyId}:${generation}` fence never matches the process table,
// so its absence there proves nothing.
!incarnation.startsWith(`${attachment.runtime_epoch}:`)
) {
// Why: a host reboot takes the PTY and its handle with it; the process table proves it gone.
const liveness = await runtime
.inspectTerminalProcessIncarnationLiveness(
incarnation,
db.getWorkerTerminalResourceByOwner(dispatchId)?.host_scope ?? null
)
.catch(() => 'unverifiable' as const)

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 '85,135p' src/main/runtime/rpc/methods/orchestration/federation/federation-attachment-observation.ts
rg -n 'processIncarnation|runtimeEpoch' src/main/runtime/orchestration src/main/runtime/rpc/methods/orchestration/federation | head -100

Repository: stablyai/orca

Length of output: 15571


🏁 Script executed:

rg -n -F -e 'getTerminalProcessIncarnation' -e 'getRuntimeId' -e 'runtime_epoch' src/main | head -160
rg -n -F -e 'inspectTerminalProcessIncarnationLiveness' -e 'process_incarnation' src/main/runtime | head -160
git diff --unified=12 de2a37140e76209008b6ff484ac39c8f5f6fffac de8c8a5e5451eec6cea874d5c56064ad3b6d1cdd -- src/main/runtime/rpc/methods/orchestration/federation/federation-attachment-observation.ts

Repository: stablyai/orca

Length of output: 41684


🏁 Script executed:

rg -n -F -e 'getTerminalProcessIncarnation(' -e 'inspectTerminalProcessIncarnationLiveness(' src/main/runtime --glob '*.ts' --glob '!*.test.ts'
rg -n -F -e 'class Runtime' -e 'getRuntimeId()' src/main/runtime/workspaces/session-hosts/get-runtime-id.ts src/main/runtime --glob '*.ts' --glob '!*.test.ts' | head -100
sed -n '1,100p' src/main/runtime/workspaces/session-hosts/get-runtime-id.ts
sed -n '1,240p' src/main/runtime/orchestration/worker-terminal-process-liveness.ts
sed -n '340,400p' src/main/runtime/orca-runtime-tests/terminal-handles-and-agent-status.spec.ts

Repository: stablyai/orca

Length of output: 23468


🏁 Script executed:

sed -n '140,215p' src/main/runtime/terminal/wait/terminal-interactive-wait.ts
rg -n -F -e 'runtimeId =' -e 'runtimeId:' -e 'ptyId' src/main/runtime/construction src/main/runtime/terminal src/main/runtime/pty --glob '*.ts' | head -140
rg -n -F -e 'new OrcaRuntimeService' -e 'runtimeId:' src/main/runtime/construction src/main --glob '*.ts' --glob '!*.test.ts' | head -100
rg -n -F -e 'incarnationId' src/main/runtime/terminal src/main/runtime/providers src/main --glob '*.ts' --glob '!*.test.ts' | head -130

Repository: stablyai/orca

Length of output: 41475


🏁 Script executed:

sed -n '1,110p' src/main/providers/local-pty-spawn.ts
sed -n '1,90p' src/main/providers/pty-provider-contract.ts
sed -n '45,140p' src/main/providers/pty-process-list-admission.ts
rg -n -F -e 'ptyId:' -e 'id: randomUUID()' -e 'id: `pty' src/main/providers src/main/ipc/pty --glob '*.ts' --glob '!*.test.ts' | head -130
rg -n -F -e 'new Pty' -e 'spawnPty' -e 'spawn:' src/main/providers src/main/ipc/pty --glob '*.ts' --glob '!*.test.ts' | head -100

Repository: stablyai/orca

Length of output: 20589


🏁 Script executed:

rg -n -F -e 'allocatePtyId' -e 'function isPtyIncarnationId' -e 'export type PtyId' -e 'runtimeEpoch: runtime.getRuntimeId()' src/main src/shared --glob '*.ts'
sed -n '1,120p' src/main/providers/local-pty-provider-state.ts
sed -n '1,90p' src/main/shared/pty-incarnation.ts
sed -n '30,90p' src/main/runtime/rpc/methods/orchestration/federation/federation-control.ts
sed -n '125,165p' src/main/runtime/rpc/methods/orchestration/federation/federated-worker-start.ts

Repository: stablyai/orca

Length of output: 11728


🏁 Script executed:

sed -n '135,175p' src/main/providers/local-pty-provider-state.ts
rg -n -F -e 'function normalizeLocalCallerSessionId' -e 'normalizeLocalCallerSessionId' src/main/providers/local-pty-launch-helpers.ts src/main/providers --glob '*.ts'
sed -n '1,100p' src/main/providers/local-pty-launch-helpers.ts
cat src/shared/pty-incarnation.ts
rg -n -F -e 'sessionId:' src/main/ipc/pty src/main/providers --glob '*.ts' --glob '!*.test.ts' | head -70

Repository: stablyai/orca

Length of output: 7389


🏁 Script executed:

rg -n -F -e 'effectiveSessionId' -e 'sessionId' src/main/ipc/pty/ipc/spawn* src/main/ipc/pty/runtime/spawn* src/main/ipc/pty --glob '*.ts' | head -120
sed -n '1,210p' src/main/ipc/pty/ipc/spawn-preflight.ts
sed -n '130,190p' src/main/ipc/pty/ipc/spawn-commit.ts
sed -n '1,220p' src/main/runtime/rpc/methods/orchestration/federated-fleet-snapshot.ts
sed -n '85,180p' src/main/runtime/rpc/methods/orchestration/federated-worker-show.ts

Repository: stablyai/orca

Length of output: 21535


🏁 Script executed:

sed -n '1,230p' src/main/runtime/rpc/methods/orchestration/federation/federated-fleet-snapshot.ts
sed -n '1,210p' src/main/runtime/rpc/methods/orchestration/federation/federated-worker-show.ts
rg -n -F -e 'nextAction' -e "status === 'exited'" src/main/runtime/rpc/methods/orchestration/federation src/main/runtime/orchestration --glob '*.ts' | head -100

Repository: stablyai/orca

Length of output: 17292


🏁 Script executed:

sed -n '1,90p' src/main/runtime/rpc/methods/orchestration/federation/federation-attachment-observation.ts
sed -n '210,250p' src/main/runtime/rpc/methods/orchestration/federation/federated-fleet-snapshot.ts
rg -n -F 'projectFleetNextAction' src/shared/orchestration-fleet-worker-projection.ts
sed -n '1,170p' src/shared/orchestration-fleet-worker-projection.ts

Repository: stablyai/orca

Length of output: 13028


🏁 Script executed:

sed -n '165,210p' src/shared/orchestration-fleet-worker-projection.ts

Repository: stablyai/orca

Length of output: 1735


🏁 Script executed:

sed -n '1,110p' src/main/runtime/rpc/methods/orchestration/federation/federation-attachment-authority.ts
sed -n '1,135p' src/main/runtime/orchestration/db/federation/remote-dispatch-attachment-authority.ts
rg -n -F -e 'runtime_epoch' -e 'processIncarnation' src/main/runtime/rpc/methods/orchestration/federation src/main/runtime/orchestration/db/federation --glob '*.ts' | head -100

Repository: stablyai/orca

Length of output: 14699


🏁 Script executed:

rg -n -F -e 'createRemoteDispatchAttachment' -e 'remote_dispatch_attachments' src/main/runtime/rpc/methods/orchestration/federation src/main/runtime/orchestration/db/federation --glob '*.ts' | head -100
sed -n '55,115p' src/main/runtime/rpc/methods/orchestration/federation/federation-control.ts

Repository: stablyai/orca

Length of output: 6833


🏁 Script executed:

sed -n '35,95p' src/main/runtime/rpc/methods/orchestration/federation/federation.ts
sed -n '1,100p' src/main/runtime/orchestration/db/federation/remote-dispatch-attachment-create.ts

Repository: stablyai/orca

Length of output: 6335


🏁 Script executed:

sed -n '25,48p' src/main/runtime/rpc/methods/orchestration/federation/federation-control.ts

Repository: stablyai/orca

Length of output: 1133


Distinguish legacy fences from current process incarnations.

The PTY IPC path accepts a caller-provided sessionId without restricting its format. A caller can use ${runtime.getRuntimeId()}:suffix; the local provider preserves it as the PTY ID and forms the current identity as ${ptyId}:${incarnationId}. Because the attachment epoch is that same runtime ID, the current identity passes this legacy-prefix guard. When the terminal is missing or replaced, the guard skips process-table liveness and returns the unresolved observation. Federation maps it to unverifiable; with no pending input or approval, the fleet sets nextAction to none instead of recover. Use an unambiguous discriminator for legacy identities before skipping the process-table check.

…st proves the agent gone

The execution host upgrades a remote worker's fleet/show verdict to exited
only on its own proof: the hook store retains a proven agent exit (fenced to
the attachment, cleared by a replacement agent), and after a reboot the
process table proves the PTY gone. Lost contact stays unverifiable.

Fixes #24353

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: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 380e2ab5-30bd-4534-87ee-1ba031b980a3
📥 Commits

Reviewing files that changed from the base of the PR and between 655a671 and 84a44be.

📒 Files selected for processing: 3
  • config/scripts/vitest-sqlite-runtime-files.mjs
  • src/main/agent-hooks/server/server-agent-presence.ts
  • src/main/agent-hooks/server/server-status-update.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 +71 to +73
if (payload.source !== undefined || payload.agentPresence?.process) {
// A hook (not a late terminal repaint) means an agent claimed the pane after the last exit.
this.forgetAgentExit(payload.paneKey)

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect the transition guard and rejection branches without running repository code.
rg -n -C 8 'function transitionHookPresence|const transitionHookPresence|isStaleGrokTurnEnd|resolveCancelVerdictLatch|forgetAgentExit' src/main/agent-hooks

Repository: stablyai/orca

Length of output: 13707


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- status update ---'
nl -ba src/main/agent-hooks/server/server-status-update.ts | sed -n '40,245p'
printf '%s\n' '--- transitionHookPresence references and definitions ---'
rg -n -F --glob '*.ts' -e 'transitionHookPresence' -e 'commitStatusRowMutation' -e 'mutationBefore' src/main/agent-hooks
printf '%s\n' '--- status-update callers ---'
rg -n -C 5 -F --glob '*.ts' 'applyNormalizedStatus(' src/main/agent-hooks

Repository: stablyai/orca

Length of output: 27859


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- transition function ---'
nl -ba src/shared/agent-hook-presence-transition.ts | sed -n '1,240p'
printf '%s\n' '--- remaining status-update flow ---'
nl -ba src/main/agent-hooks/server/server-status-update.ts | sed -n '235,310p'
printf '%s\n' '--- write guard ---'
rg -n -C 12 -F --glob '*.ts' 'canWriteLegacyStatusRow' src/main/agent-hooks

Repository: stablyai/orca

Length of output: 12490


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- stale Grok predicate ---'
nl -ba src/main/agent-hooks/server/server-grok-status-rules.ts | sed -n '1,100p'
printf '%s\n' '--- cancel latch predicate ---'
nl -ba src/shared/agent-hook-cancel-verdict-latch.ts | sed -n '1,220p'

Repository: stablyai/orca

Length of output: 8311


Clear retained exit evidence only after an accepted status write.

transitionHookPresence admits non-ended hooks with source defined. A stale Grok stop hook can then reach isStaleGrokTurnEnd, which restores the previous row and returns. A late tool-progress hook can reach resolveCancelVerdictLatch, which holds the previous row and returns. Both paths currently clear the retained exit first, so later presence reconciliation can miss the proved exit.

Move the clear after each successful writeLegacyStatusRow call. Keep the existing source/process condition, and do not clear the exit for rejected or failed writes.

🐛 Suggested fix
-    if (payload.source !== undefined || payload.agentPresence?.process) {
-      // A hook (not a late terminal repaint) means an agent claimed the pane after the last exit.
-      this.forgetAgentExit(payload.paneKey)
-    }
+    const agentClaimedPane = payload.source !== undefined || payload.agentPresence?.process
...
       if (!this.writeLegacyStatusRow(enriched)) {
         return undefined
       }
+      if (agentClaimedPane) {
+        this.forgetAgentExit(enriched.paneKey)
+      }
       this.commitStatusRowMutation(rowBefore, enriched)
...
         if (!this.writeLegacyStatusRow(held)) {
           return undefined
         }
+        if (agentClaimedPane) {
+          this.forgetAgentExit(held.paneKey)
+        }
         this.scheduleStatusPersist()
...
     if (!this.writeLegacyStatusRow(enriched)) {
       return undefined
     }
+    if (agentClaimedPane) {
+      this.forgetAgentExit(enriched.paneKey)
+    }
     this.commitStatusRowMutation(rowBefore, enriched)

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]: Remote worker liveness misses agent death (agent killed → still "live"; host reboot → host_indeterminate forever)

1 participant