feat(cache)!: keep one reviewable YAML file of replay recordings per test
The file store kept one JSON entry per cache key, named by a hash. A reviewer of a re-recording saw a list of digests and nested JSON, and #1692 (closed) kept that one-file-per-key shape in YAML. This replaces it: each test's recordings are one reviewed <test>.yml, and a generated <test>.lock.json holds what a reviewer never reads.
test: control inventory › check sets the checkbox and the radio
file: tests-agent/control-inventory.e2e.ts
steps:
- act: agree to the terms and pick the Medium size
targets:
web:
at: /e/control-inventory
do:
- check: { role: checkbox, name: Agree to terms, within: Toggles }
- check: { role: radio, name: Medium, within: Size }
expect:
shows:
- { role: status, name: Toggles state, text: "terms agreed, size Medium" }
- { role: checkbox, name: Agree to terms, states: [ checked ] }
What changed
- Format (
packages/core/src/cache/recording-file.ts): each step sits under itsactandparams, then per target what a replay does (do) and what it checks (expect). The YAML is the replay input itself: it is read with the core schema only (no tags, anchors, aliases, unknown keys), and action summaries are rebuilt from the actions. A repeatedactshowscall: N. - Lock (
<test>.lock.json,linguist-generatedin.gitattributes): per recording its key, digests, provenance (executor, model, summary), end wait in whole seconds, and a digest of the recording as the YAML reads back. A lock entry finds its YAML block by that digest, so moving steps, deleting one, or keeping both sides of a merge leaves the rest readable. An edited block, or a key pointed at another step's recording, reads asinvalid-entry; on top of that, a hit replays only when the entry's recorded step is the step that claimed the key (agent/step-cache.ts), so keys swapped in a hand-merged lock never replay. - Store (
packages/core/src/cache/store.ts): a step keeps one recording per target. Writes take a per-test lock (cache/file-lock.ts: awxfile holding its holder's random token, taken over after 30 s, and checked again right before the renames), replace both files as one (writeFilesAtomic), and refuse to rewrite a file holding a recording they cannot read. A writer records the lock it means to publish, with the digest of the YAML, before its first rename; the next run that takes the test's lock puts that lock in place when the YAML on disk is the new one, and drops the record when it is not, so a process killed between the two renames leaves no new YAML beside an old lock. A YAML whose last step was deleted (a baresteps:) reads as holding nothing. A parsed pair is reused while its text is unchanged. A new step lands where the test runs it. - Provenance: an entry now keeps the step's instruction and params, redacted (numbers that spell a secret included), and redacted again at settlement so a secret the run learns after the step never reaches the file.
- CLI and reports:
e2e cache lsprints file, target, instruction, age, actions;cleardeletes only files the store wrote, under each test's lock. Trace pages name(<test>.yml, key <12 hex>). - Benchmarks: the 70 committed entries (31 web, 39 mobile) are converted to 53 pairs with the same keys and creation times. Their YAML is 1,907 lines.
flowchart LR
S[step claims key K] --> L[lock entry for K]
L -- digest --> Y[YAML block]
Y -- act / params digests --> L
L -- recordedFor --> C{same step as the claim?}
C -- yes --> R[replay do, check expect]
C -- no --> I[invalid-entry]
Breaking
<key>.jsonentries are no longer read (no deprecation window, decided for this change).e2e cache lscounts them,cleardeletes them; aread-writerun records the steps again. The changeset is aminorwith**Breaking:**.CacheStore.readanddeletetake the step as an optional second argument (TraceProvenance, now exported); a store may ignore it.tests/types/sdk-types.tsasserts a key-only store still type-checks.
Known limits (documented in docs/cache.mdx)
- Runs of one target against two app identities replace each other's recording of a step.
- Two tests whose names come out the same get the second a
--<hash>suffix, in the order they first record. - A test whose title spells a secret the run learns only mid-test is filed under the title redacted and records again each run.
- Each of a test's two files is capped at 1 MiB, as one entry was, so a test whose recordings outgrow that stops recording new steps.
Docs
docs/cache.mdx (what a recording holds, commit, strict), reference/cli.mdx, reference/config.mdx, reference/agent.mdx, reference/security.mdx, debugging.mdx, self-healing.mdx, skills/e2e/references/running.md. The shortening pass merged the "What a recording holds" bullets (498 to 324 words): the lock moved into the intro, ordering and call share a bullet, and the commit section's reader paragraph and the invalid-entry row no longer repeat them. Cut on purpose: the reason a merge resolves (lock entries are found by digest), since the instruction to keep both sides stands without it.
Verified
Ran it locally: yes
- Web benchmark, deterministic suite (
e2e run, app on port 4391 because 4280 was taken by another checkout): 43 files, 95 tests passed. - Web benchmark, agentic suite replaying the committed recordings with
CI=1 --strict-cacheand a dummy model key (app.identitypinned tohttp://127.0.0.1:4280/so keys match): 26 of 34 passed, and all 26 replayed with no model call (self-finalizedon every recorded step,modelTokens: 0). The 8 failures are the steps that need a model by design (3gaphand-offs, 2gapmisses, 3 planted-bug judgments with no recording), allMODEL_PROVIDER_FAILEDorASSERTION_FAILED; noREPLAY_STALEorinvalid-entry. The run left.e2e/cacheunchanged. - Testbed default suite: 600 passed.
- All 70 committed recordings read back through the built store as hits and re-render to the same bytes.
- Crash recovery:
tests/unit/trace-store.test.tskills a child process (SIGKILL) as it renames onto the lock, and as it renames onto the YAML, then reopens the cache: the first finishes the new pair, the second keeps the old one. The same file reads a baresteps:as a miss and records over it. The three new cases fail on the previous head and pass now; the cache unit suites pass (131 tests). - Mobile: not run on a device locally (no simulator); the 39 mobile recordings were checked by store read-back. CI ran them on devices: the agentic suites replayed the same share of steps as on main (android 15 of 24 agent steps, ios 12 of 25, the same counts as #2088 and #2089), and the deterministic suites passed (android 60, ios 59).
🤖 Generated with Claude Code