fix(ci): wait longer for the Android keyguard and repeat a dropped dismissal

MI
3h ago
+163-26

What

The Android emulator readiness step in mobile.yml no longer fails a job because the emulator is slow. It waits up to 30 seconds for the lock screen to report non-secure, and it sends wm dismiss-keyguard again when the emulator drops the request. A secure lock screen still stops the job before any dismissal, and the script never enters credentials.

Why

Since #2394 merged, 16 of 481 finished Android jobs failed in .github/scripts/prepare-android-emulator.mjs, counted on 2 December. All 16 used up the script's single five-second budget and ended 6.5 to 9.7 seconds after the script started. The 29 passing jobs I sampled finished the whole script in 1.6 to 4.6 seconds.

On a loaded local API 36 emulator I reproduced the two places it failed.

  • Before the dismissal, 6 of the 16. dumpsys window policy reports secure=true until the keyguard service connects, which took up to about 15 seconds. It then turns secure=false by itself, and dumpsys lock_settings shows CredentialType: NONE.
  • After the dismissal, 10 of the 16. The emulator can drop wm dismiss-keyguard. I kept 6 stuck boots alive. In each one the lock screen still showed, non-secure, 30 seconds later, and a second wm dismiss-keyguard cleared it at once.

#2394 never repeats the dismissal. Its safety rules are that the script never dismisses a secure lock screen and never enters credentials. A repeat sent only after a fresh non-secure read keeps those two rules.

How it works

  1. .github/scripts/prepare-android-emulator.mjs:5-12 replaces the one five-second budget with four limits. The lock screen has 30 seconds to report non-secure, the dismissal has 10 seconds, requests are 1 second apart, and each setup call before the keyguard checks has 15 seconds. One setup call took 4.6 seconds locally. The budget error now reads Emulator readiness exceeded its budget, where it said exceeded five seconds.

  2. :50-56 waits for secure=false as before, with the 30-second limit.

  3. :57-59 starts the 10-second dismissal budget before the first request, so a late non-secure read leaves the dismissal its full time.

  4. :64-74 polls as before. While the lock screen still shows and reads non-secure, the script sends the request again once a second. Once the lock screen is hidden, the script only waits for the screen to turn on. A secure read still fails at once at :66.

  5. scripts/android-emulator-readiness.test.ts runs the workflow's real command against a stateful fake adb, on a fake clock that moves only on waits and adb calls. Each refusal asserts exit code 1 and its error, so a test timeout cannot pass a case. Every refusal but the still-locked one also asserts its exact number of requests. The two late cases use three secure reads of 2.5 seconds each, which keeps every case to at most 45 adb processes inside a 60-second limit. The new cases are:

    • a dropped request, and two dropped requests after a late non-secure read
    • a keyguard service that connects about 7.8 seconds in
    • a lock screen that turns secure after the request
    • a non-secure read that arrives 100 ms before the 30-second limit
    • a ready read that returns after the dismissal budget
    • a screen that turns on after the lock screen hides
    • the 15-second setup call limit

    The still-locked case checks that requests are 1.0 to 1.4 seconds apart and stop before the 10-second limit.

Issue

None filed. This follows #2394.

Verified

Ran it locally: yes, on an API 36 google_apis arm64 emulator with the pixel_7 profile and CI's emulator options. I slowed it to one emulator core and kept half the host's CPUs busy.

Slowed cold bootsPassedNeeded more than one request
main5 of 20n/a
An earlier version of this fix20 of 2014
This PR12 of 1210, and one of them needed 3
  • The first two rows come from one run that alternated the two scripts. The earlier version had the same 30-second and 10-second limits and the same repeat. It differs from this PR in three ways. Its dismissal budget started after the first request, it could repeat while the lock screen was already hidden, and its setup calls had five seconds each.
  • The slowest boot with this PR's script took 9.0 seconds for the whole script.
  • With the emulator at its default four cores and no host load, main passed 12 of 12. The failures come from load, as on CI.
  • node --test scripts/android-emulator-readiness.test.ts passes 18 of 18. With main's script in place, 9 of the 18 fail. With only the budget error reworded in main's script, 6 still fail, so 3 of the 9 fail on the error text alone.
  • 16 of 18 hand mutants of the script fail a test. The killed ones include no repeat, a repeat on every poll, a repeat while the lock screen is hidden, no secure check during the dismissal, a dismissal before the non-secure read, five-second settle and setup limits, one shared budget, and a dismissal budget that starts after the first request. The two survivors each delete a deadline throw inside a loop, at :53 and :68. shell() at :19-24 still stops the script at the same deadline, as it does on main, and only the error text changes.

Not verified: a hosted CI run of this head, which this PR's mobile workflow provides, and an x86 KVM emulator like CI's.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved Android emulator readiness handling by allowing more time for the screen to unlock and retrying keyguard dismissal when needed.
    • Emulator setup now reports readiness failures when the screen remains locked or a timeout is reached.
  • Tests
    • Expanded coverage for emulator startup delays, dismissal retries, and timeout conditions.