fix(cache): tell long-id steps apart under --strict-cache with an identity digest
Merged
SA
8d ago+243+243+012345678901234567890123456789-20-20-01234567890123456789
- Under
--strict-cache, a step whose key misses is checked for a recording of the same step under another key (packages/core/src/cache/rekeyed.ts). - That check compares provenance as an entry stores it, and
recordedProvenancecutstestId,targetId, andagentto 300 characters (packages/core/src/cache/recorder.ts). - Two ids that differ only after character 299 cut to the same string, so a never-recorded test matched another test's recording and failed with a false
REPLAY_STALE. - Now
recordedProvenancealso writes an optionalidentityDigest(SHA-256 of the whole redacted test id, target id, and agent name) whenboundwould make one of them ambiguous. That is when it cuts the name, or when the whole name already ends like a cut (…at 299 or 300 characters, which acreateAgentcache key can). Short-id entries are unchanged and keep the same cache key. readProvenancevalidates the digest likeparamsDigest, andstepKeykeys by it. A long-id step whose key really changed still fails withREPLAY_STALE.- An entry that cut a name before the digest existed never matches, so that step runs live.
completeProvenancewrites the digest into such an entry once a confirmed replay proves which step it belongs to. readTraceEntrydrops unknown fields, so older runners ignore the new one. There is noTRACE_SCHEMA_VERSIONbump, the same as whenparamsDigest,callIndex, andagentwere added.- Rebased onto main after #1737 moved the cache into
@e2e-dev/core, so the changeset names bothe2eand@e2e-dev/core. Main is merged in at66d07ca4, and thejaandzhcache tables get the new row. completeProvenancerewrites a kept entry only when its stored provenance lacks the occurrence fields or holds another identity digest, so a confirmed long-name entry that already has the step's digest keeps its bytes.
const ambiguous = [testId, targetId, agent ?? ''].some((text) => boundIsAmbiguous(text, MAX_TRACE_DESCRIPTOR_CHARS));
// ...
...(ambiguous ? { identityDigest: sha256Hex(JSON.stringify([testId, targetId, agent ?? null])) } : {}),
Issue
Fixes #1809
Verified
Ran it locally: yes
Built CLI at e6a69cfa against a scratch web project (later commits change only comments, docs, and tests): two tests under a 342-character describe title, each running agent.act('increment the counter') with a scripted model. Run 1 records the first test only (e2e run --grep 'first variant'). Run 2 is CI=1 e2e run --strict-cache on both.
| main (25bde7a7) | this branch (e6a69cfa) |
|---|---|
Tests 1 failed | 1 passed (2)Cache 1 replayed · 1 missedREPLAY_STALE: the recording of this step no longer replays: the store holds it under another cache key (…json), exit 2 | Tests 2 passed (2)Cache 1 replayed · 1 missedsecond test ran live (2 model calls), exit 0 |
- The recorded entry keeps a 300-character
testIdplusidentityDigest. Main and this branch write the same key file in the same project (3b488c9e….json). - After changing the agent's
context,--strict-cacheon the first test fails withREPLAY_STALE ... since the agent's context (its context, or the test's agentContext) changed after it was recorded. A long-id step whose key really changed is still caught. - A short-id entry carries no
identityDigest. - The same project with the describe title
checkout flowpasses 2 of 2 on main, so the id length is the trigger. - Mutations each fail the new tests:
- the digest left out of
stepKey,>changed to>=, onlytestIdchecked, the…case dropped,>= maxChars - 1changed to>= maxChars - the digest over unredacted names, the length measured on unredacted names, the target or agent name not redacted
- the digest dropped on read, the
typeofcheck on a read digest dropped, theparamsDigestcheck dropped - no backfill, a backfill on every replay (
recordedFor.identityDigest === undefined, which kdy1 tried), a backfill that never replaces or drops a stored digest
- the digest left out of
- The no-rewrite test counts the store's writes, since a rewrite in the same millisecond keeps the same bytes.
pnpm checkpasses.e2eunit tests: 3974 passed, 2 skipped, on the branch with main merged in.
🤖 Generated with Claude Code