Skip to content

Handoff-pause terminal RuntimeEvent lacks terminal status, breaking Session read model (revision/copy fail with persistence_failed) #5836

Closed

Description

@me2seeks

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

  1. Writer — packages/runtime/src/agent-run.ts, AgentRun.reachHandoffBoundary (~L475-488) commits the pause event as:

    { "actions": { "endInvocation": true, "handoffPause": { "hostEpoch": "…", "successorRunId": "…" } } }

    with no status field. None of the existing terminal statuses (completed/failed/aborted/cancelled) describes "paused for handoff", so it is omitted.

  2. Reader — packages/runtime/src/runtime-event-read-model.ts, classifyRuntimeEventTerminalFact (~L855-863) requires a terminal status on any terminal event and otherwise refuses classification (diagnostic incomplete_event: "terminal RuntimeEvent requires a terminal status for recovery").

  3. RuntimeReadModel.getSessionView (~L136-140) then throws RuntimeReadModelError: RuntimeEvent ledger has no valid terminal fact for a terminal run.

  4. Observability gap — packages/runtime-host/src/server/session-revision-coordinator.ts (~L356-360, plus the sibling catch below it) swallows that error in a blanket catch and returns persistence_failed. The RuntimeReadModelError.diagnostics carries the exact eventId/runId/turnId and 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):

  1. Desktop restarted while a Turn was in flight in the affected Session.
  2. The old host epoch paused the Turn at a safe boundary, writing the status-less handoff-pause event (the only handoffPause event in the entire ledger, ~40k events).
  3. 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.
  4. Any later edit & resend on that Session → getSessionView throws → 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

  1. Reader (required, ship first) — in classifyRuntimeEventTerminalFact, before the terminal-status check, branch on terminalEvent.actions?.handoffPause and 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_exists vs continuation_claim_repair_required). The new fact shape must remain distinguishable — do not masquerade as completed.
  2. 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 or handoffPause", encoding the exception explicitly instead of silently violating it.
  3. Contract test — pin the writer→reader round-trip with the real captured event shape (endInvocation: true + handoffPause, no status) as a fixture.
  4. Observability — log the swallowed error (with its diagnostics) in both blanket catch sites in session-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

  1. self-assigned this
    on Sep 29, 2026
  2. added a commit that references this issue on Sep 30, 2026
    ba60e97
  3. added a commit that references this issue on Sep 30, 2026
    4607a26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions