feat(cache)!: keep one reviewable YAML file of replay recordings per test

Closed
KD
2d ago
+8542-7581

What

Each test's replay recordings are one reviewed <test>.yml under .e2e/cache/, beside a generated <test>.lock.json that holds the keys and digests. They replace one JSON file per cache key, named by a hash. The file is named for the test: tests/admin/login.e2e.ts's signs in is admin-login-signs-in.yml.

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 ] }
  • e2e cache ls prints one row per recording: file, target, instruction, age, actions. Trace pages name the test's file and the key.
  • Breaking: <key>.json entries are no longer read. A run on the built-in file store says how many the cache directory holds, e2e cache ls counts them, and clear deletes them; a read-write run records the steps again. There is no deprecation window, by decision for this change. The changeset is a minor with **Breaking:**.
  • CacheStore.read and delete take the step as an optional second argument (TraceProvenance, now exported). A store may ignore it; tests/types/sdk-types.ts asserts that a key-only store still type-checks.

Why

A reviewer of a re-recording saw a list of digests and nested JSON, so committed recordings went unreviewed. #1692 (closed) kept the one-file-per-key shape in YAML. This makes one test one file, in the order the test runs its steps, and moves what nobody reads into a generated lock.

How it works

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]
  1. Format (packages/core/src/cache/recording-file.ts). Each step sits under its act and params, 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, or unknown keys), action summaries are rebuilt from the actions, and a repeated act shows call: N. A target carries every descriptor field, including #2093's twinsWithoutTestId and countedOnEarlierLook. The header names the test's file and titles. A setup test (setup::<file>::...) is marked (setup), and a createAgent key (core:<key>) is shown as written. A summary that quotes a unique() slot is made again from the filled action (cache/template.ts), so a parameter named with a quote still replays. tests/unit/trace-store-fields.test.ts names every field of each action, the target descriptor, the trace, its provenance, its executor, and the types nested in them (position, point, place in a node, viewport, model, key context) in records the types make exhaustive, and round-trips a fixture that sets all of them. A field added to trace-1 fails the typecheck until a fixture sets it, and the round trip fails until the YAML keeps it, so the format cannot fall behind the trace types without a failing check.
  2. Lock (<test>.lock.json, linguist-generated in .gitattributes). Per recording it holds the key, digests, provenance (executor, model, summary), the end wait in whole seconds (a replay input no digest covers, capped at 120 s), 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 as invalid-entry. The exception is an entry that says its act or params are redacted or cut: only its digests hold it, so the docs ask reviewers to open a lock change that comes with no YAML change.
  3. Step check (packages/core/src/agent/step-cache.ts). A hit replays only when the entry's recorded step is the step that claimed the key, identity digest included (it tells apart long names cut to the same text), so keys swapped in a hand-merged lock never replay.
  4. Store (packages/core/src/cache/store.ts). A step keeps one recording per target, and a new step lands where the test runs it. A write takes the test's lock (cache/file-lock.ts: a wx file holding its holder's random token, taken over after 30 s, checked again right before the renames). It replaces both files as one (internal/atomic-write.ts) and refuses to rewrite a file that holds a recording it cannot read. An eviction that cannot write the pair back fails. In a pair whose YAML holds a recording that does not read, an evicted key that replays leaves the lock alone and its block stays for a person to delete. An edited step's own key keeps its entry, so undoing the edit restores it. Settlement hands the file store a test's confirmed recordings together (writeAll, from settleStagedTraces in cache/context.ts): one lock and one rewrite of the pair for all of them. If the pair cannot take them together, or that write throws, the store writes them one at a time, so each gets the answer it would alone. Any other store still gets one write per step. A parsed pair is reused while its text is unchanged. Each file is sized and read through one open handle, and only a file that is not there (ENOENT, ENOTDIR) reads as absent: any other error makes the pair unreadable, so a lock is never taken for one whose YAML was deleted. A YAML whose last step was deleted (a bare steps:) reads as holding nothing, and a step whose last target was deleted reads as not recorded.
  5. Names (cache/recording-name.ts). A name is the test file's folders below the top one, its file name without the last two extensions (checkout.web.e2e.ts is checkout-web), and its titles, in ASCII kebab case. When two tests' names come out the same, the second to record adds --<hash of its test id>. A name that leaves part of the test out always carries that hash, so it doesn't depend on which test records first. That covers a title in Japanese, a createAgent key the name can't spell, or a name cut at 80 characters. All of a stem's tests share one lock file, whatever their suffix. cache.strict looks for a step recorded under another key in its own test's file only (cache/rekeyed.ts), so a writer of a test in another file never holds it up.
  6. Crash between the renames. Before its first rename, a writer records the lock it means to publish, with the digests of the new YAML and of the lock it replaces, in .<test>.pending under the test's base name. The next run that takes the lock and writes puts that lock in place when the YAML on disk is the new one beside the lock it replaced, and drops the record otherwise (no rename happened, both did, or a checkout replaced the pair). It keeps the record while the YAML or the lock cannot be read whole. A write that throws keeps the record too, since its rollback may have failed. A file at that path that is not such a record is left alone. A test filed under a --<hash> name is settled the same way. Until a writing run settles it, a strict run and e2e cache ls handle the step being recorded this way: a step recorded again reads as invalid-entry, a step being added reads as not recorded, and a test's first recording reads as invalid-entry. A lock file left empty by a writer killed before it wrote its token goes stale like any other.
  7. Provenance (cache/recorder.ts, cache/context.ts). An entry keeps the step's instruction and params, redacted (numbers that spell a secret included); params where two keys redact to the same text are left out, like params over the size cap. It is redacted again at settlement, so a secret the run learns after the step never reaches the file. A staged entry holds only the step and the redactor for that, not the step's session.
  8. CLI and reports (packages/e2e/src/cli/cache.ts, run/runner.ts, report/traces.ts). A run on the file store counts the <key>.json files in the cache directory before its tests start and prints one run notice with the count and the steps: clear, then record in a read-write run with strict cache off, since a strict or read-only run never writes; the file pattern lives in the core store, shared with e2e cache. clear deletes only files the store wrote, under each test's lock, plus a crashed writer's temporary files and pending record, and a stale lock, which it takes through the lock's own takeover rather than deleting it by path. It counts a working file as the store's only under a name a recording can take. A lock counts as the store's when it opens with an e2e-replay-lock format of any version. Another tool's file stays, and the CLI names it. A pair the user cannot open is listed as unreadable and left. A trace page names the test's recording file on the test's own steps only (a createAgent session's step records under its own key) and only when the file is there; otherwise it gives the key alone. docs/cache.mdx gives the two .gitignore lines that keep a writer's working files out of a committed cache, and both benchmarks use them.
  9. 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.

Known limits, documented in docs/cache.mdx:

  • Runs of one target against two app identities replace each other's recording of a step.
  • When two tests' names come out the same and spell every word of each (tests/login.e2e.ts and e2e/login.e2e.ts, which differ only by top folder), the second to record gets the --<hash> suffix.
  • A test whose title spells a secret the run learns only mid-test is filed under the redacted title and records again on every run. An agent or target name that spells one reads as invalid-entry. When an agent context spells one, a step repeated on both sides of the fill that resolves it keeps one recording of the two.
  • A reader that cannot take a test's lock (a read-only cache directory, or one that does not exist yet) reads without it, so it can catch a pair another mount's writer is halfway through replacing. Only --strict-cache fails on that, and it serves committed caches, which nothing writes.
  • 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.

Also accepted in review, and not in the docs, since each needs a stalled process or another tool writing into the cache directory:

  • A writer that stalls more than 30 s while it holds a test's lock (a suspended machine, say) can be taken over, then still publish over its successor or remove the successor's lock when it lets go. A lock file cannot fence a rename or an unlink by path. The takeover guard (<lock>.takeover) has the same gap when two waiters find one a dead waiter left, and so does cache clear when it removes a stale guard.
  • The store does not guard its own names against another tool's files: .<test>.pending, <name>--<hash>.yml and .lock.json, and its temporary files.
  • When another step's YAML block is edited, an evicted step that replays keeps its block, with no lock entry. Once the edit is undone, that orphaned block stops every write to the pair until a person deletes it. cache ls names the block.

Docs: docs/cache.mdx, reference/cli.mdx, reference/config.mdx, reference/agent.mdx, reference/security.mdx, debugging.mdx, self-healing.mdx, and skills/e2e/references/running.md.

Verified

Ran it locally: yes. At caf1f6144 (the head, 350e54812, adds only an empty commit; see the CI line) (the changes from okwasniewski's review, and Cubic's on those, on top of 1175292fa, which merged main at 614bb3d73 with no conflicts):

  • pnpm check: passed.

  • The whole e2e unit project: 5,271 passed (2 skipped). trace-store.test.ts is split in two (trace-store-lock.test.ts takes the lock and crash-recovery cases), with the same 71 tests.

  • trace-store-fields.test.ts: passes. It fails when the renderer drops a scroll's spans, and the typecheck fails when a field is added to the descriptor, to navigate, to the trace, or to TracePosition.

  • legacy-cache-notice.test.ts: passes, and fails without the notice. The built CLI on the testbed, with two <key>.json files in .e2e/cache:

    ℹ .e2e/cache holds 2 files in the replay cache format of an older e2e, one <key>.json per entry, which no run reads, so the steps recorded there run live; run e2e cache clear, then record them again in a read-write run with strict cache off (clear deletes the new recordings too)
     ✓ target "web" command at http://127.0.0.1:4271/ ready 87ms
    ...
     ✓ |web| tests/check.e2e.ts (13 tests) 2.02s
    
  • CI at 350e54812, the head: every check green, CodeQL included. Web passed 130. Web agent passed 34 (5 skipped), with 26 of 36 agent steps replayed from cache. iOS passed 67 (1 skipped), iOS agent 21 (1 skipped), Android 68 (1 skipped), Android agent 20. Microbenchmarks: no case changed by 0.5% or more. 350e54812 is an empty commit: CodeQL's run on caf1f6144 failed on GitHub Actions' installation rate limit, and GitHub does not retry a default-setup CodeQL run.

At b8abe2779 (the CodeRabbit and Cubic fixes on top of 5a0762bef, which merged main at d46f2ade8; four docs pages conflicted where main trimmed the reference (#2448): CacheStore keeps its step parameter, now described in the field table, and StepCacheInfo.entry names the lock file, not <entry>.json):

  • pnpm check: passed.
  • The cache test files (trace-store, cli-cache, step-cache, traces, trace-template, trace-cache-config, atomic-write, report-list, report-failure-text, and the trace-cache-*, agent-trace-cache, cache-model-provenance, and core integration suites): 515 tests passed, and the whole e2e unit project 5,232 (2 skipped). Each code fix since 7b368458a adds a test, checked to fail without the fix. Three have none: the staged-provenance change in step-cache.ts (it only drops a closure's hold on the step session), and the two lock-race fixes (clear taking a stale lock through takeover, and isStale reading the token before the age), whose interleavings need a hook between two syscalls.
  • Saving a test's recordings at settlement, measured with the built store: 20 steps of one test took 192 ms written one at a time and 9 ms together; 60 steps, 925 ms and 22 ms; 100 steps, 2,595 ms and 29 ms. Every step was saved both ways.
  • Web benchmark, agentic suite replaying the committed recordings with CI=1 --strict-cache and a dummy model key, set up as below: the same result as at 7b368458a. 26 of 34 passed, all 26 replayed with no model call, and Cache 26 replayed · 3 handed off · 6 missed. There was no REPLAY_STALE, and .e2e/cache was unchanged.
  • Every committed recording keeps its file name under the new naming rules.
  • CI at that head, all checks green:
    • Web: 95 passed. Web agent: 34 passed, 26 agent steps replayed from cache.
    • iOS: 67 passed (1 skipped). iOS agent: 20 passed (1 skipped), 11 of 25 agent steps replayed. Against 5a0762bef, two steps differ. Login Form replayed 5 of its 6 actions: the sixth taps "Not Now" on iOS's save-password prompt, which did not appear this run, and main's recording holds the same tap. Broken Accessibility was retried, and a retry runs live.
    • Android: 68 passed (1 skipped). Android agent: 20 passed, 15 of 24 agent steps replayed. These counts match main.
    • Reruns: iOS deterministic failed once in setup, waiting for the app's home screen; the rerun passed. This change does not touch packages/mobile or the app. Earlier at this branch, test-step.test.ts › "cuts the call running in a step as the timeout cuts any call" failed on Node 22 and passed on a rerun; main fails it too, on Node 22.22.3, 24, and 26 (its spec runs at f67aebcbb, 3834ab7ca, 7b17c4638).

At 7b368458a (this branch with main at c289aff59 merged in):

  • pnpm check: passed.
  • pnpm test: e2e passed (399 files, 1 skipped). @e2e-dev/web failed 6 Firefox tests (browser-info, cookies-url, network, press-characters, webmcp): Firefox would not launch on this Mac (Could not find profile folder). This branch does not change packages/web; CI runs them on Linux.
  • The 21 test files that touch the cache: 777 tests passed, #2093's trace-cache-twin-gone included. That file failed 6 of 6 on the merge before the target fields were added.
  • Crashed pair write of a test filed under a --<hash> name: the new case in tests/unit/trace-store.test.ts passes. It fails when the suffix strip in pendingPath is removed.
  • Web benchmark, agentic suite replaying the committed recordings with CI=1 --strict-cache and a dummy model key (app on port 4391, app.identity pinned to http://127.0.0.1:4280/ so keys match): 26 of 34 passed, and all 26 replayed with no model call. The 8 failures are the steps that need a model (3 gap hand-offs, 2 gap misses, 3 planted-bug judgments with no recording), all MODEL_PROVIDER_FAILED. There was no REPLAY_STALE or invalid-entry, and .e2e/cache was unchanged.

At e92a62efc, before the merge, and not run again since:

  • Web benchmark deterministic suite: 95 passed. Testbed default suite: 600 passed.
  • All 70 committed recordings read back through the built store as hits and re-render to the same bytes. main has added no recordings since.
  • Mobile: not run on a device locally (no simulator); CI runs the recordings on devices, as above.

e2e cache ls and stats on the web benchmark's committed recordings, at b8abe2779:

FILE                                                                                 TARGET  STEP                                              AGE  ACTIONS
control-inventory-a-long-press-and-a-double-click-are-chosen-over-a-plain-tap.yml    web     long-press the Hold me button until its state r…  53d  2
control-inventory-a-right-click-opens-the-file-menu-and-rename-renames-the-file.yml  web     rename report.pdf to summary.pdf; its menu open…  53d  3
control-inventory-check-sets-the-checkbox-and-the-radio.yml                          web     agree to the terms and pick the Medium size       53d  2
...
directory  apps/web-benchmark/.e2e/cache
tests      31
entries    31
size       69.4 KiB

Evidence not captured:

  • Terminal recording of e2e cache ls: VHS is not installed on this machine, so the output is pasted as text above.
  • pnpm bench:ab: not run. Its runs replay with CI=1, read-only, so they never reach settlement's writes, which the timings above measure directly. The strict replay above shows the same replay counts as main (26 of 34, no model call).
  • Docs screenshots: not taken. The docs pages pass pnpm docs:check (MDX compiles, links resolve).
  • Linear ticket in the title: none found that covers this change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Replay recordings are now organized into one reviewable YAML file per test, with a generated companion file to verify recording integrity.
    • e2e cache ls shows recording files, targets, instructions, and action counts; cache statistics report test and recording totals.
    • Replay recordings now include step attribution, helping strict replay detect recordings that don’t match the current test step.
  • Bug Fixes
    • Invalid or mismatched recordings are rejected instead of replayed.
  • Documentation
    • Updated cache guides with the new format, legacy-cache behavior, and recording review and refresh steps.