Repository navigation
Description
Summary
A transient provider failure permanently bricks the session. When a stream fails (e.g. OpenRouter's gpt-5.5 incident on 2026-06-11: response.failed / server_error: internal stream ended unexpectedly), the run terminates with StopError and the session lands in failed — a state with no outgoing transitions. The next prompt errors with session: illegal state transition: RecordUserPrompt from "failed" and the user loses their entire conversation context to a single upstream 5xx.
This is the known, deliberately-deferred "failed-recoverability" gap (CLAUDE.md: "a failed session is NOT resumable and still surfaces the illegal transition"; the compaction-orphan fix removed one trigger but explicitly deferred recoverability). Today's incident demonstrated its real cost.
Observed (live, 2026-06-11)
During an OpenRouter upstream incident (verified independent of mecatl: raw curl streaming requests failed 2/3 with the same response.failed, non-streaming fine, pre-batch build identical):
- First model call of a turn fails:
agent: start stream: response failed: server_error: internal stream ended unexpectedly(llmresilience retried its 3 attempts; all hit the incident). - Session →
failed. - Every subsequent prompt:
agent: record user prompt: session: illegal state transition: RecordUserPrompt from "failed". - The only escape is abandoning the session — all accumulated context gone. In one observed case the failure hit AFTER a successful tool-call turn, so real work was lost too.
The resilience layer did its job (3 attempts); the problem is the terminal state when all attempts fail.
Why it's currently this way (constraints a fix must respect)
failedwas made non-resumable because a failure could leave unpaired history (a mid-dispatch death orphans tool_use/function_call items) — replaying it draws a provider HTTP 400, which fails again: an unrecoverable loop. The cancel path already solved the same problem:Session.Interrupthistory-repairs (closes orphaned tool calls with synthetic error results) before returning toidle.- Some failures ARE history-poisoned (e.g. the historical compaction-orphan → provider 400). Recovery must not promise success — it must make RETRY possible, with history made structurally valid (
session.ValidateToolPairing). Reopenstays completed-only; the cancelled path stays onInterrupt. A failed-recovery seam should be a sibling, not a widening of those.
Proposed direction (for the architect — not prescriptive)
- A new
Sessionaggregate method (e.g.Recover():failed → idle) that history-repairs exactly likeInterrupt(synthetic error results for orphaned calls,ValidateToolPairingself-check) and clears the stop reason. - Drive it from the service layer's
loadAndReopen(the single run-entry funnel: completed→Reopen, cancelled→Interrupt, failed→Recover), so every wire surface (gRPC Converse, HTTP SSE, ACP) gets it for free. - The recovered session must replay cleanly: the failed turn's partial state (if any was recorded) must not leave dangling items.
- Tests: state-machine transitions; an e2e through server.Service proving a failed session accepts the next prompt and runs (mockllm: first run errors terminally, second run succeeds); an adversarial case where the failure orphaned a tool call mid-dispatch and the repair closes it; guard that a still-poisoned history (if irreparable) fails the run, not the recovery.
- Update the stale docs: CLAUDE.md's "failed is NOT resumable" gotcha, the run-entry-path bullet, and any design notes that record recoverability as deferred.
Context
Found during the 2026-06-11 OpenRouter gpt-5.5 streaming incident, debugging live sessions. Sibling of the resilience work (mid-stream stall watchdog, breaker) — this is the last leg: when resilience is exhausted, the session should degrade to "retryable," not "dead."
Activity
docs: full drift sync — every doc re-verified against the implementation
fix(openai): human-readable message for response.incomplete content_f…
feat(mecak8s): storage-free agent binary + ko/Taskfile wiring (Waves …
feat(mecak8s): kind-based k8s e2e proof suite (Wave 5, T5.1)
fix(subagent): recover a failed delegated child instead of refusing t…
fix(subagent): surface a failed delegation's real cause, and make a t…