Skip to content

android: check ownership before the readiness code stops an emulator whose boot failed #4867

Open

Description

@thymikee

Follow-up from the reviews of #4863 (#4863 (comment) and the maintainer review #4863 (comment), non-blocking note 1).

Problem

#4863 stops the emulator a cold boot launched when the boot fails for a non-deadline reason, from the Android readiness code (packages/platform-android/src/readiness/runtime.ts). That stop is gated by the device-shutdown policy, but it has no check that another session or device claim holds the emulator. A second open that binds to the booting emulator-NNNN could lose it when the first open's boot fails afterwards.

The daemon's failed-open cleanup (stopUnownedLaunch, #4842) already does this check: session holding the device, claim held by another owner, both under the per-device claim lock, plus the pid and start-time identity.

Required behavior

Before the readiness stop signals the launched pid, no other session or claim holds that device. Decide where the check lives: make the readiness stop ownership-aware, or route a failed boot through the daemon's existing cleanup path so there is one stop path with all gates.

Completion conditions

Activity

  1. added this to the 0.22 - lean core milestone on Nov 20, 2026
  2. apex-sentinel-staging commented on Nov 20, 2026

    @apex-sentinel-staging

    Apex Sentinel · Issue review

    Suggested label: bug

    The issue describes a concrete race/defect in Android readiness code stopping an emulator without verifying no other session or claim owns it. It provides a required behavior and completion conditions, so a maintainer can act on it.

    Required sections

    • Steps to reproduce (missing)
    • Expected and actual behavior (missing)
    • Version or environment (missing)
  3. thymikee commented on Nov 21, 2026

    @thymikee
    MemberAuthor

    Optional follow-ups from the final review of #4863 (#4863 (comment)), to take with this issue because they touch the same code:

    • Derive the keep in packages/platform-android/src/readiness/runtime.ts from !bootWaitDone && clock.now() >= deadlineAtMs and drop the bootBudgetSpent marker from error.details.
    • Reword the ADR 0029 amendment: the emulator host gates its own terminate, and the daemon's launched-process stop uses the deviceShutdownDenied flag.
    • Add one composition test through createPlatformRuntimeHost with a throwing assertShutdownAllowed that expects deviceReadiness.androidEmulator.terminate to reject (src/platform-runtime-operation-host.ts).
  4. thymikee commented on Nov 21, 2026

    @thymikee
    MemberAuthor

    Note for whoever takes this: an implementation of the second option (route a failed boot through the daemon's existing failed-open cleanup, so one stop path has the policy gate, the session check, the claim lock and the pid identity) was written during #4863 and set aside when the review chose the smaller policy-gate fix. It is the local commit 1c81fba458 ("keep the failed-open stop in one place"), kept on the unpushed local branch redesign-4863-not-pushed. It was not reviewed and not validated against the merged #4863. The design choice between the two options in this issue is still open for the maintainer.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions