fix(cache): treat short prefixed record ids as minted segments (#769)

Merged
DE
2mo ago
+16-4

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 in decideTraceReplay (packages/e2e/src/cache/decide.ts:47) replays a step only when the recorded and live routes read exactly the same.
  • PROJ-016 matched 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-016 compared its recorded route against /projects/PROJ-017 on the next run: one differing literal segment reads as undecided, 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-cache stopped at step 2 with REPLAY_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 :id and 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 the page-2 control flips to :id with it.
  • What the pattern does not touch: companies-v2 keeps staying a literal because no digit follows the dash directly, Summer-Sneaker and other dashed slugs stay literals, and john_doe stays a literal. Those controls now have test coverage.
  • Routes are computed at replay time from the stored raw paths (trace.startPath and 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.mdx already 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 routeOf and compareRoutes from main and from this branch:
mainthis branch
routeOf("/projects/PROJ-016") → /projects/PROJ-016routeOf("/projects/PROJ-016") → /projects/:id
routeOf("/projects/PROJ-017") → /projects/PROJ-017routeOf("/projects/PROJ-017") → /projects/:id
compareRoutes(recorded, live) → undecided, the start precondition wants same, so the step misses and the agent takes overcompareRoutes(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.mdx already 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.