fix(cache): wait for late or hidden controls at cached points (ENG-1556)

MI
15m ago
+579-34

What changed

Cached coordinate taps, hovers and drags wait for an identifiable control to have a usable pixel in the viewport. Replay checks the whole pixel the dispatcher will send. A fractional position that rounds outside the control keeps waiting. An older recording whose fraction rounded to one still replays when the dispatched pixel falls inside the box.

During a drag, either endpoint can load late. If the recorded point distinguishes one of several same-named controls, replay checks that group while the other endpoint loads. Losing a visible candidate stops the drag before input. Removing a candidate already outside the viewport allows the drag to continue. If a uniquely identified hidden or boxless control gains a look-alike while replay waits, the newcomer cannot receive the recorded action.

A recorded position can identify a target again once its count recovers. A same-count swap of indistinguishable, visible controls remains undetectable. Bare-point actions keep their existing behavior. The cache format and replay policy version are unchanged.

Why

When the drop target loaded late, replay gave up even if the recorded source point distinguished two controls with the same name. Waiting for hidden or offscreen targets also exposed cases that sent input to a surviving neighbor or rounded the dispatched pixel outside the intended box.

Issue

ENG-1556

Verified

Ran it locally: yes

At a44fbc8e9, all 107 tests in the focused replay suite passed locally through the built core package. Three of them are new. With the lostIdentity check in relocateEnds switched off, 106 pass and one new row fails, because replay then drags to a look-alike that took a hidden drop target's place while the source was still absent. With only the source half of that check removed all 107 still pass, since the poll ends on that look either way. The other two new rows pin what relocateEnds does with a drag end recorded with a position that turns ambiguous after it was found hidden, and the tap test for the same case in relocate now asserts the wait. The five commits after fea6ee94b add those tests, rename one row and cut the docs wording to one sentence. They leave replay.ts as it was, so the runs below are from fea6ee94b.

The docs commit cuts one sentence from the cache guide, "If same-named controls appear, replay needs enough information to tell them apart", which the sentence before it covers. The changeset drops "Points recorded outside controls replay as before", which described no change.

Through the built CLI with strict cache, the original PR head dispatched a drag to x430 just outside a box ending at 430. The repair waited and dispatched x509 inside the expanded box. A stored fraction of one on an unchanged fractional-width box also replayed at x509. When the source scrolled out of view, the destination disappeared, or a twin appeared over a hidden target, the repair stopped before sending input. Each case was repeated with a stable-control comparison.

The iOS simulator ran the repaired commit fea6ee94b merged with its base, with model fallback enabled. Across the three recordings that contain taps tied to a control, 8 of 12 such taps replayed from cache. Flattened Registration Form replayed all 11 actions, including all five coordinate taps, with zero model calls. Broken Accessibility replayed two of four actions and Flattened Login replayed one of eight. Each handed control to the model at a text entry that requires a value at run time. All three tests passed on the first attempt and reached the same point in their recordings as on the original PR commit. Repaired commit’s iOS job · Original commit’s iOS job

Earlier checks at fff0cc3b4

A scratch project on the scripted engine
(packages/e2e/tests/helpers/fake-engine.ts) recorded one point action
with a scripted executor. e2e run --strict-cache then replayed it while
the screen changed on a timer. Main is the merge base 6c87952d8.

drop target hidden on the first look, shown about 1 s later
main:    exit 0, 1 drag to (900, 100), inside the hidden box
fff0cc3b4: exit 0, self-finalized, 1 drag to (500, 100), 0 model calls
Casemainfff0cc3b4
Two same-named sources, drop target appears after 0.3 sREPLAY_STALE, no dragWaits, drags to (500, 100)
Two same-named sources, drop target absent, then hidden, then shownREPLAY_STALE, no dragWaits, drags to (500, 100)
Two same-named sources, drop target hidden on the first look, then shownDrags to (900, 100), the hidden boxWaits, drags to (500, 100)
One source, drop target absent, then hidden, then shownDrags to (900, 100), the hidden boxWaits, drags to (500, 100)
Two same-named sources, drop target absent, then hidden for goodREPLAY_STALE after 0.7 s, while the target is still absent, no dragREPLAY_STALE after 14.9 s, no drag
Source recorded 1 of 2, three on screen settle to two while the drop target loadsDrags from (100, 100) to (500, 100)Drags from (100, 100) to (500, 100)
Tap at a point in a control that is hidden, then shownTaps (900, 100), inside the hidden controlWaits, taps (500, 100)
Tap at a point in a control that stays hiddenTaps (900, 100), inside the hidden controlREPLAY_STALE after 15.0 s, no tap
Drop target outside the viewport, then in viewDrags to (1279, 100), the viewport edgeWaits, drags to (500, 100)
Tap at a point in a control outside the viewport, then in viewTaps (1279, 100), the viewport edgeWaits, taps (500, 100)
Tap at a point in a control that stays outside the viewportTaps (1279, 100), the viewport edgeREPLAY_STALE after 14.8 s, no tap

Every replay above made zero model calls. A control that never shows now
costs the existing 15-second polling cap, or the rest of the step budget,
before the stop.

The scripted engine reports exact coordinates and has no video.

Eleven single-line mutants of replay.ts ran in a separate worktree
against trace-replay.test.ts. Each fails at least one test.

pnpm bench:ab --suite testbed -- tests/forms.e2e.ts exercises ordinary
form interactions and skips the cached point paths. The machine was busy
(load 54.8 on 18 cores), so read the behavior and counter sections and
treat the timings as noisy.

bench-ab: 6c87952d (merge base with origin/main) vs 58c2bf1d

apps/testbed: e2e run --workers 1 tests/forms.e2e.ts. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 26.13.1, load 54.8.

Behavior

Every test ran the same steps with the same outcome on every run of both builds.

Timings

Metricbase median (IQR)head median (IQR)change (95% CI)verdict
wall (process)3.63 s (3.55 s-3.67 s)3.54 s (3.52 s-3.71 s)+1.6% (-6.3% to +4.0%)unresolved
suite (sum of attempts)2.20 s (2.16 s-2.24 s)2.13 s (2.10 s-2.15 s)-4.0% (-4.8% to -0.8%)same
action (events)465 ms (459 ms-471 ms)444 ms (436 ms-450 ms)-5.8% (-10.9% to -1.1%)unresolved
step expect.not.toBeChecked1.01 s (1.00 s-1.01 s)1.00 s (1.00 s-1.00 s)-0.3% (-1.0% to 0.0%)same, under the floor
step app.open274 ms (264 ms-285 ms)262 ms (255 ms-268 ms)-6.9% (-10.2% to +6.9%)unresolved
step locator.fill211 ms (202 ms-221 ms)205 ms (202 ms-221 ms)+0.9% (-8.4% to +10.2%)same, under the floor
step locator.tap79 ms (77 ms-90 ms)71 ms (64 ms-76 ms)-14.9% (-28.7% to +13.7%)unresolved
step locator.pressSequentially56 ms (53 ms-58 ms)54 ms (52 ms-56 ms)-2.6% (-26.6% to +1.9%)same, under the floor
step locator.check54 ms (47 ms-57 ms)42 ms (34 ms-44 ms)-19.6% (-29.1% to -15.3%)faster
step locator.uncheck48 ms (46 ms-51 ms)47 ms (46 ms-49 ms)-1.0% (-19.2% to +8.8%)same, under the floor
step locator.selectOption36 ms (32 ms-42 ms)30 ms (27 ms-37 ms)-22.8% (-35.3% to +21.0%)same, under the floor
step locator.clear29 ms (27 ms-34 ms)29 ms (28 ms-30 ms)+1.8% (-16.4% to +8.0%)same, under the floor
step expect.toBeVisible21 ms (21 ms-22 ms)20 ms (20 ms-20 ms)-4.8% (-9.3% to +2.6%)same, under the floor
step expect.toHaveValue17 ms (15 ms-19 ms)15 ms (13 ms-16 ms)-11.2% (-31.4% to -0.0%)same, under the floor
step expect.toHaveCount10 ms (9 ms-10 ms)9 ms (9 ms-10 ms)-5.1% (-26.5% to +10.6%)same, under the floor
step expect.toHaveText9 ms (7 ms-9 ms)8 ms (7 ms-8 ms)-6.5% (-30.4% to +14.3%)same, under the floor
step expect.toBeChecked4 ms (3 ms-6 ms)5 ms (3 ms-5 ms)+6.1% (-47.3% to +58.1%)same, under the floor

Counters

Every counter matched on every run of both builds.

Tests outside the threshold: 0 of 639

With 639 tests compared at 95%, about 32.0 could land outside by chance.

Summary by CodeRabbit

  • Bug Fixes
    • Cached taps, hovers, and drags recorded inside a control now wait until the recorded point is usable within that control on screen.
    • Cached drags wait for delayed or hidden drop targets. Replay stops when a same-named control leaves the visible area and that control is needed to identify the target.
    • Replay avoids acting on a replacement control when the recorded point no longer identifies the original target.
  • Documentation
    • Updated replay guidance to describe visibility waits and when cached drags stop.