fix(mobile): act after a scroll or swipe only once the control stops moving

KD
6d ago
+890-90
  • After a scroll or swipe, a test acts on a control only once it stops moving. The gesture budget is the least wait, then the engine reads until two sightings of the control and its look-alikes agree, at most 4 s after the gesture. That read is also the relocation read, so a list that already sits still costs no extra read.
  • scroll can return while a fling still moves the list. On an iOS simulator with agent-device 0.21.36, 3 of 120 scrolls kept moving 1.66 to 1.84 s after it returned, and the benchmark's 1.5 s sleep sends the next tap about 1.7 s after. In CI the same shape shows as sticky chrome: accept below the fold (scrollUntilVisible, then tap): flaky in the final iOS report of 6 of the 101 PRs updated since Oct 15, the most of any test.
  • mobile({ transition }) also takes { default, gesture, launch } (new TransitionBudgets type), so the least wait after a gesture can differ from the wait after a tap. The wait #1564 puts before a screen swipe follows the same kinds. A number still sets one wait for every action, and 0 still means no wait. The benchmark config keeps 1.5 s.
  • An action whose own timeout cannot fit another read goes ahead on the latest read instead of failing. Agent actions and the default and launch paths are unchanged.
  • Left out on purpose: agent-device's opt-out of its own post-gesture settle (callstack/agent-device#4253, in no release yet), which widens the tail and so follows this wait, and new benchmark budgets, which need CI runs of their own.
flowchart LR
  A[scroll or swipe returns] --> B[sleep the gesture budget]
  B --> C[read the screen]
  C --> D{two sightings agree?}
  D -- no --> E{cap or timeout reached?}
  E -- no --> C
  D -- yes --> F[act on the control as read]
  E -- yes --> F
mobile({ platform: 'ios', transition: { gesture: 1_500 } }); // 500 ms after everything else

Verified

Ran it locally: yes

  • apps/mobile-benchmark through the built CLI on an iOS simulator and an Android emulator, @e2e-dev/mobile built from main and from this branch, both on the pinned agent-device 0.21.36 (--workers 1 --retries 0, one run at a time). Both builds carried a wrapper around the agent-device client that records every call (not in this PR).
  • iOS, a scratch test (below, not in this PR): 21 × scrollUntilVisible then tap on the huge virtualized list, --repeat-each 10, two runs per build in the order main, branch, branch, main (main was f6aba972, before #1564 landed). That is 840 scroll-then-tap pairs, and all 40 repeats pass. A tap counts as sent on a moving list when the last two snapshots before it disagree about where the rows sit (more than 1 px).
mainthis branch
scroll-then-tap pairs420420
taps sent after a last read that still saw the list moving60
slow flings (the first two reads disagree)610
scroll return to tap, median1,727 ms1,724 ms
scroll return to tap, slow flings (median, range)1,881 ms, 1,757 to 1,8862,154 ms, 2,020 to 2,482

Fisher exact, one-sided: p = 0.015. Five of main's six were in one run (the other main run had one), so without that run the contrast alone is 1/210 against 0/420. Slow flings are 16 of 840 scrolls (1.9%). On the branch each waited 2.0 to 2.5 s for two reads to agree, with 3 to 5 reads, and none reached the 4 s cap.

  • Full deterministic suite with this branch on the pin: iOS 57 passed, 1 skipped (611 s); Android 57 passed, 1 skipped (379 s). The 1-minute load at start was 2.4 and 2.5 after waiting for it to drop below 3, with peaks of 6.3 and 7.3. The first scroll-then-tap run (main) had a load spike to 26.9 in its first two minutes from the cold simulator boot; only one of its five events fell in that window.
  • After the review fixes (a fill or clear takes the read that found the field at rest, so it costs no read of its own), the full suites again on the pin with the new head: iOS 57 passed, 1 skipped (611 s) and Android 57 passed, 1 skipped (384 s), 1-minute load at start 2.5 after waiting.
  • Rebased onto c74de8d0 and with the long-press fix: the full suites again on the pin, iOS 57 passed, 1 skipped (690 s) and Android 57 passed, 1 skipped (466 s). Both run about 80 s longer than before, because #1564 now waits the remaining budget before every screen swipe and the benchmark's budget is 1.5 s. The 1-minute load at start was 3.0 and 2.4 after the wait cap, with peaks of 9.1 and 6.3.
  • Rebased again onto 3c9de80d. The one conflict was packages/mobile/src/index.ts, where main added the default export next to this branch's TransitionBudgets export. The other three commits are unchanged (git range-diff). Main's new commits touch neither surface.ts nor options.ts; in packages/mobile they add an up-front platform check in mobile(), that default export, one test, and a devDependency bump. After the rebase, the 590 mobile unit tests and pnpm check pass. The device suites were not run again for it, since none of that sits on the gesture path.

Not covered: a swipe that starts a UIKit transition (the tree reports that screen's final frame at once, so only the gesture budget protects the tap, as before) and real devices.

The scratch test
test('fling taps: scroll to a row and tap it, twenty-one times', { timeout: 280_000 }, async ({ app, device, screen }) => {
  await openScenario({ app, device, screen }, 'Huge Virtualized List');
  for (let row = 24; row <= 504; row += 24) {
    const target = screen.getByTestId(`row-${row}`);
    await screen.scrollUntilVisible(target, { direction: 'down', timeout: 120_000 });
    await target.tap();
  }
});

🤖 Generated with Claude Code