fix: honor wait budgets, preserve the daemon on polling timeouts, refuse off-screen selector taps

Merged
TH
5mo ago
+648-35

Dogfooding session: drove the Bluesky dev build (deep RN app, signed-in account) end to end on the iPhone 17 Pro simulator as an agent would — doctor → open → snapshot → press/fill --verify → wait stable/wait text → error paths. Four defects fixed, each reproduced live before and verified fixed live after.

1. wait dies at 90s regardless of its own timeout (and takes the daemon with it)

wait text "Create account" 180000 accepted the 180s budget, then died at 90s with Daemon request timed out — the wait budget travels as a positional, so resolveDaemonRequestTimeoutMs never saw it and used the default envelope. Worse: wait was on the daemon-reset timeout path, so the collateral was runner killed → daemon reset → SESSION_NOT_FOUND on the next command. One overlong wait for a Metro bundle destroyed the whole session.

  • The client now parses wait positionals (shared src/core/wait-positionals.ts parser, including sleep durations) and extends the request envelope to budget + 30s margin — extend-only, never shrinks below the default.
  • wait/find join snapshot on the daemon-preserving timeout path. They ARE repeated snapshot captures; the preserve-snapshot rationale ("can block in platform accessibility bridges") applies verbatim.
  • Live proof: wait text <bogus> 100000 now runs past the old 90s cliff, fails with the wait's own timeout shape, and the session survives.

2. Off-screen selector targets silently tapped (the big one)

tap "label=Explore" against Bluesky's closed drawer returned success: true, "Tapped (-161, 265)" — negative x, coordinates that physically cannot land. Three layers each missed it, and all three are fixed:

  • Selector disambiguation now prefers candidates whose center lies in the root viewport (isNodeVisibleOnScreen). Center, not edge overlap: Bluesky's drawer overlay grazes the viewport by 0.07px of float rounding, so rect-intersection wrongly counted it as visible. With this, press "label=Profile" (drawer item + bottom tab, both matching) taps the on-screen tab at (355, 817) instead of the drawer at (-161, 615). All-offscreen candidate sets keep the existing deepest-smallest tiebreak, and ambiguity-tie failures are unchanged — this only reorders preference among already-ambiguous matches.
  • Selector-resolved interactions get the same off-screen guard @ref targets already had (parity fix): reason: offscreen_selector with rect/viewport details and a "scroll toward it or open its container" hint.
  • The runner's direct selector tap refuses matches whose center is outside the main window frame with ELEMENT_OFFSCREEN, which the daemon treats as a fallback trigger to the tree-based path. app.frame is unusable for this: on RN apps it unions transformed subtrees, so the closed drawer inflates it and containment always passes.

Also fixed en route: isNodeVisibleOnScreen composes effective-viewport visibility (nearest scrollable ancestor) with the root check — a drawer item is "visible" inside its own off-screen ScrollView, so the ancestor check alone also passed.

3. --verify evidence contradicted by the non-hittable hint

press @ref --verify on a non-hittable target returned evidence.changedFromBefore: true directly next to the hint "this press may have had no visible effect. Verify with a snapshot" — stale advice the evidence just disproved, and an invitation to spend a wasted snapshot. The hint is now dropped when evidence proves a change; kept when evidence shows no change or verify is off.

4. Tests

New/extended: wait-budget envelope cases (text/stable/sleep/small/default), daemon-preserving timeout set, on-screen preference + edge-grazing + all-offscreen + offscreen-ScrollView disambiguation fixtures (Bluesky-shaped), selector offscreen guard (asserts zero taps), hint-suppression triple (changed/unchanged/no-verify), ELEMENT_OFFSCREEN fallback triggers. Suites: 1600 unit + 89 provider integration green; format/typecheck/lint clean.

Compatibility note: the disambiguation preference and the off-screen guard change behavior only for selectors that resolve to elements whose tap point is outside the viewport — previously silent no-op taps reporting success. The react-navigation Maestro suite taps drawer items with the drawer open (on-screen), so it should be unaffected, but it's worth a run before release per the repo convention on resolution changes.

Remaining findings from the same session are filed separately (stale-ref silent mismatch, runner-uptime fields leaking into responses, wait stable settling on splash trees, doctor's generic adb-timeout hint).