feat(cache)!: store one readable YAML replay per test
- Replace the per-act JSON cache with one readable YAML file per test in
cache.dir, default.e2e/cache/. Instructions and compact action maps come first; replay keys and verification evidence stay with the act. - Breaking: delete old
.jsonand.replay.tscaches and regenerate withcache: 'read-write'. Neither old format is read, including in strict mode. There is no migration, format switch,e2e/replayexport, ore2e cache diff. - Keep the existing replay executor, conservative target matching, concurrent transition/outcome checks, alert detection, partial-action recovery, runtime-value handoffs, verification boundary, and strict behavior. Web and mobile share the same storage and replay path.
Format
Excerpt from the converted web control-inventory recording, with its generated replay and identity metadata omitted:
test: control inventory › back returns from the details view to the inventory
file: tests-agent/control-inventory.e2e.ts
recordedWith:
engine: 1
platform: web
app: dc587874e98340c0ead3b9555bef25c85bca9337c6c8e28ae9e991c982ef1202
contextDigest: "02e45116d4a18a6603260cbbc8fa198d311b6a1a01362cc9dd6aa341d16bb3cf"
acts:
- instruction: open the details, then return to the inventory through the browser history
steps:
- tap: { role: button, name: Open details, within: Navigation }
- back: {}
- wait: { role: status, name: Navigation state, text: back on the inventory }
- waitGone: { role: status, name: Navigation state, text: not opened }
waitandwaitGoneare the existing positive and negative outcome anchors. They are checked together with the stored wait budget, not executed as sequential sleeps. Transition spans and partial-action evidence remain intact.typecarries eithervalueorsecret;press: Enterrepresents keyboard input. Optionalparamsretain projected values andunique()slots. Custom tool and runtime-derived gaps stay explicittoolhandoffs. The prior cache never recorded arbitrary tool arguments, so this conversion does not invent them or authorize new tool execution.- The required
recordedWithheader describes the first target variant: engine contract version, platform, app identity digest and redacted agent context digest. Every act retains its own completekeyedByvalidity metadata. Empty, missing, incomplete or mismatched headers fail validation with the filename and line. Writes without validity metadata are rejected. The 30 older web traces lackedkeyedBy; their restored context was checked against each existing cache key before conversion, without changing the keys or replay actions. - The loader uses YAML core schema, rejects tags, anchors, aliases, duplicate/prototype/unknown keys, and validates every replay field. Limits are 1 MiB and 64 nesting levels. Errors include the filename and line. No recorded code is evaluated.
- Stable field order, flow-style targets, quoted ambiguous scalars, and blank lines between acts make diffs predictable. No creation timestamps, generated observation IDs or random filename components. Secret values stay behind references and redaction.
Naming and lifecycle
tests/checkout.e2e.ts::buysmaps to.e2e/cache/checkout-buys.yml.- File stem plus decoded describe/test titles, lowercase ASCII kebab case, accents removed, repeated stem prefix included once, capped at the last word boundary within 40 characters, without a trailing dash. Only a single word longer than the cap is cut mid-word. Empty names use
test; Windows device names receive atest-prefix. - Only colliding slugs, including collisions introduced by truncation, receive
--plus 12 hexadecimal characters of the original collected test ID's SHA-256. Both names change, independent of writer order. For example,tests/a/login.e2e.ts::logs%20inandtests/b/login.e2e.ts::logs%20inbecomelogin-logs-in--8557668b0fc9.ymlandlogin-logs-in--db53982224c6.yml. A digest collision fails the write instead of overwriting data. Suffixes persist after a collision. - The old
07b4d7e9bd3b15f44051f1e387b5afcf6e7534ebc17d317fc7d11903eaebc3d6.replay.tsis nowcontrol-inventory-back-returns-from-the.yml, in the same cache directory. - The earlier YAML basename
control-inventory-back-returns-from-the-details-view-to-the-inventory.ymlis shortened tocontrol-inventory-back-returns-from-the.yml. - Another example:
scenarios-act-completes-flattened-registration-form.ymlbecomesscenarios-act-completes-flattened.yml. This follow-up renames 22 files and completes the headers in all 52 committed recordings. - Act keys retain instruction, projected params, repeated-call occurrence, test, target, agent and validity context. Execution order is stored separately. A missing file or new act falls through to the agent. An invalid or stale entry repairs normally and fails as
REPLAY_STALEin strict mode. Strict mode never writes. - Confirmed writes merge under a cache-directory lock and publish atomically. A successful body prunes unvisited steps for its variant. Other variants remain; failed/interrupted attempts retain the existing confirmation rules.
- Successful read-write runs prune renamed/removed tests when collection proves absence. Filtered, strict and read-only runs preserve recordings outside their scope. Retired configurations and unreadable files remain visible through
cache lsfor manual deletion.cache clearpreserves unrelated/unreadable YAML instead of deleting arbitrary configuration files. - Redacted display titles determine filenames; original identity digests determine ownership. A fallback lookup by identity handles provider secrets resolved only after recording, and collision renames cannot turn an existing recording into a transient miss.
flowchart LR
A[agent.act key] --> B[Find test YAML by slug and identity]
B --> C{Matching valid act?}
C -->|yes| D[Existing replay and outcome checks]
C -->|missing| E[Existing agent executor]
D -->|stale, normal mode| E
D -->|stale, strict mode| F[REPLAY_STALE]
E --> G[Later verification confirms result]
G -->|read-write| H[Atomic per-test YAML update]
Verified
Ran it locally: yes.
-
Full
pnpm checkpassed. -
Full core unit and integration run on the final YAML implementation: 4,551 passed, 11 skipped, 327 files. This includes replay, CLI, round-trip, invalid-YAML and model-provenance tests.
-
Built CLI testbed: 587 passed, 1 skipped, 47 files.
-
Full web benchmark: 91 passed, 41 files.
-
Built CLI control-inventory suite with
--strict-cache: 7 passed, 7 replayed, no model calls. -
Built
e2e cache statsrecognizes 30 web and 22 mobile YAML files with no unreadable entries. -
The fresh-context reviewer independently parsed all 52 former TypeScript files and compared every original act payload, key, variant and count with YAML. All 69 act recordings are preserved. Original instruction text was recovered from source by digest; recoverable params were also checked against their stored digest. No conversion utility ships.
-
Parser/store coverage includes ambiguous scalars, arbitrary Unicode, schema errors, malicious tags/aliases/prototype keys, byte/depth limits, deterministic serialization, concurrent target writes, slug collisions, rename races, secret-bearing titles, truncated Unicode provenance, and unchanged replay file bytes.
-
Real-runner coverage proves slug discovery, ordered and repeated-label act matching, missing file/act fallback in both modes, stale-target repair versus strict failure, invalid-YAML repair versus strict failure, changed/removed-step pruning, and test rename cleanup.
| Behavior | Previous JSON cache | This branch |
|---|---|---|
| File relationship | One opaque file per act key | One readable YAML file per test, original act keys inside |
| Missing file or new call | Agent fallback; strict does not write | Same executor and confirmation rules |
| Stale target | Repair normally; fail under strict | Same replay executor and safeguards |
| Changed/removed acts | Old per-act files could remain | Completed attempt replaces its variant's step set |
| Invalid advisory model metadata | Discarded during JSON normalization | Strict YAML schema rejects the recording; strict run makes no model call |
| File trust | Validated JSON trace data | Bounded core-schema YAML plus the same trace validation |
Review findings handled
- Removed the TS codec, cache AST loader, public replay builders and type assertions, together with all dual-format/migration/diff machinery from earlier iterations.
- Fresh review of the slug/header follow-up found no critical or important issues. It recomputed all 69 act keys from metadata and verified that corpus actions, params, identities and replay evidence are unchanged. New coverage includes word boundaries, truncation collisions in both writer orders, Unicode/redacted titles, required-header errors, and web/iOS/Android recording through confirmation to persisted metadata.
- Fixed all four findings from the fresh YAML review: metadata fields overwritten before validation, a collision rename causing a transient miss, provider-redacted titles changing lookup paths, and percent-decoding truncated Unicode provenance. Each has regression coverage.
- Preserved one file across variants whose secret ledgers redact the title differently. Directory-level locking serializes renames, merges and cleanup. Trace pages and strict errors use resolved filenames, including suffixes.
- Kept the original shared replay implementation deliberately. YAML changes serialization and reviewability, not what makes an action or outcome safe to replay.
Related work
- #1687 adds a separate pinned-step layer, inline actions and a required-pins policy. This PR replaces default cache storage and keeps existing miss/fallback semantics. Both touch shared replay and confirmation code; coordinate those changes before merging either PR.
Limits and CI
- The complete test recording is capped at 1 MiB. Oversized updates preserve the previous file. A crashed writer may leave
.recordings.lock; remove it before regenerating. - Identity fallback scans YAML files when the display slug changes. Writes serialize within one cache directory. No performance improvement is claimed.
- Live-model read-write repair and broader device coverage remain untested locally. Current-head CI verifies web, Android and iOS replay plus live handoffs; it does not cover every device or read-write regeneration path.
- Head
2fbb9059dfdaf8457bdfa0de3618143d236dd5b5: all required CI checks passed, with no pending or failing checks and no unresolved review threads. The PR remains draft. - Android CI: deterministic suite 57 passed and one documented skip; agent suite 19 passed and one Gestures test passed on retry, with 15 full cached replays. Both Gestures attempts loaded YAML and replayed the long-press before the existing
tool swipegap; the first live swipe attempt failed and the retry succeeded. The report confirms the same cache entry and handoff point on both attempts. - iOS CI: deterministic suite 55 passed and one documented skip; agent suite 21 passed and one documented Apple Pay Billing Address skip, with 12 full cached replays. Neither iOS suite reported a flaky test on this head.
- The Android Gestures flake remains a known limitation after agent handoff. No failure occurred in YAML loading, act-key matching or the cached long-press. Keep this PR draft. Do not merge.