fix(cache): treat short prefixed record ids as minted segments (#769)
Merged
DE
2mo ago+16+16+01234567890123456789-4-4-0123456789
What and why
Fixes #769
- The replay cache compares screens as routes, not URLs:
routeOf(packages/e2e/src/cache/route.ts:81) splits a location's path and replaces every segment that looks minted per record with:id, and the start-path precondition indecideTraceReplay(packages/e2e/src/cache/decide.ts:47) replays a step only when the recorded and live routes read exactly the same. PROJ-016matched none of the minted shapes: it is 8 characters, so the 12-or-more-character mixed-token rule skips it, and it is not a hex run, not all digits, and carries no whitespace. It stayed a literal.- So a step recorded on
/projects/PROJ-016compared its recorded route against/projects/PROJ-017on the next run: one differing literal segment reads asundecided, which is a miss at the start of a step, and the agent took over. Only the step before the project exists ever replayed (11 warm runs on three models per the issue), and--strict-cachestopped at step 2 withREPLAY_STALE.
flowchart LR
A[replay starts] --> B["routeOf(recorded startPath)"]
A --> C["routeOf(currentPath)"]
B --> D{compareRoutes}
C --> D
D -- same --> E[replay]
D -- "undecided / different" --> F["miss: wrong-context"]
- The fix adds one pattern to
MINTED_SEGMENT:
/^[A-Za-z]+-\d{2,}$/,
- Letters, a dash, then a digit tail of two or more:
PROJ-016,INV-2041,item-42. It sits next to the existing shapes and inherits their behavior, so both sides of the comparison reduce to:idand the routes read alike. - The single-digit floor is deliberate. Both ids in the issue carry a zero-padded tail, while a single trailing digit is usually a route word a router owns (
page-2). If you would rather follow the issue's<letters>-<digits>wording exactly, widening the tail to-\d+is a one-character change and thepage-2control flips to:idwith it. - What the pattern does not touch:
companies-v2keeps staying a literal because no digit follows the dash directly,Summer-Sneakerand other dashed slugs stay literals, andjohn_doestays a literal. Those controls now have test coverage. - Routes are computed at replay time from the stored raw paths (
trace.startPathand the live path), so recordings made before this change benefit too: no cache version bump, no re-record, and no change to the.e2e/cache/layout the stability policy covers. - Docs:
docs/cache.mdxalready promises "the same route, whatever the record id"; this change makes the code keep that promise for prefixed ids, so no docs edit was needed.
Verified
Ran it locally: yes
- The new assertions fail against main's code and pass here, in
packages/e2e/tests/unit/trace-route.test.ts:
AssertionError: expected '/projects/PROJ-016' to be '/projects/:id'
AssertionError: expected 'undecided' to be 'same'
- Cache unit suites on this branch:
pnpm --filter e2e exec vitest run tests/unit/trace-route.test.ts tests/unit/trace-cache.test.ts tests/unit/trace-decide.test.ts tests/unit/trace-identity.test.ts tests/unit/step-cache.test.ts tests/unit/trace-recorder.test.ts, 6 files, 116 tests passed. - The bug and the fix side by side, running
routeOfandcompareRoutesfrommainand from this branch:
| main | this branch |
|---|---|
routeOf("/projects/PROJ-016") → /projects/PROJ-016 | routeOf("/projects/PROJ-016") → /projects/:id |
routeOf("/projects/PROJ-017") → /projects/PROJ-017 | routeOf("/projects/PROJ-017") → /projects/:id |
compareRoutes(recorded, live) → undecided, the start precondition wants same, so the step misses and the agent takes over | compareRoutes(recorded, live) → same, the step replays |
Checklist
- Changeset added (
.changeset/prefixed-record-ids.md,e2e: patch). - Not a breaking change: no public API, config key, wire format, or
.e2e/cache/layout change; the fix widens which paths read as the same route. - Docs checked in the same review:
docs/cache.mdxalready describes this behavior and needs no edit;skills/e2e/does not describe the minted shapes. - No contract change: no emitted
.d.ts, schema, or fixture touched, and no engine contract change.