Skip to content

fix: align Android Maestro gesture dispatch - #1356

Merged
thymikee merged 2 commits into
mainfrom
agent/android-maestro-gesture-dispatch
Jul 21, 2026
Merged

thymikee merged 2 commits into
mainfrom
agent/android-maestro-gesture-dispatch

Conversation

@thymikee

@thymikee thymikee commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Align Android Maestro swipes with the persistent helper architecture.

  • dispatch helper input without the framework's global animation wait on every event, keeping the canonical synchronous one-/two-pointer sample schedule (including the final MOVE) intact
  • let an authored waitForAnimationToEnd that actually observes a stable screenshot pair consume the same-generation pending mutation boundary, avoiding a redundant hierarchy capture; a timed-out wait leaves the boundary pending for the next mutating command's hierarchy settle
  • model waitForAnimationToEnd as a read: it preserves observation generation instead of invalidating it

The PagerView discrepancy came from the public two-argument UiAutomation overload waiting for global animations before every injected event, stretching a 100 ms pan to roughly 10 seconds. The helper now resolves Android's runtime three-argument injection API (injectInputEvent(event, sync, waitForAnimations=false)) and falls back to the public overload on runtimes where the lookup fails. Per-event dispatch guarantees and event shape are unchanged; it does not restore adb input swipe.

Validation

  • PagerView Android Maestro suite: 9/9 passed in 359.1s
  • scrollable PagerView flow: five consecutive focused passes, then passed in 24.0s in the full suite
  • live emulator-5554 (API 36), persistent-session helper: app-observable passes for one-/two-pointer pan, fling left/right, pinch, rotate, combined transform, semantic scroll, and coordinate swipe
  • focused Maestro runtime tests: 33/33; broad affected run 762/771 with all nine failures unrelated exact 5s host-load timeouts (affected files passed in isolation, 47/47)
  • pnpm check:affected --base origin/main --run: format, lint, typecheck, layering, fallow, and build passed
  • pnpm format, pnpm build:android
  • residual risk: the reflective fallback was not live-tested on an older API image (only API 36/37 AVDs available); the fallback path is the pre-existing public two-argument injection

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
JS raw 1.8 MB 1.8 MB +514 B
JS gzip 575.1 kB 575.2 kB +120 B
npm tarball 689.5 kB 689.7 kB +118 B
npm unpacked 2.4 MB 2.4 MB +514 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 26.7 ms 26.8 ms +0.1 ms
CLI --help 57.2 ms 57.2 ms -0.0 ms

Top changed chunks:

Chunk Raw diff Gzip diff
dist/src/session.js +514 B +120 B

@thymikee

Copy link
Copy Markdown
Member Author

Three blockers before readiness:

  1. [P1] waitForAnimationToEnd now unconditionally clears the pending mutation-stability boundary after executeMaestroRuntimeCommand returns. The screenshot wait returns normally when its deadline expires without two matching frames, so a timed-out/unstable visual wait is treated as success and the next mutation can run without the hierarchy barrier. This contradicts the updated ADR (“A failed visual wait leaves that boundary pending”). Return/propagate whether visual stability was actually reached, consume only on true stability, and add a distinct-frame timeout regression proving the boundary remains pending.

  2. TouchPlanInjector is shared by all Android helper gestures, so the reflection dispatcher changes public pan/fling/pinch/rotate/transform/two-pointer behavior, not only Maestro swipes. ADR 0013/0015 require the non-Maestro two-pointer canaries and app-observable effects to remain unchanged. Please attach exact-head pnpm test-app:replay:android (or equivalent gesture-lab) evidence; the PagerView one-pointer suite does not cover this surface.

  3. macOS Smoke is red due to the System Settings launch error -609. This looks like unrelated infrastructure, but the failed check needs a successful rerun before readiness.

No conflict; Android and other completed checks are green. Leave ready-for-human off.

@thymikee

Copy link
Copy Markdown
Member Author

Addressed the follow-up review in a9f4471:\n\n- waitForAnimationToEnd now reports whether visual stability was actually reached. Only a stable pair consumes the pending mutation boundary; a deadline retains it for the next hierarchy settle. The command is modeled as a read, so it preserves observation generation.\n- Removed the PR's async one-pointer shortcut and restored the canonical synchronous planned sample sequence. The helper's three-argument UiAutomation call now changes only the global-animation-wait policy; it does not change per-event dispatch guarantees and does not add an adb input fallback.\n- Hardened reflective lookup for SecurityException and pinned the legal two-sample sequence as DOWN -> MOVE -> UP.\n\nValidation:\n- pnpm build:android\n- focused Maestro runtime tests: 33/33\n- broad affected run: 762/771; all nine failures were unrelated exact 5s host-load timeouts. The six affected files passed in isolation, 47/47.\n- live emulator-5554 (API 36): android-helper 0.19.3, persistent-session backend. App-observable passes for one-/two-pointer pan, fling left/right, pinch, rotate, combined transform, semantic scroll, and coordinate swipe.\n- no older API image is installed locally (available AVDs are API 36/37), so the reflective fallback was not live-tested on an older runtime.\n\nAll manual sessions were closed.

@thymikee

Copy link
Copy Markdown
Member Author

Re-reviewed head a9f4471f2. The prior blockers are resolved:

  • Visual-wait completion is now explicit; only a genuinely stable screenshot pair consumes the pending mutation boundary. The distinct-frame timeout regression is non-vacuous: the old implementation would leave its clock at zero instead of performing the required hierarchy-settle cadence before the next mutation.
  • Android’s canonical synchronous planned sample sequence is restored, including the final MOVE. The remaining dispatcher change only disables the framework’s global animation wait; shared one- and two-pointer scheduling stays intact.
  • Exact-head live API-36 persistent-helper evidence covers one-/two-pointer pan, fling, pinch, rotate, combined transform, semantic scroll, and coordinate swipe.
  • All required checks are green, including the macOS Smoke rerun; the branch is mergeable with no conflict.

No remaining code findings. Residual risk: the reflection fallback was not live-tested on an older Android API, but it returns to the pre-existing public two-argument injection path. The PR summary still describes removal of the final MOVE even though the updated head restores it; correcting that summary would improve the handoff but is not a readiness blocker.

Code review is clean; marking ready-for-human.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Jul 21, 2026
@thymikee
thymikee marked this pull request as ready for review July 21, 2026 16:37
@thymikee
thymikee merged commit f087a59 into main Jul 21, 2026
24 checks passed
@thymikee
thymikee deleted the agent/android-maestro-gesture-dispatch branch July 21, 2026 16:44
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-21 16:44 UTC

thymikee added a commit that referenced this pull request Nov 16, 2026
…ion wait

The helper's input-tap and key actions injected through the public
UiAutomation.injectInputEvent(event, sync) overload, which syncs window
animations before DOWN and after UP for up to five seconds each. While a
window animation or transition stays pending, every plain press paid up to
ten seconds even though dispatch itself was immediate (#4590). Touch plans
already avoided this since #1356.

Taps and keys now inject through UiAutomationInputDispatcher without the
animation wait. A DOWN the framework refuses reached no window, so it is
cancelled and injected once more with a fresh down time after the
framework's animation sync.

Refs #4590

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thymikee added a commit that referenced this pull request Nov 17, 2026
…ion wait (#4609)

* fix(android): dispatch helper taps and keys without the global animation wait

The helper's input-tap and key actions injected through the public
UiAutomation.injectInputEvent(event, sync) overload, which syncs window
animations before DOWN and after UP for up to five seconds each. While a
window animation or transition stays pending, every plain press paid up to
ten seconds even though dispatch itself was immediate (#4590). Touch plans
already avoided this since #1356.

Taps and keys now inject through UiAutomationInputDispatcher without the
animation wait. A DOWN the framework refuses reached no window, so it is
cancelled and injected once more with a fresh down time after the
framework's animation sync.

Refs #4590

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(android): scan the whole helper source tree for direct input injection

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(android): report an unavailable animation sync apart from a refused press

Tap and key presses now share PressSequence, an Android-free policy that the
helper's JVM suite tests with a fake injector. A refused start is discarded
and retried once after the animation sync. When the runtime skips the
animation wait but cannot sync separately, the press fails with its own
outcome and error type instead of reporting a refusal. A refused end is not
cancelled, because the injection verifier has already recorded it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(android): state why a refused press end gets no cancel

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(android): release a timed-out press start instead of retrying it

Synchronous injection reports a dispatch timeout and a drop alike as false,
but the dispatcher starts its 30 s deadline when the call enters it, so only
a refusal at least that long after the call can be a timeout. A timed-out
start was enqueued and reaches the receiver, so it is now released (touch:
ACTION_CANCEL, key: ACTION_UP with FLAG_CANCELED) and reported as its own
outcome instead of being followed by a second start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(android): pin that a timed-out press start fails as a timeout without an end

The outcome-to-exception mapping moves from AutomationCommandHandler into
PressSequence, next to the outcome it maps, so the JVM suite covers it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(android): share one touch event builder and keep typed press outcomes

- Taps and touch plans build their finger events through TouchEvents.
- A dropped start on a runtime that injects through the public overload
  fails at once, without a discard, as it did before this change.
- A discard or cancel that throws no longer replaces the press outcome.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(android): bound a press by the host budget and report a refused cancel

A synchronous injection can block until the framework's 30 s deadline, so a
press that waited it out answered after the host's 30 s input timeout and
lost its typed result. The helper now bounds each press by a 40 s budget:
the retry of a dropped start runs only when the animation sync and its own
deadline fit, and an end that does not fit is injected without waiting for
dispatch. The host waits 45 s for helper input; a repo guard keeps that above
the press budget.

A timed-out start whose cancel is refused now says so in its timeout
instead of claiming it was cancelled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(android): release every refused press start and bound the retry by the host budget

Replaces the timing-based timeout classification, the cancel-result
outcomes, the async end injection and the helper's fixed press budget with
one rule. Every refused start is released (touch: ACTION_CANCEL, key: a
canceled ACTION_UP), which covers both a dropped start and one that timed
out after delivery. The start is retried at most once, only when the host's
remaining budget, now sent with each input command, still fits the
animation sync and the retry's injection deadline. Fill's tap uses the same
command deadline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(android): derive the helper press budget from the request's remaining deadline

The host now waits for an input command until the earlier of its input cap
and the request's own deadline, and sends the helper that wait less its
answer margin, instead of a fixed budget. A request near its deadline sends
a small budget, so the helper skips a retry it could not finish in time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(android): run a press without a budget as a no-retry press

A provider-supplied helper can be newer than its host, which then sends no
budgetMs; that press is no longer refused with a JSONException but runs
without a retry. Also states why the retry reserves the sync and the
retried start but not the end, and drops an unused import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(android): refuse a press whose request has no room for one injection

The host now admits helper input at one point: when the request's remaining
time, less the answer margin, cannot cover one synchronous injection's 30 s
framework deadline, the press is refused with the typed reason
android-input-budget-exhausted before anything reaches the helper, so the
host can never stop waiting mid-injection and tear the shared session down.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(android): name the budget test's catch parameter error

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(android): state what the input timeout covers and why a budget refusal skips the fallback

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(android): admit input on one attempt's cost and check fill's time before typing

The host refused any press whose request had under 35 s left, because its
admission minimum was a full 30 s injection plus the answer margin. It now
admits a press when the remaining wait covers one attempt (2 s) and sends
the helper the wait less the margin, down to zero, which only rules out the
retry. Fill checks once after its focus tap that the accessibility
interaction timeout still fits before entering text, and a helper whose host
sends no budget assumes the older host's 30 s wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(android): pin fill's typed refusal when text entry no longer fits

Moves fill's post-tap budget check into requireTextEntryTime, unchanged, so
the helper's JVM suite covers both sides of its 5 s boundary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant