perf(agent): stop re-waiting for a lost list on every repeat of a replayed scroll

Merged
OK
2mo ago
+51-17

A replayed folded scroll (one recorded scroll with times: N) on a list that filled the screen re-ran the full relocation backoff before every repeat when the list could not be found. pollSettled (packages/e2e/src/agent/replay.ts) waits about 14s per relocation, so a recorded 4x scroll spent about 56s before falling back to the viewport each time.

  • scrollOnce now reports whether it scrolled the list, scrolled the viewport (list lost, spans >= MAIN_LIST_SHARE), or failed. Once a list is judged lost, the rest of the repeats in that scroll go through the viewport path: a settled held-still look, then a scroll, with no new relocation.
  • The list and viewport repeats share one loop now.
  • Unchanged: a smaller region (spans below the share) still hands off on the first miss, the count of repeats done before a miss is kept, and the cache key and recordings are untouched.
flowchart LR
  A[repeat i] --> B{list still tracked?}
  B -- yes --> C[relocate, up to 14s]
  C -- found --> D[scroll list]
  C -- lost, fills screen --> E[scroll viewport, stop tracking list]
  C -- lost, small region --> F[hand off]
  B -- no --> G[held-still look, scroll viewport]

Verified

Ran it locally: yes

  • Unit: new test in tests/unit/trace-replay.test.ts uses fake timers to replay a 4x scroll whose list is gone. It asserts the elapsed clock (14000ms) and the looks: one backoff of 9, then one held-still look per later repeat. On main it fails with expected 56000 to be 14000.
  • Runner: a scratch integration test (not committed) runs the built runner through the fake engine on an ios target with cache: 'read-write'. The first run records an executor that scrolls list "Feed" (97% of the viewport) four times, folded to one action with times: 4. Before the second run the list is renamed (Feed, row 13 of 40, the way a device renames a scroll view) and the step replays:
mainthis branch
replayed agent.act step56369 ms14324 ms
cacheself-finalized, 1/1self-finalized, 1/1
swipes / test4 / passed4 / passed