fix(server): wait for Android boot and stream readiness before opening #48277
main fromrefs/pull/48277/head·opened View on GitHubProblem#
Cold-booting an Android emulator from the Device panel reliably fails with "No video received from the device. Reconnect to try again." on the first open:
expo-device-hub'sPOST /api/devices/bootreturns as soon asadbcomes online, beforesys.boot_completed=1and SurfaceFlinger are ready.- Once
openpublishes the session,serve-emu's first capture startup (scrcpy-server, ffmpeg probe, and H.264 startup gate) can exceed the client's 15 s first-frame timer (FIRST_FRAME_TIMEOUT_MS), so the panel gives up before the first frame arrives even though the emulator is still starting normally.
Expected behavior: boot finishes booting and warming the stream (while the panel shows "Starting…"), then opens the session ready to stream frames within the 15 s client budget.
Change#
In apps/server/src/device/DeviceHubOperations.ts, mirror what iOS boot already does (attachIosStream) for cold-booted Android emulators (skipping physical phones and missing/non-emulator serials):
- After
/api/devices/bootreturns anemulator-<port>serial, polladb -s <serial> shell getprop sys.boot_completedfor up to 2 minutes (every 1.5 s) until it returns1. - Once boot completes, call
GET /vendor/serve-emu/health?device=<serial>(up to 60 s). Inexpo-device-hub@0.26.1,/healthawaitsserve-emu's sharedensure()startup, returns200 { ok: true, status: "streaming" }once capture is streaming (and keeps capture warm with 0 clients), and returns503during a failed start or its 5 sSPAWN_RETRY_COOLDOWN_MS. Warm-up retries through cooldown503s and up to one transient startup failure. - Both stages reserve 5.5 s inside their deadlines to confirm an emulator exit via two
adb devicesomissions separated by 1.5 s (so a single transientadbblip does not abort boot, and exit confirmation never overshoots the stage budget). A confirmed exit fails boot withDeviceBootError(launch_failed)preserving the underlyingcause; slow boots or video/HTTP failures log a warning and degrade cleanly so agent-only flows and Reconnect still work. - Does not touch the client's 15 s first-frame timer in
packages/client-runtime/src/device/stream.ts,DeviceHubOperations.attach,LocalDeviceHost, orDeviceService.ts.
Scope#
Focused server bug fix in DeviceHubOperations.boot (2 files: DeviceHubOperations.ts and DeviceService.test.ts).
Context: #18598 described the same cold-start timeout symptom and was closed as Not planned because the 15 s client timer is working as designed; this fix leaves that timer untouched and waits for readiness during server-side boot instead.
Verification#
- Live Windows Android emulator test (
b6a615c798, identical 2-file patch before clean rebase onto4b8199987c→4d4a4e2041) on Windows 11 Pro (10.0.26200), Android Emulator 37.2.13.0 (Medium_Phone_API_37.0, Android 17.0), isolatedexpo-device-hub@0.26.1,ffmpeg9.0.2, running the realmakeDeviceHubOperations:- True cold boot (
-no-snapshot):POST /api/devices/bootreturnedemulator-5554in 12.95 s whilesys.boot_completedwas still empty; polling waited 6.6 s (5 polls) untilsys.boot_completed=1;GET /vendor/serve-emu/health?device=emulator-5554blocked 1.52 s and returned200 { ok: true, status: "streaming" }(libx264,grpc-screenshot); totalboot()took 21.1 s. Opening/vendor/serve-emu/ws?device=emulator-5554&frame-meta=1immediately after received the first binarySEMUvideo frame in 166 ms with 0 reconnects, followed by a valid 443 KB PNG screenshot and clean shutdown. - Quick Boot resume:
POST /api/devices/boottook 3.44 s (sys.boot_completed=1on poll #1),/healthreturned200 streamingin 2.28 s (totalboot()5.97 s), first WS video frame arrived in 165 ms with 0 reconnects, followed by a valid 715 KB PNG screenshot and clean shutdown.
- True cold boot (
- Hub source check: Verified
expo-device-hub@0.26.1vendor/serve-emu/dist/middleware.jsbehavior (/healthawaitsensure(), returns200 { ok: true, status: "streaming" }only when streaming, and returns503with"cooling down after a failure"during its 5 sSPAWN_RETRY_COOLDOWN_MS). - Focused automated checks (
vp run check:changedon rebased4d4a4e2041):format,lint(0 warnings, 0 errors, 206 rules),knip,graphql,typecheck, andtest(DeviceService.test.ts: 87 passed including 8 newTestClocktests for boot-completion wait, restarted cooldown retries, missing-serial skip, timeout/warm-up degradation, transientadbomission, and confirmed exit within the 60 s budget;AgentContextBudget.test.ts: 2 passed). - Not verified live: Neither live run triggered a
serve-emu503/cooldown (covered byTestClockunit tests), and the live stream check measured binarySEMUframes arriving on the WebSocket rather than full browser decoding in the Device panel UI.
Model: Gemini 4 Neon (high); harness: Antigravity in T3 Code.
- 1
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Approved at
4d4a4e2Macroscope's review found this PR approvable — Android emulator launches now wait for boot and stream readiness before opening, reducing premature video failures. The added waits are bounded, with fallback behavior for slow startup and stream errors; physical devices and iOS are unaffected.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Walkthrough
-
Android virtual-device boot now polls
sys.boot_completedand then checks the serve-emu health endpoint before returning. Timeouts and stream startup failures log warnings and retain the serial; confirmed emulator exits raiseDeviceBootError. iOS stream attachment remains unchanged.Changes: Android emulator boot readiness
Layer / File(s) Summary Boot probes and exit confirmation
apps/server/src/device/DeviceHubOperations.tsAdds bounded boot-completion polling and exit confirmation. Two successful adb devicesomissions confirm an exit; failed probes do not.Serve-emu stream warm-up
apps/server/src/device/DeviceHubOperations.tsChecks the serve-emu health endpoint after boot completion. Retries eligible HTTP 503 responses, handles cooling-down responses, and stops on other failures or deadline expiry. Boot flow and validation
apps/server/src/device/DeviceHubOperations.ts,apps/server/src/device/DeviceService.test.tsRuns Android readiness checks when the hub returns an emulator serial. Tests cover retries, cooldowns, timeouts, missing serials, and confirmed exits. iOS stream attachment behavior is unchanged. Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant DeviceHubOperations participant Hub participant Adb as adb participant ServeEmu as serve-emu health endpoint DeviceHubOperations->>Hub: Request Android device boot Hub-->>DeviceHubOperations: Return emulator serial loop Until boot completion or deadline DeviceHubOperations->>Adb: Probe sys.boot_completed Adb-->>DeviceHubOperations: Return boot state end loop Until stream ready or deadline DeviceHubOperations->>ServeEmu: Request health status ServeEmu-->>DeviceHubOperations: Return health response endSuggested reviewers:
juliusmarminge
Merge Risk:
Minimal · up to4d4a4-
This change makes Android emulator boot wait for boot completion and stream readiness before returning. It degrades cleanly on slow boots and fails only when an emulator exit is confirmed. No concrete merge-blocking risk was established. The worst-case boot is longer, which matters only if some caller enforces a short timeout, and none was found in the server code.
Pre-merge checks:
4-
Check name Status Explanation Title check The title "fix(server): wait for Android boot and stream readiness before opening" matches the main change: DeviceHubOperations.boot now waits for sys.boot_completed=1 and a serve-emu health response … Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Description check The description is thorough and follows the template. It has Problem, Change, Scope, and Verification sections. The Problem section states the cold-boot failure, the cause, and the expected behavior. … Full details: Title check
-
Explanation
The title "fix(server): wait for Android boot and stream readiness before opening" matches the main change: DeviceHubOperations.boot now waits for sys.boot_completed=1 and a serve-emu health response before the session opens. It follows the conventional commit format and is specific enough for a teammate scanning history. The title does not mention the confirmed-exit failure path, but that is a secondary detail.
Full details: Description check
-
Explanation
The description is thorough and follows the template. It has Problem, Change, Scope, and Verification sections. The Problem section states the cold-boot failure, the cause, and the expected behavior. The Change section lists the server-side polling, warm-up, and exit-check behavior and names the files left untouched. The Scope section names the two changed files and links context from a closed issue. The Verification section reports live Windows emulator runs with timings, the automated checks run, and what was not verified live. The template asks for a conventional commit title in the PR title, but the title is not part of the provided description, so it cannot be checked here. The model and harness line is present at the end. Issue
#18598is referenced in Scope but not linked as a URL, which is minor.
-
Finishing Touches
-
Generate unit tests (beta)
-
- 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: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 4b81999
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6e32b5b7-8c74-4f14-932c-f2e5b01ac4a7
Commits-
Reviewing files that changed from the base of the PR and between 4b8199987cb63f82912b8f3dbe9de6a96cdb057b and 4d4a4e2041fefd6bb1852a4b09126354e1e7adb3.
Files selected for processing: 2-
apps/server/src/device/DeviceHubOperations.tsapps/server/src/device/DeviceService.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.
-
-
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes