fix(cache): replay unique() params whose paths contain pipes, closing braces or line breaks
What
Replay cache placeholders now distinguish pipes and closing delimiters inside unique() parameter paths. A name such as x|slug or x|} resolves to its own value alongside a shorter sibling. A line break in a name also round-trips. Encoding lookup in parsePlaceholder uses Object.hasOwn so inherited Object.prototype names like toString are rejected.
Compared with the merge base, steps get a new key when a marked path contains | or }}, or ends in }. In read-write mode those steps record again. Under --strict-cache they miss with no-entry and run live without writing. An isolated internal brace and a line break alone keep their existing keys.
Why
parsePlaceholder splits on the last | to read an optional encoding (uri, form, slug, flat). When a step marked both x and x|slug with unique(), the recording wrote {{param:/x|slug}} for x|slug and replay parsed it back as /x in slug form, typing "delta-updated" instead of "Gamma Updated" and passing silently when the end state still matched. Even without a sibling x, a recording containing the raw placeholder of a key with | failed to expand and fell into invalid-entry.
How it works
flowchart LR
A["paramPointer('', 'x|slug') -> /x|slug"] --> B["spellPointer -> /x~2slug"]
B --> C["placeholder -> {{param:/x~2slug}} or {{param:/x~2slug|slug}}"]
C --> D["parsePlaceholder splits last |, checks Object.hasOwn(ENCODERS)"]
D --> E["readPointer -> /x|slug"]
spellPointerescapes every|as~2. It escapes a closing brace as~3only before another closing brace or at the end of the pointer. BecauseparamPointeralready escapes literal tildes as~0, neither spelling collides with a literal key. Percent signs and ordinary internal braces keep their spelling.- The placeholder matcher accepts line terminators inside a path.
readPointerrestores the pipe and brace escapes afterparsePlaceholdersplits off the optional encoding.Object.hasOwn(ENCODERS, encoding)rejects inherited names. templateParamsuses the same pointer spelling when deriving the cache key. An older recording with an ambiguous brace misses before any cached action executes.
Escaping % and | as %25 and %7C while keeping keys unchanged would misread pre-fix recordings for keys containing those strings. Escaping every brace would unnecessarily change the existing {{param:/a}b}} spelling. Bumping REPLAY_POLICY_VERSION would invalidate every committed cache.
Issue
None.
Verified
Ran it locally: yes
Closing braces and line breaks
Ran locally with the built CLI, Chromium and a scripted executor. Each case recorded a title, replayed with a different title, and read the app server's saved value. A separate run with caching disabled established the expected write. On the initial PR revision, the trailing brace, adjacent braces and line break each produced the wrong write twice. All five fresh recordings below replayed on the fix with zero executor calls and saved exactly Gamma Updated.
| Marked name | Strict replay of a merge-base recording | Strict replay of an initial PR recording |
|---|---|---|
| `x | slug, beside x` | Ran live |
| `x | }, beside x | ` |
x}}tail, beside x | Ran live | Ran live |
| A pipe and a line feed in one name | Ran live | Replayed |
a}b, beside a | Replayed | Replayed |
Every live fallback above reported no-entry and saved the expected title. The eight new unit cases failed on the initial PR revision and passed with the fix. They cover all four JavaScript line terminators, repeated braces, raw and slugged values, and a literal ~3 beside an escaped brace.
Pipes, captured at 2346af099
- Built CLI via our external
cache-runnerharness (runspackages/e2e/dist/cli/bin.js runwith a scripted executor and no model against a local fixture app) onparam-pipe-key(params: { 'x|slug': unique(...), x: unique(...) }, record with'Beta Original'/'Alpha Original', replay with'Gamma Updated'/'Delta Updated'), comparingmain(7c1b2b258) and this branch (2346af099, clean tree). Stderr case lines below (paths abbreviated; stdout summary JSON omitted):
$ node cache-runner/run.mjs --repo <base-7c1b2b258> --cases param-pipe-key --save-recordings <base-rec> --out base-pr1.json
param-pipe-key benign unsafe replay=self-finalized: ref=passed
$ node cache-runner/run.mjs --repo <head-2346af099> --cases param-pipe-key --save-recordings <head-rec> --out pr1-fresh.json
param-pipe-key benign replayed replay=self-finalized: ref=passed
$ node cache-runner/run.mjs --repo <head-2346af099> --cases param-pipe-key --frozen <base-rec> --out pr1-frozen.json
param-pipe-key benign missed replay=missed:no-entry ref=passed
$ node cache-runner/run.mjs --repo <base-7c1b2b258> --cases param-pipe-key --frozen <head-rec> --out base-on-pr1.json
param-pipe-key benign missed replay=missed:no-entry ref=passed
| scenario | reader: main (7c1b2b258) | reader: this PR (2346af099) |
|---|---|---|
param-pipe-key (fresh recording) | unsafe (self-finalized, wrote "delta-updated", expected "Gamma Updated") | replayed (self-finalized, wrote "Gamma Updated") |
param-pipe-key (main recording) | unsafe (self-finalized, wrote "delta-updated") | missed (no-entry, agent wrote "Gamma Updated") |
param-pipe-key (this PR's recording) | missed (no-entry, agent wrote "Gamma Updated") | replayed (self-finalized, wrote "Gamma Updated") |
- All 4 new tests in
packages/e2e/tests/unit/trace-template.test.tsfail onmain(7c1b2b258) and pass on2346af099; 5/5 hand-written mutants ontemplate.tsare killed byAssertionError. pnpm bench:abnot run: across all 70 committed benchmark recordings (31 web, 39 mobile), the only{{param:slot is{{param:/label}}, so no committed entry holds|or changes behavior.
Docs page
No screenshot of the rendered docs/cache.mdx: the change there is one paragraph of prose in the strict-mode section.
Summary by CodeRabbit
- Bug Fixes
- Cache replay now handles
unique()parameters whose paths contain pipes, closing braces, or line breaks. - Some earlier recordings may no longer match these paths and will run live with
--strict-cacheuntil refreshed inread-writemode.
- Cache replay now handles
- Documentation
- Updated cache guidance to explain when earlier recordings run live and how to refresh them.