fix(cache): a failure where no model answered evicts no recording
A read-write run with no model access deleted valid committed recordings. Replay handed a step to the agent (a gap, or a divergence), the provider rejected the request with MODEL_PROVIDER_FAILED, and the cache treated that like a failed flow: the step-level conclude('failed') evicted the consumed entry, and flushStagedTraces deleted every unconfirmed staged entry, including an act that replayed whole before an agent.assert that could not reach its model.
A failure where no model answered is a verdict on the provider, never on the app. It now evicts nothing, like an interrupt, while steps verified before it are still saved.
AGENT_CODE_TABLEmarks the codes that mean no model answered:MODEL_PROVIDER_FAILED(auth, rate limit, outage, the 120 s stall guard) andMODEL_UNAVAILABLE.isModelUnreachable()reads that flag (packages/e2e/src/agent/error.ts).- Step level:
StepOutcome'cancelled'becomes'no-verdict', covering a cancellation and a model that never answered.failedStepOutcome()maps a thrown error to it, andconcludedoes nothing for it (packages/e2e/src/agent/step-cache.ts). - Attempt level:
flushStagedTracestakes anAttemptSettlement. When every failure in the attempt (primary and secondary, e.g. anafterEachassertion) is model-unreachable,implicatesUnconfirmedis false: steps verified before the failure are still written, and every unconfirmed entry (a new recording or one a step replayed whole) is left exactly as stored (packages/e2e/src/cache/context.ts,packages/e2e/src/run/execute.ts). Interrupts keep skipping settlement entirely. - A model that answered with something unusable (
MODEL_OUTPUT_INVALID,CONTEXT_OVERFLOW) or a step that ran out of time (STEP_TIMEOUT, even with a request still open, since the 120 s stall guard outlasts the 30 s judgment default) still counts as a failure of the flow: the screen it was shown may be what went wrong. The model cannot pick either code in a verdict (MODEL_ERROR_CODESinprimitives.ts).
flowchart LR
F[step or attempt fails] --> Q{why}
Q -- interrupted --> K[cache untouched]
Q -- no model answered --> W[write confirmed, leave the rest]
Q -- other --> E[write confirmed, evict unconfirmed]
Docs: docs/cache.mdx, docs/coding-agents.mdx, docs/reference/errors.mdx, skills/e2e/references/agent.md.
Verified
Ran it locally: yes
- web benchmark, no
CI, noAI_GATEWAY_API_KEY:node node_modules/e2e/dist/cli/bin.js run --config e2e.agent.config.ts tests-agent/scenarios.e2e.ts --grep 'lying-labels|async-states|shadow-dom-form|iframe-form', thengit status. Both builds fail the 4 tests withMODEL_PROVIDER_FAILED(Cache 2 handed off · 2 missed, exit 3); only main deletes recordings.
| main | this branch |
|---|---|
D .e2e/cache/46163014...jsonD .e2e/cache/d01c00f9...jsonD .e2e/cache/ee64bc2d...jsonD .e2e/cache/ffc271f6...json | git status clean |
- New integration tests in
tests/integration/agent-trace-cache.test.ts: anactreplayed whole then anagent.asserton an unreachable model, and a replay that hands off mid-step to an unreachable model, both fail on main with the entry deleted and pass here with the entry bytes and mtime unchanged; a fresh recording confirmed by anexpectbefore the unreachable judgment is still written; a failingafterEachassertion after the unreachable judgment still evicts the replayed entry. - Mobile variant not run on a simulator; the replayed-whole-then-assert integration test covers the same path.