feat: bounded retry for a dropped tap, and poll the screen more gently

Running spotify_play against the real phone showed a tap can be delivered
to the app and then never acted on (the dispatcher lists the Spotify window
as the touch target, and the screen does not move). The run log also showed
step durations were printed as 0s while the recorded ones were correct.

- wait steps accept "retry N": on timeout, re-run the step above and wait
  again, up to N extra times. Only a wait may use it, it needs a step above
  it, and it can only press something already matched by text. spotify_play
  uses it on the search box and on the playback check.
- The success log line printed the duration before the deferred assignment
  ran. It now records the duration first.
- uiautomator dump starts a JVM on the phone, and the wait helpers polled
  every 400ms. ui.PollInterval is now 1500ms, which cuts that load on a
  phone that is already short of memory.

docs/phase-3-spotify-recipe.md logs attempts 7-10: the recipe now reaches
tap_row and picks "Honky Tonk Women" at (540,878), but the app stops acting
on input on this loaded phone, so the end-to-end run is still outstanding.
This commit is contained in:
2026-10-16 14:12:01 +11:00
parent 767844cacc
commit ab69f37aa4
6 changed files with 175 additions and 23 deletions

View File

@@ -11,6 +11,13 @@ import (
"gitea.lab.audasmedia.com.au/sam/artemis_control/internal/adb"
)
// PollInterval is how long the wait helpers sleep between screen dumps.
//
// A dump runs a whole uiautomator JVM on the phone, which is expensive on a
// loaded device: polling every 400ms starves the very app Artemis is driving.
// A slower poll costs a moment of latency and keeps the phone responsive.
const PollInterval = 1500 * time.Millisecond
// Android key events we use.
const (
KeyHome = 3
@@ -173,7 +180,7 @@ func WaitForText(r *adb.Runner, query string, exact bool, timeout time.Duration)
}
}
}
time.Sleep(400 * time.Millisecond)
time.Sleep(PollInterval)
}
if len(seen) > 0 {
return nil, fmt.Errorf("text %q is on screen but no enabled match could be tapped", query)
@@ -194,7 +201,7 @@ func WaitForNoText(r *adb.Runner, query string, exact bool, timeout time.Duratio
if err == nil && len(h.FindText(query, exact)) == 0 {
return nil
}
time.Sleep(400 * time.Millisecond)
time.Sleep(PollInterval)
}
return fmt.Errorf("text %q was still on screen after %s", query, timeout)
}