fix(cache): a failure where no model answered evicts no recording

Merged
OK
2mo ago
+308-63

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_TABLE marks the codes that mean no model answered: MODEL_PROVIDER_FAILED (auth, rate limit, outage, the 120 s stall guard) and MODEL_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, and conclude does nothing for it (packages/e2e/src/agent/step-cache.ts).
  • Attempt level: flushStagedTraces takes an AttemptSettlement. When every failure in the attempt (primary and secondary, e.g. an afterEach assertion) is model-unreachable, implicatesUnconfirmed is 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_CODES in primitives.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, no AI_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', then git status. Both builds fail the 4 tests with MODEL_PROVIDER_FAILED (Cache 2 handed off · 2 missed, exit 3); only main deletes recordings.
mainthis branch
D .e2e/cache/46163014...json
D .e2e/cache/d01c00f9...json
D .e2e/cache/ee64bc2d...json
D .e2e/cache/ffc271f6...json
git status clean
  • New integration tests in tests/integration/agent-trace-cache.test.ts: an act replayed whole then an agent.assert on 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 an expect before the unreachable judgment is still written; a failing afterEach assertion 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.