fix(cache): --strict-cache fails a step whose key changed under its recording
Follow-up to #796, which re-recorded the entries. This PR makes the next cache key change fail loudly.
--strict-cache let a cache key change through. #732 bumped REPLAY_POLICY_VERSION and added the agent to the key, so every committed web-benchmark entry became a no-entry miss. Strict runs no-entry live by design, so the web-agent job kept passing while spending about 120 model calls per run.
- On a strict
no-entry, the runner now lists the file store and fails the step withREPLAY_STALEif an entry recorded for exactly the same step sits under another key. The listing is read once per worker and target, and only on a strict miss (packages/e2e/src/cache/rekeyed.ts). - "Same step" means test, target, instruction digest, params digest, occurrence, and agent name. Entries now record the last three in
recordedFor. The other key fields count as the environment: replay policy, engine minor, app identity, agent context, and project. A change to any of them makes the step stale. - Older entries only record test, target, and instruction. One of them could belong to another call of the same instruction, so strict ignores them instead of guessing. A confirmed whole replay in read-write mode proves which step an entry belongs to, so it writes the missing fields in (
completeProvenanceincache/context.ts). - 25 of the benchmark's 29 entries are migrated in their own commit. I made it with a local read-write replay, no model calls, and only
recordedForandcreatedAtchange. The other 4 are gap entries that need a live run. - These still run live: a new or edited instruction or params, a retry, a truncated entry, and non-strict mode (no listing there, so behavior is unchanged).
CacheStoreis unchanged. Listing is a method onFileCacheStoreonly, so a customcache.storeis not checked.- The message names the old entry file and repeats the existing re-record advice. It contains only a key hash. Provenance is compared in its redacted form.
AgentCacheContext.claimKeyHashis nowclaimKeyand returns the step's provenance. The unusedidentityfield is gone.
flowchart LR
A[strict step] --> B{own key in store?}
B -- hit --> C[replay as before]
B -- no-entry --> D{file store holds an entry for exactly this step under another key?}
D -- yes --> E[REPLAY_STALE, names the old file]
D -- no --> F[run live]
Verified
Ran it locally: yes. Surface: the apps/web-benchmark agent suite, run as CI=1 node node_modules/e2e/dist/cli/bin.js run --config e2e.agent.config.ts --strict-cache with no API key. A step that needs a model fails with MODEL_PROVIDER_FAILED, which is how you can tell it went live.
No false positives on this branch with the real policy (conservative/6):
Tests 8 failed | 25 passed (33)
Cache 25 replayed · 2 handed off · 7 missed
There were 0 REPLAY_STALE. The 8 failures are the steps that need a model, the same as on main: 3 with no recording, 2 gap hand-offs, and 3 planted-bugs judgments.
To simulate a key change I bumped REPLAY_POLICY_VERSION to conservative/7 locally and did not commit it:
| main | this branch |
|---|---|
every recorded step is no-entry and handed to the model (MODEL_PROVIDER_FAILED with no key, a silent pass with one) | all 25 migrated entries fail REPLAY_STALE with no model call; the 4 unmigrated gap entries and the never-recorded step run live |
FAIL web tests-agent/control-inventory.e2e.ts > control inventory > check sets the checkbox and the radio
REPLAY_STALE: the recording of this step no longer replays: the store holds it under another cache key (3016a446bf7d9b426938366e1bb8cdd7968d34bb154707fda2509486765e685e.json), since the runner, the engine, the app, or the agent's context changed after it was recorded, and cache.strict hands no step to the agent; re-record it with a read-write run without --strict-cache and commit the changed entry under .e2e/cache
❯ tests-agent/control-inventory.e2e.ts:20:5
Tests:
- New integration test in
trace-cache-replay.test.ts. It strips a recorded entry down to the old provenance, and a read-write replay completes it. It then changes the agent's context: strict fails withREPLAY_STALEand makes no model call, a lenient run goes live and re-records, and strict replays after that. - Unit tests in
step-cache.test.tscover a legacy entry (runs live), an edited instruction, other params, occurrence, agent, test, or target, a truncated entry, a masked secret in the title, and non-strict mode. - A
trace-cache-config.test.tstest checks the provenance completion on keep.
The fresh-context review and cubic both pointed at the old-entry wildcard: an unrecorded repeat could match an earlier occurrence's legacy entry. The fix replaced the wildcard with exact matching plus the migration. The review's other findings are also fixed: the message no longer tells users to delete an entry that may still serve another app identity, and the "once per run" comments now say once per worker and target.