fix(cache): replay a multi-line unique() value the screen shows on one line

Merged
SA
17d ago
+23-5

What and why

  • The cache writes end anchors on one line (collapseText in packages/e2e/src/cache/anchors.ts). So a multi-line unique() value, such as an address typed into a textarea, is recorded on one line.
  • templateText looked for the value as given and in its URL spellings (uri, form, slug) only. The one-line spelling stayed the recording run's literal text. The next run typed a new value, and the end check missed: REPLAY_STALE (end-mismatch) with --strict-cache, a hand-off to the agent without it.
  • ENCODERS in packages/e2e/src/cache/template.ts gets a flat spelling, normalizeText: every whitespace run, \r included, becomes one space, then the result is trimmed. The anchors record as {{param:/address|flat}}, and replay fills in this run's value on one line.
  • normalizeText, not collapseText: collapseText turns a \r into U+FFFD, but a textarea stores \r\n as \n, so a value joined with \r\n would still miss.
  • Older runners: an entry recorded with |flat reads as invalid-entry on a runner without this fix (stated in the changeset). Cache keys do not change, because templateParams writes placeholders with no encoding. A value with no whitespace run has no flat spelling, so no other recording changes.

The issue author, @amoscicki, proposed this fix and the flat name in #1359.

Issue

Fixes #1359

Verified

Ran it locally: yes

  • The issue's reproduction as a scratch project on the built packages. A scripted executor (no model) types unique(address) into a textarea and taps Save. Steps: npx e2e run to record, then npx e2e run --strict-cache.
  • Same steps with the value joined by \r\n instead of \n. It failed on this branch before the normalizeText change and passes now.
  • The new unit test in tests/unit/trace-template.test.ts fails on main.
mainthis branch
Recorded end anchors"value":"Ada Lovelace 12 Example Street E2E 1793336967299""value":"{{param:/address|flat}}"
--strict-cache replay, \n valueREPLAY_STALE (end-mismatch), 15.30s, Cache 1 handed offpassed, 1.21s, Cache 1 replayed
--strict-cache replay, \r\n valuenot runpassed, 1.17s and 1.11s, Cache 1 replayed

main:

   Ɨ saves a multi-line address > agent.act "save the address {address}" 14.37s failed
REPLAY_STALE: the recording of this step no longer replays (end-mismatch), and cache.strict hands no step to the agent; re-record it with a read-write run without --strict-cache and commit the changed entry under .e2e/cache
      Cache  1 handed off

this branch:

   āœ“ saves a multi-line address > agent.act "save the address {address}" 304ms
      Tests  1 passed (1)
      Cache  1 replayed
   Duration  1.21s

Reviewed with sol-loop: 2 rounds with gpt-6.1-sol on high. Sol verdict: approved

šŸ¤– Generated with Claude Code