Repository navigation
fix(orchestration): remote worker liveness reports exited when the host proves the agent gone - #29276
Conversation
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to
|
2f10586 to
56a26bf
Compare
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:
4f7b0170-51a5-46a2-9716-2766eec5f63b
📒 Files selected for processing: 17
src/main/agent-hooks/agent-hook-runtime-deps.tssrc/main/agent-hooks/server-agent-presence.test.tssrc/main/agent-hooks/server/server-agent-presence.tssrc/main/agent-hooks/server/server-authority-aliases.tssrc/main/agent-hooks/server/server-cleanup.tssrc/main/agent-hooks/server/server-ingest-terminal.tssrc/main/agent-hooks/server/server-state.tssrc/main/agent-hooks/server/server-status-update.tssrc/main/runtime/construction/runtime-construction-dependencies.tssrc/main/runtime/orchestration/worker-terminal-release-runtime.tssrc/main/runtime/rpc/methods/orchestration/federation/federation-agent-death-liveness.test.tssrc/main/runtime/rpc/methods/orchestration/federation/federation-attachment-observation.tssrc/main/runtime/rpc/methods/orchestration/federation/federation-control.tssrc/main/runtime/terminal/adoption/adopt-terminal-orphans-from-inventory.tssrc/main/runtime/terminal/driver/terminal-driver-resources.tssrc/main/runtime/terminal/input/terminal-agent-status-and-submission.tssrc/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.
|
|
||
| /** 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) |
There was a problem hiding this comment.
🎯 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 -100Repository: 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.tsRepository: 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.tsRepository: 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 -130Repository: 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 -100Repository: 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.tsRepository: 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 -70Repository: 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.tsRepository: 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 -100Repository: 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.tsRepository: stablyai/orca
Length of output: 13028
🏁 Script executed:
sed -n '165,210p' src/shared/orchestration-fleet-worker-projection.tsRepository: 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 -100Repository: 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.tsRepository: 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.tsRepository: stablyai/orca
Length of output: 6335
🏁 Script executed:
sed -n '25,48p' src/main/runtime/rpc/methods/orchestration/federation/federation-control.tsRepository: 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.
de8c8a5 to
b9693a8
Compare
951e9a0 to
3790842
Compare
…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]>
3790842 to
84a44be
Compare
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:
380e2ab5-30bd-4534-87ee-1ba031b980a3
📒 Files selected for processing: 3
config/scripts/vitest-sqlite-runtime-files.mjssrc/main/agent-hooks/server/server-agent-presence.tssrc/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.
| 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) |
There was a problem hiding this comment.
🗄️ 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-hooksRepository: 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-hooksRepository: 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-hooksRepository: 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)
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
live, because only the terminal was checked and the shell had taken the prompt back.unverifiable / host_indeterminateforever, withnextAction: none.After
exited, andnextActionbecomesrecover(read the transcript, then stop or abandon).Mechanism
observeRemoteAttachmentLivenesswraps the existinginspectRemoteAttachment, and it feedsorchestration.federationFleetSnapshotandorchestration.federationShow.checkTerminalAgentPresence(handle, exitedSince), which reusesrecheckHookAgentPresenceForPty. The store compares the agent's hook-captured PID and start time against the process table.agentExitedAtByPaneKey), whether the proof came from aSessionEndhook 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.inspectTerminalProcessIncarnationLivenessthat worker-release already trusts. It reportsexitedonly when the table was read and the process is absent.Why
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_indeterminateis a reason under theunverifiableverdict, not a fourth verdict, so the live/unverifiable/exited vocabulary already holds. The bug was that no proof was ever looked for.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, plusretained agent exitcases inserver-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 stayslive, and an unreadable process table staysunverifiable.Re-ran the existing federation liveness, fleet-snapshot and federation suites plus
agent-prompt-submission-runtime.test.ts.pnpm tc:nodeandcheck:code-quality:changedpass.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
orca serverestart the verdict falls back to the terminal's (live) for an agent that died before the restart.worker-stopafter a reboot still reportsstop_unknown;worker-abandonremains the exit route thatrecoverpoints to.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)