refactor(mobile): read for rest after a scroll or swipe, and set the transition wait by kind of action

Closed
KD
7d ago
+965-230
  • This is a refactor of the rest wait #1668 added, plus one option. It gives the same protection as main (no tap lost on a moving list in the reviewer's re-run of 420 idle and 252 loaded scroll-then-tap pairs) with one read and about 100 ms less per scroll-then-tap, and it sets the wait by the kind of the last action. It does not fix a lost tap that main still has.
  • 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. A look-alike with no bounds is left out of the sighting.
  • It replaces the re-read #1668 added (steadied), which compared the control's own bounds, 100 ms apart, for up to 2 s after the gesture and failed the action with OPERATION_TIMEOUT when its budget ran out first. This one compares the control with its look-alikes, 50 ms apart, runs up to 4 s, and goes ahead on the latest read when the budget runs out. #1668's opt-out of agent-device's own post-gesture settle (postGestureStabilization: false) stays as it is.
  • 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. A budget of 0 is no wait at all after any other action; after a scroll or swipe it sleeps for nothing and the rest check still runs.
  • An action whose own timeout cannot fit another read goes ahead on the latest read instead of failing with OPERATION_TIMEOUT. Agent actions and the default and launch paths are unchanged. This is a behavior change from main and is open for the owner to decide.
  • Left out on purpose: 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

Latest head (rest check kept at a budget of 0, look-alikes with no bounds left out): the 632 mobile unit tests pass and the three new or changed tests fail on the previous head; tsc, oxlint, plugins:check, and docs:check pass. The device suites below were not rerun on this head.

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 and #1668 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. The baseline is main before #1668, with agent-device's own settle in place. The table was not repeated against main with #1668's re-read, so it shows what the rest wait adds over that settle, not over steadied.

  • Full deterministic suite with this branch on agent-device 0.21.36: 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 agent-device 0.21.36 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 agent-device 0.21.36, 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.
  • On the current head, with main (3ce6b589) merged in and agent-device 0.21.37 pinned since #1735: the 618 mobile unit tests and pnpm check pass. The previous head (33388e39, the PR's four commits on f64e7dba) passed CI with all four device jobs (iOS and Android, deterministic and agentic) green. Locally, the iOS deterministic suite on a simulator with 0.21.37 gave 57 passed, 1 skipped, 1 failed (672 s, 1-minute load 3.5 at start after the 4-minute wait cap). The failure is openLink opens the scenario a deep link names, new from #1805: the app installed on that simulator is the 11-03 build, whose bundle has no e2e-benchmark:// routing, so the link opens and the app ignores it. CI builds or repacks the app from each head's own source. Android was not run locally.

Not covered: this branch against main with #1668's re-read on 0.21.37, 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