Repository navigation
Description
Summary
A handoff-pause terminal RuntimeEvent is written without a terminal status, and the read model's terminal-fact classifier refuses it. Any Session containing such an event becomes unreadable through RuntimeReadModel.getSessionView, so every full-view operation on it — edit & resend (session.revision.create), branch, side-conversation copy — fails deterministically with persistence_failed ("Source conversation ledger is unavailable"), surfaced to the user only as a generic "operation failed" toast.
Reproduced against a copy of a real production state root using the repository's own SqliteRuntimeStore + RuntimeReadModel at HEAD (0cb4fc32b).
Root cause: writer/reader asymmetry around handoffPause
-
Writer —
packages/runtime/src/agent-run.ts,AgentRun.reachHandoffBoundary(~L475-488) commits the pause event as:{ "actions": { "endInvocation": true, "handoffPause": { "hostEpoch": "…", "successorRunId": "…" } } }with no
statusfield. None of the existing terminal statuses (completed/failed/aborted/cancelled) describes "paused for handoff", so it is omitted. -
Reader —
packages/runtime/src/runtime-event-read-model.ts,classifyRuntimeEventTerminalFact(~L855-863) requires a terminal status on any terminal event and otherwise refuses classification (diagnosticincomplete_event: "terminal RuntimeEvent requires a terminal status for recovery"). -
RuntimeReadModel.getSessionView(~L136-140) then throwsRuntimeReadModelError: RuntimeEvent ledger has no valid terminal fact for a terminal run. -
Observability gap —
packages/runtime-host/src/server/session-revision-coordinator.ts(~L356-360, plus the siblingcatchbelow it) swallows that error in a blanketcatchand returnspersistence_failed. TheRuntimeReadModelError.diagnosticscarries the exacteventId/runId/turnIdand would have made this a one-minute diagnosis.
Note the asymmetry: the projection path already special-cases handoffPause (runtime-event-read-model.ts ~L577-578 does not project terminal turn state for it, since the turn's terminal state belongs to the successor run). Only the terminal-fact classifier lacks the branch.
Evidence
Timeline captured from a real install (Desktop on Windows, Runtime Host in WSL2):
- Desktop restarted while a Turn was in flight in the affected Session.
- The old host epoch paused the Turn at a safe boundary, writing the status-less handoff-pause event (the only
handoffPauseevent in the entire ledger, ~40k events). - The new host epoch resumed the handoff — and tripped on the same event shape: the successor Run was immediately terminated with
failureClass: missing_terminal_event("Handoff Run Composition execution semantics changed"). So the in-flight Turn died at the restart, too. - Any later edit & resend on that Session →
getSessionViewthrows → toast.
Deterministic replay (repro harness): opening a copy of the live runtime.sqlite read-only and calling RuntimeReadModel.getSessionView for each of the 41 Sessions — 40 read clean; exactly the one Session containing the handoffPause event throws the error above. Perfect correlation. Database integrity is fine (quick_check ok): this is a code defect, not data corruption.
Impact
- Blast radius: any Session whose invocation was paused by host handoff. Transcript paging still works (different read path), so users can view history but every
getSessionView-based operation fails permanently. - Ledger immutability: existing events will never gain a
status— a writer-only fix cannot heal already-affected Sessions.
Suggested fix
- Reader (required, ship first) — in
classifyRuntimeEventTerminalFact, before the terminal-status check, branch onterminalEvent.actions?.handoffPauseand produce a distinguishable fact (e.g.runStatus: 'handed_off'; the turn's terminal state stays with the successor run).RuntimeEventTerminalFact.runStatus(~L254) is currently the closed union'completed' | 'failed' | 'cancelled'and needs extending.- Caution:
packages/runtime/src/runtime-resume.ts(~L668-684) calls the same classifier and relies on "no fact" to recognize the paused state when deciding handoff resume (continuation_already_existsvscontinuation_claim_repair_required). The new fact shape must remain distinguishable — do not masquerade ascompleted.
- Caution:
- Writer (optional hardening, ship after the reader fix) — restore the invariant "a terminal event carries a terminal status" by writing an explicit new status (e.g.
paused); do not reuse the existing four values. A new enum value makes older builds reject new events, so this must roll out after the reader fix is widespread. Also assert at the terminal-write path: "either a terminal status orhandoffPause", encoding the exception explicitly instead of silently violating it. - Contract test — pin the writer→reader round-trip with the real captured event shape (
endInvocation: true+handoffPause, nostatus) as a fixture. - Observability — log the swallowed error (with its
diagnostics) in both blanketcatchsites insession-revision-coordinator.ts.
After the reader fix lands, already-affected Sessions heal with no data migration — the data was never wrong.
Environment
Observed on a Maka Desktop dev build (Electron on Windows) driving a Runtime Host in WSL2; reproduced with repository HEAD 0cb4fc32b.
Activity
fix(runtime): classify handoff-pause terminal RuntimeEvents as handed…
fix(runtime): classify handoff-pause terminal RuntimeEvents as handed…