Skip to content

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

Open
michal-e2e wants to merge 3 commits into
mainfrom
michal/android-readiness-redismiss
Open

michal-e2e wants to merge 3 commits into
mainfrom
michal/android-readiness-redismiss

Conversation

@michal-e2e

@michal-e2e michal-e2e commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

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 boots Passed Needed more than one request
main 5 of 20 n/a
An earlier version of this fix 20 of 20 14
This PR 12 of 12 10, 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.

michal-e2e and others added 3 commits December 2, 2026 17:51
… dropped dismissal

The readiness script failed 16 of 481 finished Android jobs since #2394, all
at its single five-second budget. Two causes, both reproduced on a loaded
local API 36 emulator:

- The keyguard service reports secure=true until it connects, which can take
  most of the five seconds. The script now waits up to 30 seconds for
  non-secure state; a healthy CI run still finishes in under five.
- The emulator can drop `wm dismiss-keyguard` sent right after that: the
  keyguard stays up, non-secure, for at least 30 seconds, and a second
  request dismisses it at once. The script now repeats the request once a
  second while the keyguard still shows and is known to be non-secure,
  within its own ten-second budget that starts before the first request.

A secure keyguard still stops the script without a dismissal, and it never
enters credentials. The tests run on a fake clock that moves only on waits
and adb calls, so a refusal is the script's own exit, not the test timeout,
and the request spacing and deadlines are asserted directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… requests after a late settle

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every fake adb call starts a real process. The two late-settle cases made
about 53 and 72 of them inside a 15-second limit, which a slow runner could
miss. They now make about 10 and 17, assert that the first request comes
after five seconds, and the limit is 60 seconds.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".github/scripts/prepare-android-emulator.mjs">

<violation number="1" location=".github/scripts/prepare-android-emulator.mjs:70">
P2: A slow retry resets this timer only after `shell()` returns, adding its full latency before the next one-second wait. Record the timestamp before `shell()` so retries follow request-start cadence.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment on lines +70 to +71
shell('wm', 'dismiss-keyguard');
dismissedAt = Date.now();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: A slow retry resets this timer only after shell() returns, adding its full latency before the next one-second wait. Record the timestamp before shell() so retries follow request-start cadence.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .github/scripts/prepare-android-emulator.mjs, line 70:

<comment>A slow retry resets this timer only after `shell()` returns, adding its full latency before the next one-second wait. Record the timestamp before `shell()` so retries follow request-start cadence.</comment>

<file context>
@@ -39,22 +47,29 @@ shell('svc', 'power', 'stayon', 'true');
-  if (Date.now() >= deadline) throw new Error('Emulator keyguard did not dismiss with the screen on');
+  if (Date.now() >= readinessDeadline) throw new Error('Emulator keyguard did not dismiss with the screen on');
+  if (state.showing === 'true' && Date.now() - dismissedAt >= REDISMISS_MS) {
+    shell('wm', 'dismiss-keyguard');
+    dismissedAt = Date.now();
+  }
</file context>
Suggested change
shell('wm', 'dismiss-keyguard');
dismissedAt = Date.now();
dismissedAt = Date.now();
shell('wm', 'dismiss-keyguard');

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Emulator readiness

Layer / File(s) Summary
Setup call and readiness budgets
.github/scripts/prepare-android-emulator.mjs, scripts/android-emulator-readiness.test.ts
Setup ADB calls use a 15-second timeout. The tests check this timeout and readiness budget expiry.
Keyguard settling and dismissal
.github/scripts/prepare-android-emulator.mjs, scripts/android-emulator-readiness.test.ts
The script allows 30 seconds for the keyguard to become non-secure, then starts a separate 10-second dismissal budget. It retries dismissal once per second while the keyguard remains showing and non-secure. Tests model delayed state changes, dropped requests, screen wake, and budget expiry.

Suggested reviewers: thymikee

Change: Bug fix

Merge Risk: Minimal · up to 97604

The change makes Android emulator preparation more tolerant of slow cold boots and retries keyguard dismissal. It still stops the job when the keyguard is secure. No merge-blocking risk was identified, and the only gap is that a hosted CI run of this head was not reported.

Security architecture risk: Minimal · up to 97604

Android CI gives the emulator more time to become ready and retries a dismissal only when the latest check shows a visible, non-secure keyguard. The change still targets the same CI emulator, never enters credentials, and requires the screen to be on and the keyguard hidden before the suite starts. No material regression in security or failure containment was established.

Security review details

Security Blast Radius

  • observed — The changed dismissal behavior targets the emulator assigned to the Android suite job. The script requires an explicit emulator serial and passes it to every ADB invocation instead of using ADB's default device.

Trust Boundaries and Controls

  • observed — The host script bases its decision on the latest state reported by the targeted emulator. Reading that state and issuing dismissal were separate operations in the base and remain separate for every retry; the host-side check is not an atomic Android authorization check.

Resilience and Maintainability Implications

  • observed — The fake-ADB tests cover dropped requests, a keyguard that becomes secure, and a ready read returned after the deadline. The fake models a dismissal as dropped or as an immediate state change; it does not model a request still pending at suite start.

Hardening Proposals

  • proposed — On the pinned API 36 emulator, validate that a delayed duplicate dismissal cannot affect a later keyguard presentation after the suite takes control, particularly during the Android lock-and-unlock test.

Rollout and rollback

  • observed — The readiness script still decides whether preparation succeeds, and mobile.yml retains its 60-minute job limit. Only the suite command has a retry in the workflow; preparation handles its own dismissal retries. No workflow reconfiguration is needed to adopt or revert the new readiness behavior.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: de8fe4da-10cd-4925-b7ac-2b659384d6ae
Commits

Reviewing files that changed from the base of the PR and between 5f1b005 and 97604c5.

Files selected for processing: 2

  • .github/scripts/prepare-android-emulator.mjs
  • scripts/android-emulator-readiness.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review (AI triage pass), not yet read by a maintainer.

Reviewed 97604c5f7. The script logic is sound: the secure-lock refusal is intact, every failure still exits 1 with a named error, and the tests catch the regressions they claim to. Blocking item: CI never ran on this head.

Must fix

  1. No spec or mobile run exists for 97604c5f7. Only pr-policy and review-verdict ran (gh api actions/runs?head_sha=...), and the labeler never added size or team labels either, so the pull_request event seems lost. The Android jobs in mobile.yml are the only real check of this change, and the PR body lists them as not verified. Push again or close and reopen so they run.

Verified

  • Secure refusal: a re-dismiss at :69-72 only runs after the same iteration's fresh read passed :66 and the deadline check at :68. No credentials are entered.
  • Fails loudly: every exit path throws. shell() still caps each adb call at the remaining deadline (:19-24). Worst case is about 45 s of setup calls + 30 s settle + 10 s dismissal, and that is bounded.
  • Tests: 18/18 pass locally. With main's script in place 9 fail. With only the re-dismiss mutated out, 3 fail (locked, dropped, slow-dropped).

Should fix

  1. The PR shows that a dismissal gets dropped, but not why. AOSP drops it silently when the delegate is not yet showing (PhoneWindowManager.dismissKeyguardLw: if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()), no else for a null callback). It also drops it with a log line in KeyguardViewMediator (Ignoring request to DISMISS because mShowing=false, Ignoring dismiss because we're already going away). The first request at :57-59 goes out on secure=false alone, without checking showing. If the stuck boots are the mShowing=false case, the fix is to send the first dismissal only once a read shows showing=true. The repeat is still acceptable as-is, since it only fires after a fresh showing=true, secure=false read. But please run logcat -d -s KeyguardViewMediator on one stuck boot and name the cause in the comment at :61-63.

For the maintainer

  • Is a state-gated repeat of wm dismiss-keyguard acceptable under the no-heuristics policy, or should it wait until the drop cause is named (Should fix 1)?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants