Skip to content

fix(android): use typed evidence in the readiness boot poller - #4717

Merged
thymikee merged 3 commits into
mainfrom
t3/fix-android-boot-poller
Nov 20, 2026
Merged

thymikee merged 3 commits into
mainfrom
t3/fix-android-boot-poller

Conversation

@thymikee

@thymikee thymikee commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Use the existing Android boot verdicts in the second readiness poller. Transient offline and not-ready observations retry within the existing budget. Terminal failures return typed evidence promptly, and cancellation preserves the caller's reason.

Three files change. Refs #4426. App-lifecycle cancellation and deadline forwarding remain tracked there.

Validation

Base de36d03b707ad199c3f50b12f5ed8f90f8c1ea8c. Tested head c277c86c40fd75e7250dcf55fb3b03345c698cbb.

  • pnpm check:affected --run passed at the exact head (exactCommit=true, vitest-related and unit).
  • New regression: identical probe failure text, different typed evidence. Transient evidence retries to booted. Terminal evidence fails on the first poll. It fails on the base runtime.ts and on both verdict mutants (always retry, never retry).
  • Live: the branch CLI cold-booted the stopped AVD Pixel_9_Pro_XL_API_37 (Android 17) through boot --headless, with booted: true and bootOccurred: true. That run was at 33d6fa8 (pre-rebase, same production diff). It was shut down afterwards. No stopped dedicated AVD was free at the final head, so a rerun at c277c86 is open.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.45 MB 6.45 MB -705 B
Package (unpacked) 6.45 MB 6.45 MB -705 B
Package (download) 1.97 MB 1.97 MB -113 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 20.9 ms 21.8 ms +1.0 ms
CLI --help 47.6 ms 43.9 ms -3.7 ms

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The change at 1f24c83 needs stronger regression and live validation before merge.

The offline then booted test also passes on the base because the old loop retries every non-1 stdout. It can pass even if terminal and transient errors are retried alike. Could a production-route regression use identical diagnostic text with different typed evidence and assert retry versus prompt terminal failure, and show that the base or a verdict mutant fails?

The reported cold boot does not include the command or captured output that identifies the readiness route, so it does not establish which poller ran. Please record, with the branch-built CLI (node bin/agent-device.mjs after pnpm build), the exact command and output for a stopped AVD through daemon bootTarget or bootTargetHeadless to readiness/runtime.ts waitForBoot, including the device API level, bootOccurred, booted result, and cleanup.

The still-booting deadline test repeats the existing deadline test and also passes on the base. Please remove it or replace it with a distinct regression that fails without the typed verdict.

All 18 checks pass. There are no known conflicts. Before merge, provide verifiable live cold-boot evidence and a regression that detects loss of the typed transient versus terminal decision.

thymikee and others added 3 commits November 20, 2026 13:19
…nce (#4426)

The second Android boot poller (waitForBoot in the readiness runtime behind
ensureReady/bootTarget) still made retry/stop decisions from raw probe output:
a terminal device_unauthorized or host refusal was polled until the deadline
and then misreported as boot_timeout, and a probe-level exec timeout escaped
untyped. It now stamps each observation through the existing typed evidence
owner (androidAdbResultError/attachAdbFailureHint classification) and applies
the same shared verdicts as the #4610 lifecycle poller
(isTransientAndroidBootFailure/androidBootFailureReason, now exported from
emulator-lifecycle.ts): transient not-ready/offline observations retry inside
the existing deadline budget, terminal unauthorized/host-refusal/unclassified
outcomes stay terminal with typed adbFailure/reason details, probe timeouts
report ANDROID_BOOT_TIMEOUT, cancellation keeps the abort owner's typed
reason, and deadline expiry keeps the boot_timeout typed outcome.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@thymikee
thymikee force-pushed the t3/fix-android-boot-poller branch from 1f24c83 to c277c86 Compare November 20, 2026 12:43
@thymikee

Copy link
Copy Markdown
Member Author

Thanks for the review. Head is now c277c86c40fd75e7250dcf55fb3b03345c698cbb, rebased on origin/main (de36d03). The PR still changes three files.

1. Offline-then-booted test

I replaced it with one regression through ensureAndroidReady. The probe throws the same text, adb shell getprop sys.boot_completed failed, with typed evidence {adbFailure: 'device_not_found', retriable: true}. The only difference is adbHostRefusal: true.

  • Transient evidence: the poller retries, and the second probe reports booted. run is called 2 times.
  • Terminal evidence: the poller fails on the first poll with ADB_TRANSPORT_UNAVAILABLE. run is called 1 time, and 0 ms elapse.

Failing output (I committed WIP first, then restored with git checkout):

== verdict mutant: always retry  (if (observation.failure && false))
 FAIL  identical probe failure text retries on transient typed evidence and fails promptly on terminal typed evidence
AssertionError: promise resolved "{ platform: 'android', …(5) }" instead of rejecting

== verdict mutant: never retry  (if (observation.failure))
 FAIL  identical probe failure text ...
AssertionError: promise rejected "Error: adb shell getprop sys.boot_complet… { …(2) }" instead of resolving
Serialized Error: { code: 'COMMAND_FAILED', details: { ..., adbFailure: 'device_not_found', retriable: true, reason: 'BOOT_COMMAND_FAILED' } }

== base runtime.ts (de36d03)
 FAIL  identical probe failure text ...
AssertionError: promise rejected "Error: adb shell getprop sys.boot_complet… { …(2) }" instead of resolving
Serialized Error: { code: 'COMMAND_FAILED', details: { adbFailure: 'device_not_found', retriable: true } }

== head c277c86
      Tests  1 passed | 13 skipped (14)

2. Still-booting deadline test

I deleted it. I did not replace it. The existing deadline test already covers the not_ready verdict: if bootObservation === 'not_ready' is removed from isTransientAndroidBootFailure, that test fails with reason: 'BOOT_COMMAND_FAILED' instead of boot_timeout.

3. Live cold boot

Route: session-boot.ts:132 calls bootTargetHeadless. platform-android/src/runtime.ts maps it to ensureAndroidReady(..., headless: true). That calls ensureEmulatorReady, then waitForBoot.

Run with the branch CLI after pnpm install --frozen-lockfile && pnpm build, at 33d6fa8 (before the rebase; the production diff is the same):

$ node bin/agent-device.mjs boot --platform android --device Pixel_9_Pro_XL_API_37 --headless --state-dir /private/tmp/ad-4717-boot --json --debug
[agent-device][diag] {"phase":"daemon_request","command":"boot","durationMs":53151,...}
{
  "success": true,
  "data": {
    "platform": "android", "target": "mobile",
    "device": "Pixel_9_Pro_XL_API_37", "id": "emulator-5556",
    "kind": "emulator", "booted": true,
    "selection": { "reason": "explicit-selector", "source": "local", "candidateCount": 1, "bootOccurred": true }
  }
}
  • Before the boot, devices showed Pixel_9_Pro_XL_API_37 with booted: false.
  • After the boot, devices showed emulator-5556, model sdk_gphone16k_arm64, osVersion: "17" (API 37).
  • The request log has 48 adb exits with code 1 during the boot. They are probe misses while the emulator came up, and the poller retried them to readiness.
  • Cleanup: I shut the emulator down and ran daemon stop --state-dir /private/tmp/ad-4717-boot. After that, devices showed Pixel_9_Pro_XL_API_37 with booted: false.

Limit: I did not rerun at c277c86. When I checked again, emulator-5556 (Pixel_9_Pro_XL_API_37) was running for another owner, and I did not stop it. No other dedicated stopped AVD was free. Please run the same command on another host at c277c86.

Validation at c277c86

pnpm check:affected --run passed with exactCommit=true (vitest-related and unit). There are no inline review threads to resolve.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of c277c86

Since the review of 1f24c83: 1 new · 0 still open · 0 no longer raised

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
packages/platform-android/src/readiness/runtime.ts:189 🆕 Terminal probe failure loses the original AppError cause; sibling poller keeps it

Reviewed with this repository's own Sentinel configuration (0a1c2cce7b9b).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on c277c86. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

The PR is ready at c277c86. The earlier concern from the review at 1f24c83 is fixed, CI is green (19 checks, none failing), and there are no conflicts. Not blocking, and fine to take or leave: the stderr "device offline" exit-1 retry case was removed from runtime.test.ts, and the new regression throws a pre-typed AppError, so it skips the nonzero-exit classification route. Could you add one case through ensureAndroidReady where the probe returns { stdout: '', stderr: 'error: device offline', exitCode: 1 } and then the booted probe, and assert it resolves booted with run called twice? A change that makes every nonzero exit terminal would pass today's tests, and that would break the common cold-boot path.

On the open inline threads: the thread on error code and cause in the readiness poller still applies and is minor. Reusing buildAndroidBootError would shape errors the same way in both pollers.

The live run was at 33d6fa8, before the rebase. The production code matches that head through range-diff, with no upstream change to the route files. Nothing else must happen before merge.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
@thymikee
thymikee merged commit c94e110 into main Nov 20, 2026
19 checks passed
@thymikee
thymikee deleted the t3/fix-android-boot-poller branch November 20, 2026 13:18
@thymikee

Copy link
Copy Markdown
Member Author

Pushed 8c0dd8a5ca. It takes both recommended follow-ups from the review at c277c86, and it closes the open review thread.

  1. Offline then booted: new case through ensureAndroidReady. The probe returns { stdout: '', stderr: 'error: device offline', exitCode: 1 }, then the booted probe. It resolves, with run called twice. A change that makes every nonzero exit terminal now fails this test.
  2. Shared error shape: the readiness poller reuses buildAndroidBootError, now exported from emulator-lifecycle.ts. The builder passes the original cause on every branch. A new test pins the cause on a terminal TOOL_MISSING failure and fails without the change.

The PR still changes three files. All 1,512 platform-android tests pass, and typecheck and lint are clean.

Local validation: pnpm check:affected --run failed at this head on two repo-guard tests that hit their 5-second limit under host load (load average about 28): test/repo-guards/daemon-fixture-launches.test.ts and test/repo-guards/macos-helper-package-contents.test.ts. Neither touches Android readiness code, and both pass when run alone (4 of 4). Hosted CI validates this head.

Live evidence: unchanged. The cold boot ran at 33d6fa8, before the rebase. A rerun at the final head is still needed on a host with a free dedicated AVD.

@thymikee

Copy link
Copy Markdown
Member Author

Correction to my last comment: this PR merged at c277c86 before that push, so the two follow-ups are not in it. They are in #4812.

thymikee added a commit that referenced this pull request Nov 20, 2026
* origin/main:
  refactor(apple-runner): generate the Swift runner error-code enums from runner-contract.ts (#4810)
  fix(daemon-client): report a newer daemon that won a startup race as daemon-incompatible (#4801)
  feat(shake): add a shake command for iOS simulators and Android emulators (#4741)
  fix(daemon): give a closing daemon its full teardown before anything kills it (#4806)
  fix(android): use typed evidence in the readiness boot poller (#4717)
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