fix(android): wait out a device-offline refusal and retry once
Summary
An Android emulator can drop back to offline for a few seconds after sys.boot_completed while adbd restarts. In that window, the host adb refuses every command with adb: device offline before anything reaches the device. adb-failure.ts already classified this as device_offline and marked it retriable, but no caller ever acted on that.
In the e2e mobile benchmark, the first test after boot hit that window during the snapshot helper install (job):
APP_UNREACHABLE: snapshot failed: Android snapshot helper failed: Failed to install Android snapshot helper: device offline: adb: device offline
The device-scoped executor (createSerialAdbExecutor) now reacts to a device offline refusal, whether it comes back as a result or as a thrown error. It runs adb -s <serial> wait-for-device against the same adb server and environment, then retries the command once. Only the bare host refusal counts: stderr exactly adb: device offline or error: device offline, empty stdout, and no timeout. Output from a command that ran on the device never matches. The refusal comes from the host adb, so the command never ran and the retry cannot repeat a side effect. If the device is still offline, the second refusal surfaces with the existing classification and hint.
The retry is bounded so short probes keep their budgets:
- A caller's
timeoutMscovers the wait and the retry together. The wait takes at most half of what is left, and 15 s when the caller sets no timeout. With no budget left, the refusal stands. An abort during the wait skips the retry. - A caller without a timeout gets an unbounded retry, as its first attempt was.
- A device that stays offline through its wait fails fast for 30 s instead of making every call wait again. The mark is keyed by adb server and serial, and the device's next answer clears it (a timeout or a cancel does not). Without this, a wedged device would cost 15 s per call to
doctor, the boot uptime probe, and snapshot-helper retirement.
Touched: 2 source files (adb-provider-scope.ts, adb-failure.ts) and 2 test files.
Validation
-
Live, on a Pixel 7 API 36 emulator:
adb -s emulator-5554 reconnect devicefollowed immediately by a guardedshell truethroughcreateDeviceAdbExecutor. Onmain, 5/5 attempts fail withadb: device offline(11-13 ms). With this change, 6/6 succeed (440-560 ms) with and without a caller timeout, and so does the thrown-error path. This also confirms the real host serializes the waitFor-only invocation. -
adb-provider-scope.test.tscovers:- an offline result retries after the wait (exact host calls asserted);
- a thrown offline error gets the same single retry;
- the wait and the retry share the caller's timeout;
- an abort during the wait skips the retry;
- a non-offline failure is not retried;
- device output that mentions
device offlineis not retried; - a refusal with no budget left stands;
- the wait uses the command's adb server and env;
- a device that stays offline stops waiting until it answers again, and a timeout doesn't clear that.
Each new assertion fails without the fix.
-
adb-executor.test.ts: the retriable-classification test now models a device that stays offline (the command, the wait, the retry). -
pnpm check:affected --run: passed.pnpm test:coverage:ci: passed. Changed-line gate: passed (100%, 51/51).