Repository navigation
fix(open): stop the emulator an open booted when the open fails - #4842
Conversation
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 72f20d3. The verdict and the full list are in the summary comment.
An open that boots a stopped Android emulator and then ends without publishing a session left that emulator running with nothing to own it: no session recorded the boot, so no later close ever learned to stop it (#4764). The open now stops the launch it caused when its own steps end without a session, whether they return a failure, throw, or report the request canceled, and reports the result on that open's own error details as failedOpenEmulatorCleanup. A host that refuses the stop itself is treated as an unconfirmed stop: the open's own error stays the reported error either way. Only a launch this open caused is stopped. The readiness runtime reports the process it started, and reports nothing at all when the device was already running, so a prebooted emulator is never mistaken for this open's launch and no serial-based process probe is added. A launch whose start time could not be read keeps running with one diagnostic naming the step. When the daemon's policy denies device-shutdown nothing is signaled and the reason rides the error (ADR 0029 amended). The stop goes through the launched-process owner the root already composes, on the same path close --shutdown uses, so open orchestration names no platform.
72f20d3 to
17eafaa
Compare
Live run: failed and interrupted cold opens on a dedicated AVDHead
{
"success": false,
"error": {
"code": "APP_NOT_INSTALLED",
"message": "No package found matching \"com.example.not.installed.app\"",
"details": {
"package": "com.example.not.installed.app",
"failedOpenEmulatorCleanup": "stopped",
"dispatched": "unknown"
}
}
}Limits: for run B the evidence is the observed process exit and the empty session list; I found no daemon diagnostic line for the canceled case in the state dir, so the outcome label for that path is not shown here. The AVD boots from a Quick Boot snapshot (about 5 s), so the interrupt window is short. The isolated daemon was stopped after the runs. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 finding moved to a new line on 17eafaa. The verdict and the full list are in the summary comment.
|
Reviewed 6cd7300: the change is close, but one regression and one help-text gap need fixing before merge. The cleanup in session-open-launch-cleanup.ts:107 asks only whether a session under this open's name owns the boot. The post-boot steps can also fail because another owner holds the new serial: a session in this daemon (session-open-execution.ts:550) or a device claim from another daemon or workspace (session-open-execution.ts:563-566, DEVICE_IN_USE). Both return a response, so the open stops the launch by pid. Open A boots the AVD under the AVD-name lock. Open B targets emulator-5554 once adb lists it, under a different lock key, and publishes a session or claim. A then hits the conflict and kills the emulator B is using. Before this PR, A failed with DEVICE_IN_USE and B kept its device, so this breaks the PR's own rule and is a regression. The window is short, but the route is real and has no test. Could the rule be: the open stops its launch only when no session or claim other than its own holds the device? The new help sentence in app.ts:222 says any open that fails after launching a stopped emulator stops it. Head 6cd7300 narrowed commands.md to failures after the boot completes, so a boot that times out or fails before ready leaves the emulator running (tracked in #4847). The CLI help has no such carve-out, so an agent reading Not blocking, take or leave: The inline thread on the pid and start-time comparison is fixed at this head (#4842 (comment)). The thread on a boot that throws after launch no longer applies, because commands.md now states that carve-out and #4847 tracks it; the help gap above is the remaining part (#4842 (comment)). The required live evidence is in the author's comment at 17eafaa; this head differs only by one docs line. Not verified here: the live runs, and the race above, which comes from reading the code. The SIGINT-during-boot run exercises the existing abort rollback, not the new post-boot cancel branch, which only the routed unit test at session-open-failed-boot.test.ts:293 covers. Not verified here: the 3-second stop bound. Checks are still running on this head, and there are no conflicts. Before merge, the device-in-use case needs a fix with a routed test, the help text needs the carve-out, and the checks need to finish green. |
This comment has been minimized.
This comment has been minimized.
A failed cold open stopped its launch whenever no session under its own name owned the boot, so an open refused with DEVICE_IN_USE — a session in this daemon holding the booted serial, or a claim from another workspace or daemon — killed the emulator that other owner had just taken (#4764 review). The cleanup now asks the same authority acquisition uses: the device's session, plus inspectDeviceClaimAcquisition for this open's own session and workspace. Only a conflict keeps the launch; this open's own claim answers held and settles nothing. The kept launch is reported as kept_running with the typed failedOpenEmulatorCleanupReason device-in-use from the contracts table. The open help states the boot carve-out commands.md already carries: the stop applies after the emulator finished booting, and a boot that timed out or failed before ready leaves it running. The Android stop keeps one escalation path, and the comment budgets state their constraint.
|
Round 2 folded in — commit 1. Session / claim conflict must keep the launch (blocking). 2. 3. Stop path deduped. Validation this round: typecheck, layering guard (R89 quiet), oxlint, |
Live run repeated at
|
| Run | Result |
|---|---|
Cold open com.example.not.installed.app --platform android --device agent-device-4539-live --json |
exit 1 in 8.3 s, APP_NOT_INSTALLED, details.failedOpenEmulatorCleanup: "stopped"; no -avd agent-device-4539-live process right after the command returned |
So the ownership check added in this head (no other session or claim holds the device) still lets the open stop its own launch. The device-in-use route is covered by the two routed tests only; I did not stage two racing opens on a live device. The PR body line that says the live runs are still owed is out of date: they are in the linked comment and here.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 4e9d7e0. The verdict and the full list are in the summary comment.
This comment has been minimized.
This comment has been minimized.
|
One high-priority defect remains at 8146622: a failed cold open can still stop an emulator that a second daemon already owns. The three earlier findings from #4842 (comment) are fixed at this commit. A cold open can clear its claim on a preparation failure (session-open-execution.ts:591-593, :648-650). Cleanup then inspects the booted serial and finds no claim. A second daemon can acquire that serial (device-claims.ts:224-228) and publish its claim (:432) before the first daemon signals the process. The inspection at session-open-launch-cleanup.ts:154 takes no host-global claim lock. The signal path also awaits a PID identity read before SIGTERM (host-process.ts:807-812). The emulator is still the same process, so the identity check permits the stop. The failed open can then terminate an emulator that another daemon owns and is opening. The merge base left that emulator running. The final claim check and the bounded process stop should both run under the same per-device claim lock that acquisition uses. A foreign claim must be preserved, and so must the original open error. Could daemon-contracts own a callback that runs only while the per-device claim lock proves the device has no conflicting owner, with session-open-launch-cleanup owning the stop and its outcome? The largest helper, stopUnownedLaunch, has no full duplicate. It reuses the existing claim inspection and process stop. Its in-daemon holder check repeats findSessionHoldingDevice in open-device-contention-wait.ts:129-136. The three earlier inline threads are fixed at this commit and can be resolved: the pid and start-time comparison (#4842 (comment)), the help text carve-out (#4842 (comment)), and the reassigned-pid doc comments (#4842 (comment)). CI is green: 15 checks, none failing, on 8146622. There are no conflicts. The device-in-use branch is a race between two opens and was not run live. Not verified here: the tests were not run locally, and the earlier live evidence at 17eafaa covers the stop route, which this change leaves unchanged. Not verified here: what inspectDeviceClaimAcquisition does on every I/O error. Once the claim-lock fix lands and CI stays green, nothing else blocks merge. |
A failed open read the device's owner and then signalled the process it had booted, so an acquisition that took the device in between had its emulator stopped (#4764 review). The final ownership answer and the bounded stop now run as one exclusion under the per-device claim lock that `acquireDeviceClaim` writes a claim under. The lock is taken without waiting: a lock this process cannot take says somebody is claiming the device right now, which is the same answer a claim that refuses this open gives, so the launch is kept and reported as device-in-use. `withDeviceClaimLockHeld` owns that take-without-wait in the claim store, beside the lock acquisition already uses, and reports ran or conflict.
|
Fixed at The helper (daemon-contracts owns it). The stop route. After the identity, policy and published-session answers, the cleanup re-asks the claim question under the lock and only its answer permits the stop. The lock is held for exactly the re-check plus the bounded stop (TERM, then KILL, ≤3 s), nothing else.
On your open question — what Tests. Validation at this head: |
Live run repeated at
|
| Run | Result |
|---|---|
Cold open com.example.not.installed.app --platform android --device agent-device-4539-live --json |
exit 1 in 8.2 s, APP_NOT_INSTALLED, details.failedOpenEmulatorCleanup: "stopped"; no -avd agent-device-4539-live process right after the command returned |
So with the final check and the stop now under the per-device claim lock, the open still takes the lock and stops its own launch. The conflict branches (device-in-use, lock held by another owner) are covered by the routed and claim-store tests only.
This comment has been minimized.
This comment has been minimized.
|
Most of the earlier review (#4842 (comment)) is fixed at f988585: a failed open now stops the emulator it booted, and the live run shows it. One docs finding remains. The new open help at https://github.com/callstack/agent-device/blob/f988585/packages/command-surface/src/management/app.ts#L222 says an open that fails after its own emulator finishes booting stops that emulator within 3 seconds. When the daemon policy denies device-shutdown, the router sets deviceShutdownDenied (request-router.ts:200-201) and session-open-launch-cleanup.ts:108-113 leaves the emulator running and reports kept_running with daemon-policy-denied. The routed test at session-open-failed-boot.test.ts:239-259 expects zero stops. A caller who reads the help can believe the emulator is stopped when the daemon kept it on purpose. Please word the help as an attempt to stop an unowned launch, and point callers to failedOpenEmulatorCleanup for the confirmed outcome and the kept-running reason. Could device-claims.ts accept the booted device for the no-wait claim-lock operation and derive the canonical key there? Then the claim owner would control the mapping that must agree with acquisition. The store would still own the lock mechanics, and session-open-launch-cleanup.ts would still own the stop and its reported outcome. The three earlier inline threads no longer apply at this commit, so they can be resolved: pid and start-time comparison is unchanged by this delta (#4842 (comment)), the help-text carve-out was fixed in 6cd7300 (#4842 (comment)), and the reassigned-pid comments were fixed in 8146622 (#4842 (comment)). Not verified here: tests were not run locally, and the held-lock branch (a two-daemon race) was not run live. The unit test with a lock held by another live pid covers that branch, and the live run at f988585 is the author report. Smoke Tests (macos) and one other check are still running on f988585, and all other checks are green. The change only touches the failure branch of an Android cold open that launched an emulator, so a macOS smoke run that never fails such an open does not reach it. No conflicts are known. After the help fix, the remaining step before merge is for the running checks to finish green. |
|
Reply to the review at f988585 (#4842 (comment)). Head is now Help text. Could The three inline threads named in the review are resolved. |
Apex Sentinel · ✅ Approve · review of
|
| 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.
|
The PR is ready at e8d8095. The help text now describes the stop as an attempt and points to failedOpenEmulatorCleanup for the outcome, and every kept-running case it lists matches the code at that commit. CI is green (15 checks, none failing), and there are no conflicts. Not blocking, and fine to take or leave: the help sentence at https://github.com/callstack/agent-device/blob/e8d8095/packages/command-surface/src/management/app.ts#L222 lists the cases where the emulator keeps running, but a fifth case exists (the launch start time could not be read, reason no-process-identity); adding it would match commands.md, and the help already points to failedOpenEmulatorCleanupReason for the reason. Not verified here: a live device run for this change, which only edits help text; the live cleanup evidence sits in earlier PR comments, and the device-in-use route is covered by routed and store tests only, as the PR body states. |
* fix(open): stop the emulator an open booted when the open fails An open that boots a stopped Android emulator and then ends without publishing a session left that emulator running with nothing to own it: no session recorded the boot, so no later close ever learned to stop it (#4764). The open now stops the launch it caused when its own steps end without a session, whether they return a failure, throw, or report the request canceled, and reports the result on that open's own error details as failedOpenEmulatorCleanup. A host that refuses the stop itself is treated as an unconfirmed stop: the open's own error stays the reported error either way. Only a launch this open caused is stopped. The readiness runtime reports the process it started, and reports nothing at all when the device was already running, so a prebooted emulator is never mistaken for this open's launch and no serial-based process probe is added. A launch whose start time could not be read keeps running with one diagnostic naming the step. When the daemon's policy denies device-shutdown nothing is signaled and the reason rides the error (ADR 0029 amended). The stop goes through the launched-process owner the root already composes, on the same path close --shutdown uses, so open orchestration names no platform. * docs(commands): state that a failed boot is outside the failed-open stop * fix(open): keep the launch when another owner holds the booted device A failed cold open stopped its launch whenever no session under its own name owned the boot, so an open refused with DEVICE_IN_USE — a session in this daemon holding the booted serial, or a claim from another workspace or daemon — killed the emulator that other owner had just taken (#4764 review). The cleanup now asks the same authority acquisition uses: the device's session, plus inspectDeviceClaimAcquisition for this open's own session and workspace. Only a conflict keeps the launch; this open's own claim answers held and settles nothing. The kept launch is reported as kept_running with the typed failedOpenEmulatorCleanupReason device-in-use from the contracts table. The open help states the boot carve-out commands.md already carries: the stop applies after the emulator finished booting, and a boot that timed out or failed before ready leaves it running. The Android stop keeps one escalation path, and the comment budgets state their constraint. * docs(device-boot): say a replaced launch answers stopped, as host-kit reports it * fix(open): decide the failed-open stop under the device claim lock A failed open read the device's owner and then signalled the process it had booted, so an acquisition that took the device in between had its emulator stopped (#4764 review). The final ownership answer and the bounded stop now run as one exclusion under the per-device claim lock that `acquireDeviceClaim` writes a claim under. The lock is taken without waiting: a lock this process cannot take says somebody is claiming the device right now, which is the same answer a claim that refuses this open gives, so the launch is kept and reported as device-in-use. `withDeviceClaimLockHeld` owns that take-without-wait in the claim store, beside the lock acquisition already uses, and reports ran or conflict. * docs(open): word the failed-open stop as an attempt and point to its reported outcome
* fix(open): stop the emulator an open booted when the open fails An open that boots a stopped Android emulator and then ends without publishing a session left that emulator running with nothing to own it: no session recorded the boot, so no later close ever learned to stop it (#4764). The open now stops the launch it caused when its own steps end without a session, whether they return a failure, throw, or report the request canceled, and reports the result on that open's own error details as failedOpenEmulatorCleanup. A host that refuses the stop itself is treated as an unconfirmed stop: the open's own error stays the reported error either way. Only a launch this open caused is stopped. The readiness runtime reports the process it started, and reports nothing at all when the device was already running, so a prebooted emulator is never mistaken for this open's launch and no serial-based process probe is added. A launch whose start time could not be read keeps running with one diagnostic naming the step. When the daemon's policy denies device-shutdown nothing is signaled and the reason rides the error (ADR 0029 amended). The stop goes through the launched-process owner the root already composes, on the same path close --shutdown uses, so open orchestration names no platform. * docs(commands): state that a failed boot is outside the failed-open stop * fix(open): keep the launch when another owner holds the booted device A failed cold open stopped its launch whenever no session under its own name owned the boot, so an open refused with DEVICE_IN_USE — a session in this daemon holding the booted serial, or a claim from another workspace or daemon — killed the emulator that other owner had just taken (#4764 review). The cleanup now asks the same authority acquisition uses: the device's session, plus inspectDeviceClaimAcquisition for this open's own session and workspace. Only a conflict keeps the launch; this open's own claim answers held and settles nothing. The kept launch is reported as kept_running with the typed failedOpenEmulatorCleanupReason device-in-use from the contracts table. The open help states the boot carve-out commands.md already carries: the stop applies after the emulator finished booting, and a boot that timed out or failed before ready leaves it running. The Android stop keeps one escalation path, and the comment budgets state their constraint. * docs(device-boot): say a replaced launch answers stopped, as host-kit reports it * fix(open): decide the failed-open stop under the device claim lock A failed open read the device's owner and then signalled the process it had booted, so an acquisition that took the device in between had its emulator stopped (#4764 review). The final ownership answer and the bounded stop now run as one exclusion under the per-device claim lock that `acquireDeviceClaim` writes a claim under. The lock is taken without waiting: a lock this process cannot take says somebody is claiming the device right now, which is the same answer a claim that refuses this open gives, so the launch is kept and reported as device-in-use. `withDeviceClaimLockHeld` owns that take-without-wait in the claim store, beside the lock acquisition already uses, and reports ran or conflict. * docs(open): word the failed-open stop as an attempt and point to its reported outcome
…#4991) * fix(android): check ownership before a failed boot stops its emulator #4863 stops the emulator a cold boot launched when that boot fails, and the stop is gated only by the `device-shutdown` policy. A second `open` that binds to the booting `emulator-NNNN` becomes that emulator's owner, and the first open's later failure stopped it out from under that owner. The daemon's failed-open cleanup (#4842) already refuses to stop a launch somebody else holds; the readiness stop had no such answer. Readiness now asks whoever owns the boot before its stop signals the launched pid. The daemon answers from the same session and claim state its cleanup reads, under that device's claim lock, so a claim being written right now answers as ownership too. A held device is never signaled, whichever reason failed the boot, and an answer that cannot be reached keeps the launch. A route that opens no session, such as `boot`, has no ownership to ask about and keeps following the boot's own rule. Keeping a launch after its own failure is now the boot wait's own knowledge rather than an undocumented `bootBudgetSpent` field on the error's details. Taking the optional notes from #4863's final review: ADR 0029's amendment now says the emulator host gates its own `terminate` and the launched-process stop uses the request-level flag, and a composition test pins the shutdown gate into the composed emulator host's `terminate`. * fix(android): record an unanswered ownership question The readiness stop already keeps a launch when nobody can say who owns the emulator, but it swallows the reason. It now emits android_emulator_launch_ownership_unanswered, in the same style as the terminate refusal beside it, and the open's help, the command docs and ADR 0029 say that an unreachable answer stops nothing. The failed-open cleanup asks the session half of the same question through holdsDeviceInAnotherSession, so both stops read ownership one way. * fix(android): keep a launch whose boot never resolved a serial Sessions and device claims are keyed under the emulator's serial, so an AVD name is not an address anything can be held under. Asking ownership about a boot that never resolved a serial could therefore only answer "not held", which is a guess at somebody else's emulator: the guard was vacuous exactly when the boot failed before discovery named the serial, and the stop killed the emulator a concurrent open had already taken. Readiness now treats that answer as unknown and keeps the launch, the same way it treats an unreachable one, and records android_emulator_launch_ownership_unanswered with the reason. No re-resolution is added: whoever resolves the serial is the open that binds to it. The daemon test pinned the vacuous false answer for an AVD; it asks about a serial nobody holds instead, which is the other real answer. * docs(4867): scope the ownership answer to the open that launched the boot Only `open` reads the session and claim state that answers ownership, and only an `open` publishes the session a held device would belong to. `boot`, app deployment, `apps`, `appstate`, `push` and `doctor` keep the boot's own rule and stop their launch; covering every route from the daemon's readiness composition is filed as a follow-up (#4867 comment r4660185881 finding). The commands doc sentence and ADR 0029 said the whole boot-time rule, including `boot` and deployment, stops nothing when the device is held. They now state the scope: only `open` asks who holds the emulator. * fix(android): stop a launch whose boot failed before a serial exists Ownership is recorded under the emulator's serial, so a boot that failed before discovery named one has nothing to ask about. Settling that address would take one more inventory pass, and every inventory probe runs under the request's own signal, which a canceled request has already aborted: the pass could only fail. Ask ownership only of a boot that resolved a serial, and let the earlier window stop its launch as base did, so no emulator is left running with no session to own it (#4863). Issue #4993 tracks giving that window, and every other daemon route that can stop a failed boot's launch, an ownership answer from state that needs no inventory. Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com> * fix(android): keep the ownership diagnostic's reason a code android_emulator_launch_ownership_unanswered recorded the ownership caller's error message as its `reason`. Report the typed reason code `ownership-query-failed` there and carry the message as `error`, so a reader of the diagnostic log groups unanswered ownership questions by why, not by the text each caller happened to throw. Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com> --------- Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com>
* fix(open): stop the emulator an open booted when the open fails An open that boots a stopped Android emulator and then ends without publishing a session left that emulator running with nothing to own it: no session recorded the boot, so no later close ever learned to stop it (#4764). The open now stops the launch it caused when its own steps end without a session, whether they return a failure, throw, or report the request canceled, and reports the result on that open's own error details as failedOpenEmulatorCleanup. A host that refuses the stop itself is treated as an unconfirmed stop: the open's own error stays the reported error either way. Only a launch this open caused is stopped. The readiness runtime reports the process it started, and reports nothing at all when the device was already running, so a prebooted emulator is never mistaken for this open's launch and no serial-based process probe is added. A launch whose start time could not be read keeps running with one diagnostic naming the step. When the daemon's policy denies device-shutdown nothing is signaled and the reason rides the error (ADR 0029 amended). The stop goes through the launched-process owner the root already composes, on the same path close --shutdown uses, so open orchestration names no platform. * docs(commands): state that a failed boot is outside the failed-open stop * fix(open): keep the launch when another owner holds the booted device A failed cold open stopped its launch whenever no session under its own name owned the boot, so an open refused with DEVICE_IN_USE — a session in this daemon holding the booted serial, or a claim from another workspace or daemon — killed the emulator that other owner had just taken (#4764 review). The cleanup now asks the same authority acquisition uses: the device's session, plus inspectDeviceClaimAcquisition for this open's own session and workspace. Only a conflict keeps the launch; this open's own claim answers held and settles nothing. The kept launch is reported as kept_running with the typed failedOpenEmulatorCleanupReason device-in-use from the contracts table. The open help states the boot carve-out commands.md already carries: the stop applies after the emulator finished booting, and a boot that timed out or failed before ready leaves it running. The Android stop keeps one escalation path, and the comment budgets state their constraint. * docs(device-boot): say a replaced launch answers stopped, as host-kit reports it * fix(open): decide the failed-open stop under the device claim lock A failed open read the device's owner and then signalled the process it had booted, so an acquisition that took the device in between had its emulator stopped (#4764 review). The final ownership answer and the bounded stop now run as one exclusion under the per-device claim lock that `acquireDeviceClaim` writes a claim under. The lock is taken without waiting: a lock this process cannot take says somebody is claiming the device right now, which is the same answer a claim that refuses this open gives, so the launch is kept and reported as device-in-use. `withDeviceClaimLockHeld` owns that take-without-wait in the claim store, beside the lock acquisition already uses, and reports ran or conflict. * docs(open): word the failed-open stop as an attempt and point to its reported outcome
…#4991) * fix(android): check ownership before a failed boot stops its emulator stop is gated only by the `device-shutdown` policy. A second `open` that binds to the booting `emulator-NNNN` becomes that emulator's owner, and the first open's later failure stopped it out from under that owner. The daemon's failed-open cleanup (#4842) already refuses to stop a launch somebody else holds; the readiness stop had no such answer. Readiness now asks whoever owns the boot before its stop signals the launched pid. The daemon answers from the same session and claim state its cleanup reads, under that device's claim lock, so a claim being written right now answers as ownership too. A held device is never signaled, whichever reason failed the boot, and an answer that cannot be reached keeps the launch. A route that opens no session, such as `boot`, has no ownership to ask about and keeps following the boot's own rule. Keeping a launch after its own failure is now the boot wait's own knowledge rather than an undocumented `bootBudgetSpent` field on the error's details. Taking the optional notes from #4863's final review: ADR 0029's amendment now says the emulator host gates its own `terminate` and the launched-process stop uses the request-level flag, and a composition test pins the shutdown gate into the composed emulator host's `terminate`. * fix(android): record an unanswered ownership question The readiness stop already keeps a launch when nobody can say who owns the emulator, but it swallows the reason. It now emits android_emulator_launch_ownership_unanswered, in the same style as the terminate refusal beside it, and the open's help, the command docs and ADR 0029 say that an unreachable answer stops nothing. The failed-open cleanup asks the session half of the same question through holdsDeviceInAnotherSession, so both stops read ownership one way. * fix(android): keep a launch whose boot never resolved a serial Sessions and device claims are keyed under the emulator's serial, so an AVD name is not an address anything can be held under. Asking ownership about a boot that never resolved a serial could therefore only answer "not held", which is a guess at somebody else's emulator: the guard was vacuous exactly when the boot failed before discovery named the serial, and the stop killed the emulator a concurrent open had already taken. Readiness now treats that answer as unknown and keeps the launch, the same way it treats an unreachable one, and records android_emulator_launch_ownership_unanswered with the reason. No re-resolution is added: whoever resolves the serial is the open that binds to it. The daemon test pinned the vacuous false answer for an AVD; it asks about a serial nobody holds instead, which is the other real answer. * docs(4867): scope the ownership answer to the open that launched the boot Only `open` reads the session and claim state that answers ownership, and only an `open` publishes the session a held device would belong to. `boot`, app deployment, `apps`, `appstate`, `push` and `doctor` keep the boot's own rule and stop their launch; covering every route from the daemon's readiness composition is filed as a follow-up (#4867 comment r4660185881 finding). The commands doc sentence and ADR 0029 said the whole boot-time rule, including `boot` and deployment, stops nothing when the device is held. They now state the scope: only `open` asks who holds the emulator. * fix(android): stop a launch whose boot failed before a serial exists Ownership is recorded under the emulator's serial, so a boot that failed before discovery named one has nothing to ask about. Settling that address would take one more inventory pass, and every inventory probe runs under the request's own signal, which a canceled request has already aborted: the pass could only fail. Ask ownership only of a boot that resolved a serial, and let the earlier window stop its launch as base did, so no emulator is left running with no session to own it (#4863). Issue #4993 tracks giving that window, and every other daemon route that can stop a failed boot's launch, an ownership answer from state that needs no inventory. Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com> * fix(android): keep the ownership diagnostic's reason a code android_emulator_launch_ownership_unanswered recorded the ownership caller's error message as its `reason`. Report the typed reason code `ownership-query-failed` there and carry the message as `error`, so a reader of the diagnostic log groups unanswered ownership questions by why, not by the text each caller happened to throw. Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com> --------- Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com>
…stack#4842) * fix(open): stop the emulator an open booted when the open fails An open that boots a stopped Android emulator and then ends without publishing a session left that emulator running with nothing to own it: no session recorded the boot, so no later close ever learned to stop it (callstack#4764). The open now stops the launch it caused when its own steps end without a session, whether they return a failure, throw, or report the request canceled, and reports the result on that open's own error details as failedOpenEmulatorCleanup. A host that refuses the stop itself is treated as an unconfirmed stop: the open's own error stays the reported error either way. Only a launch this open caused is stopped. The readiness runtime reports the process it started, and reports nothing at all when the device was already running, so a prebooted emulator is never mistaken for this open's launch and no serial-based process probe is added. A launch whose start time could not be read keeps running with one diagnostic naming the step. When the daemon's policy denies device-shutdown nothing is signaled and the reason rides the error (ADR 0029 amended). The stop goes through the launched-process owner the root already composes, on the same path close --shutdown uses, so open orchestration names no platform. * docs(commands): state that a failed boot is outside the failed-open stop * fix(open): keep the launch when another owner holds the booted device A failed cold open stopped its launch whenever no session under its own name owned the boot, so an open refused with DEVICE_IN_USE — a session in this daemon holding the booted serial, or a claim from another workspace or daemon — killed the emulator that other owner had just taken (callstack#4764 review). The cleanup now asks the same authority acquisition uses: the device's session, plus inspectDeviceClaimAcquisition for this open's own session and workspace. Only a conflict keeps the launch; this open's own claim answers held and settles nothing. The kept launch is reported as kept_running with the typed failedOpenEmulatorCleanupReason device-in-use from the contracts table. The open help states the boot carve-out commands.md already carries: the stop applies after the emulator finished booting, and a boot that timed out or failed before ready leaves it running. The Android stop keeps one escalation path, and the comment budgets state their constraint. * docs(device-boot): say a replaced launch answers stopped, as host-kit reports it * fix(open): decide the failed-open stop under the device claim lock A failed open read the device's owner and then signalled the process it had booted, so an acquisition that took the device in between had its emulator stopped (callstack#4764 review). The final ownership answer and the bounded stop now run as one exclusion under the per-device claim lock that `acquireDeviceClaim` writes a claim under. The lock is taken without waiting: a lock this process cannot take says somebody is claiming the device right now, which is the same answer a claim that refuses this open gives, so the launch is kept and reported as device-in-use. `withDeviceClaimLockHeld` owns that take-without-wait in the claim store, beside the lock acquisition already uses, and reports ran or conflict. * docs(open): word the failed-open stop as an attempt and point to its reported outcome
…callstack#4991) * fix(android): check ownership before a failed boot stops its emulator stop is gated only by the `device-shutdown` policy. A second `open` that binds to the booting `emulator-NNNN` becomes that emulator's owner, and the first open's later failure stopped it out from under that owner. The daemon's failed-open cleanup (callstack#4842) already refuses to stop a launch somebody else holds; the readiness stop had no such answer. Readiness now asks whoever owns the boot before its stop signals the launched pid. The daemon answers from the same session and claim state its cleanup reads, under that device's claim lock, so a claim being written right now answers as ownership too. A held device is never signaled, whichever reason failed the boot, and an answer that cannot be reached keeps the launch. A route that opens no session, such as `boot`, has no ownership to ask about and keeps following the boot's own rule. Keeping a launch after its own failure is now the boot wait's own knowledge rather than an undocumented `bootBudgetSpent` field on the error's details. Taking the optional notes from callstack#4863's final review: ADR 0029's amendment now says the emulator host gates its own `terminate` and the launched-process stop uses the request-level flag, and a composition test pins the shutdown gate into the composed emulator host's `terminate`. * fix(android): record an unanswered ownership question The readiness stop already keeps a launch when nobody can say who owns the emulator, but it swallows the reason. It now emits android_emulator_launch_ownership_unanswered, in the same style as the terminate refusal beside it, and the open's help, the command docs and ADR 0029 say that an unreachable answer stops nothing. The failed-open cleanup asks the session half of the same question through holdsDeviceInAnotherSession, so both stops read ownership one way. * fix(android): keep a launch whose boot never resolved a serial Sessions and device claims are keyed under the emulator's serial, so an AVD name is not an address anything can be held under. Asking ownership about a boot that never resolved a serial could therefore only answer "not held", which is a guess at somebody else's emulator: the guard was vacuous exactly when the boot failed before discovery named the serial, and the stop killed the emulator a concurrent open had already taken. Readiness now treats that answer as unknown and keeps the launch, the same way it treats an unreachable one, and records android_emulator_launch_ownership_unanswered with the reason. No re-resolution is added: whoever resolves the serial is the open that binds to it. The daemon test pinned the vacuous false answer for an AVD; it asks about a serial nobody holds instead, which is the other real answer. * docs(4867): scope the ownership answer to the open that launched the boot Only `open` reads the session and claim state that answers ownership, and only an `open` publishes the session a held device would belong to. `boot`, app deployment, `apps`, `appstate`, `push` and `doctor` keep the boot's own rule and stop their launch; covering every route from the daemon's readiness composition is filed as a follow-up (callstack#4867 comment r4660185881 finding). The commands doc sentence and ADR 0029 said the whole boot-time rule, including `boot` and deployment, stops nothing when the device is held. They now state the scope: only `open` asks who holds the emulator. * fix(android): stop a launch whose boot failed before a serial exists Ownership is recorded under the emulator's serial, so a boot that failed before discovery named one has nothing to ask about. Settling that address would take one more inventory pass, and every inventory probe runs under the request's own signal, which a canceled request has already aborted: the pass could only fail. Ask ownership only of a boot that resolved a serial, and let the earlier window stop its launch as base did, so no emulator is left running with no session to own it (callstack#4863). Issue callstack#4993 tracks giving that window, and every other daemon route that can stop a failed boot's launch, an ownership answer from state that needs no inventory. Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com> * fix(android): keep the ownership diagnostic's reason a code android_emulator_launch_ownership_unanswered recorded the ownership caller's error message as its `reason`. Report the typed reason code `ownership-query-failed` there and carry the message as `error`, so a reader of the diagnostic log groups unanswered ownership questions by why, not by the text each caller happened to throw. Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com> --------- Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com>
* fix(open): stop the emulator an open booted when the open fails An open that boots a stopped Android emulator and then ends without publishing a session left that emulator running with nothing to own it: no session recorded the boot, so no later close ever learned to stop it (#4764). The open now stops the launch it caused when its own steps end without a session, whether they return a failure, throw, or report the request canceled, and reports the result on that open's own error details as failedOpenEmulatorCleanup. A host that refuses the stop itself is treated as an unconfirmed stop: the open's own error stays the reported error either way. Only a launch this open caused is stopped. The readiness runtime reports the process it started, and reports nothing at all when the device was already running, so a prebooted emulator is never mistaken for this open's launch and no serial-based process probe is added. A launch whose start time could not be read keeps running with one diagnostic naming the step. When the daemon's policy denies device-shutdown nothing is signaled and the reason rides the error (ADR 0029 amended). The stop goes through the launched-process owner the root already composes, on the same path close --shutdown uses, so open orchestration names no platform. * docs(commands): state that a failed boot is outside the failed-open stop * fix(open): keep the launch when another owner holds the booted device A failed cold open stopped its launch whenever no session under its own name owned the boot, so an open refused with DEVICE_IN_USE — a session in this daemon holding the booted serial, or a claim from another workspace or daemon — killed the emulator that other owner had just taken (#4764 review). The cleanup now asks the same authority acquisition uses: the device's session, plus inspectDeviceClaimAcquisition for this open's own session and workspace. Only a conflict keeps the launch; this open's own claim answers held and settles nothing. The kept launch is reported as kept_running with the typed failedOpenEmulatorCleanupReason device-in-use from the contracts table. The open help states the boot carve-out commands.md already carries: the stop applies after the emulator finished booting, and a boot that timed out or failed before ready leaves it running. The Android stop keeps one escalation path, and the comment budgets state their constraint. * docs(device-boot): say a replaced launch answers stopped, as host-kit reports it * fix(open): decide the failed-open stop under the device claim lock A failed open read the device's owner and then signalled the process it had booted, so an acquisition that took the device in between had its emulator stopped (#4764 review). The final ownership answer and the bounded stop now run as one exclusion under the per-device claim lock that `acquireDeviceClaim` writes a claim under. The lock is taken without waiting: a lock this process cannot take says somebody is claiming the device right now, which is the same answer a claim that refuses this open gives, so the launch is kept and reported as device-in-use. `withDeviceClaimLockHeld` owns that take-without-wait in the claim store, beside the lock acquisition already uses, and reports ran or conflict. * docs(open): word the failed-open stop as an attempt and point to its reported outcome
…#4991) * fix(android): check ownership before a failed boot stops its emulator stop is gated only by the `device-shutdown` policy. A second `open` that binds to the booting `emulator-NNNN` becomes that emulator's owner, and the first open's later failure stopped it out from under that owner. The daemon's failed-open cleanup (#4842) already refuses to stop a launch somebody else holds; the readiness stop had no such answer. Readiness now asks whoever owns the boot before its stop signals the launched pid. The daemon answers from the same session and claim state its cleanup reads, under that device's claim lock, so a claim being written right now answers as ownership too. A held device is never signaled, whichever reason failed the boot, and an answer that cannot be reached keeps the launch. A route that opens no session, such as `boot`, has no ownership to ask about and keeps following the boot's own rule. Keeping a launch after its own failure is now the boot wait's own knowledge rather than an undocumented `bootBudgetSpent` field on the error's details. Taking the optional notes from #4863's final review: ADR 0029's amendment now says the emulator host gates its own `terminate` and the launched-process stop uses the request-level flag, and a composition test pins the shutdown gate into the composed emulator host's `terminate`. * fix(android): record an unanswered ownership question The readiness stop already keeps a launch when nobody can say who owns the emulator, but it swallows the reason. It now emits android_emulator_launch_ownership_unanswered, in the same style as the terminate refusal beside it, and the open's help, the command docs and ADR 0029 say that an unreachable answer stops nothing. The failed-open cleanup asks the session half of the same question through holdsDeviceInAnotherSession, so both stops read ownership one way. * fix(android): keep a launch whose boot never resolved a serial Sessions and device claims are keyed under the emulator's serial, so an AVD name is not an address anything can be held under. Asking ownership about a boot that never resolved a serial could therefore only answer "not held", which is a guess at somebody else's emulator: the guard was vacuous exactly when the boot failed before discovery named the serial, and the stop killed the emulator a concurrent open had already taken. Readiness now treats that answer as unknown and keeps the launch, the same way it treats an unreachable one, and records android_emulator_launch_ownership_unanswered with the reason. No re-resolution is added: whoever resolves the serial is the open that binds to it. The daemon test pinned the vacuous false answer for an AVD; it asks about a serial nobody holds instead, which is the other real answer. * docs(4867): scope the ownership answer to the open that launched the boot Only `open` reads the session and claim state that answers ownership, and only an `open` publishes the session a held device would belong to. `boot`, app deployment, `apps`, `appstate`, `push` and `doctor` keep the boot's own rule and stop their launch; covering every route from the daemon's readiness composition is filed as a follow-up (#4867 comment r4660185881 finding). The commands doc sentence and ADR 0029 said the whole boot-time rule, including `boot` and deployment, stops nothing when the device is held. They now state the scope: only `open` asks who holds the emulator. * fix(android): stop a launch whose boot failed before a serial exists Ownership is recorded under the emulator's serial, so a boot that failed before discovery named one has nothing to ask about. Settling that address would take one more inventory pass, and every inventory probe runs under the request's own signal, which a canceled request has already aborted: the pass could only fail. Ask ownership only of a boot that resolved a serial, and let the earlier window stop its launch as base did, so no emulator is left running with no session to own it (#4863). Issue #4993 tracks giving that window, and every other daemon route that can stop a failed boot's launch, an ownership answer from state that needs no inventory. Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com> * fix(android): keep the ownership diagnostic's reason a code android_emulator_launch_ownership_unanswered recorded the ownership caller's error message as its `reason`. Report the typed reason code `ownership-query-failed` there and carry the message as `error`, so a reader of the diagnostic log groups unanswered ownership questions by why, not by the text each caller happened to throw. Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com> --------- Co-authored-by: Apex powered by GPT-5.6 <noreply@callstack.com>
Summary
An
openthat boots a stopped Android emulator and then ends without publishing a session left that emulator running with nothing to own it: no session recorded the boot, so no latercloseever learned to stop it. The open now stops the launch it caused when its own remaining steps end with no published session, whether they return a failure, throw, or report the request canceled. A host that refuses the stop is treated as an unconfirmed stop; the open's own error stays the reported error either way. Fixes #4764.The stop uses the launched-process owner the root composes — the same path
close --shutdownconfirms through (#4815) — so open orchestration names no platform. Before stopping, the cleanup asks the same ownership authority acquisition uses: another session of this daemon holding the booted device, or a claim conflicting with this open's session and workspace, keeps the launch. The final ownership answer and the bounded stop run as one exclusion under the per-device claim lock that acquisition writes a claim under, so no owner can be acquired for the device in between; a lock this process cannot take keeps the launch too. ADR 0029 is amended for the denied-policy outcome.Before / after
Same cold open, failing after the boot:
COMMAND_FAILED: pm list features timed out, emulator left running, no session.error.details.failedOpenEmulatorCleanup:stopped,kept_runningwithfailedOpenEmulatorCleanupReason(device-in-use,daemon-policy-denied,no-process-identity), ornot_confirmed.An emulator that was already running reports nothing and is never stopped, because readiness reports a launch only for a boot it started. A launch whose start time could not be read is left running with one diagnostic — no serial-based process probe. An open that lost the booted device to another session or claim, or found the device being claimed at that moment, keeps that owner's emulator running and says
device-in-use. The rule covers failures after the boot completes; a boot that timed out or failed before ready leaves the emulator as it is (#4847).Validation
Head
f988585abc, baseorigin/0.22=db5f1225e3. Review rounds one to three folded in: cleanup stop is try/caught, ownership compares the full pid+start-time pair, a session/claim conflict keeps the launch and reportsdevice-in-usefrom the typed contracts table, the claim re-check and the stop share one acquisition of the per-device claim lock throughwithDeviceClaimLockHeld(daemon-contracts, no wait, typedran/conflict),findSessionHoldingDeviceis reused rather than repeated,openCLI help states the stop and its boot carve-out, ADR 0029 amended, docs link fixed, stop escalation shared and its budget comments reduced, routed cases for both conflict routes and the lock. Local:pnpm typecheck,pnpm check:layering(R89 quiet),pnpm format,fallow audit --base origin/0.22(no issues on 25 changed files), oxlint,check:production-exports,check:daemon-wire-compat(protocol unchanged, ledger updated by the tool),check:doc-links,check:doc-prose,check:mcp-metadata,check:command-docs+MCP surface (always-loaded 22519 / 22528 B), and the fullunit-corelane: 2159 files / 20823 tests. No localcheck:affectedunder host load — hosted CI validates the head.Live runs on a dedicated AVD: a cold open failing after the boot (
failedOpenEmulatorCleanup: "stopped", emulator process gone), a cold open interrupted during the boot, and a control are in #4842 (comment) (head17eafaaaba); the failing-after-boot run was repeated at4e9d7e0cb7in #4842 (comment). Thedevice-in-useroute and the claim-lock exclusion are covered by routed and store-level tests only, not run as a two-daemon race.