Repository navigation
feat(close): stop a simulator or emulator the session's own open booted - #4539
Conversation
Size Report
Startup median (7 runs, lower is better):
|
There was a problem hiding this comment.
All reported issues were addressed across 32 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 7dd1ac9. The verdict and the full list are in the summary comment.
|
CI is green at e5f7ab7 (16 checks, none failing), but the PR is a draft, so the device lanes were skipped and do not cover the Android or iOS lifecycle path. No conflicts. The code has two problems to fix before merge. The new sentence at website/docs/docs/sessions.md:130 says provider-owned devices are not stopped through --shutdown. On a provider session, The Android cold-open route has no live run. The route is bootStoppedLocalAndroidDevice, then markSelectionBootOccurred on the AVD selection, then the serial swap, then plain close with bootedByOpen. The PR body reports that Android cold open failed with DEVICE_NOT_FOUND for emulator-5554 and Pixel_7_CI, and the cause is not diagnosed. Whether the serial device reaches close with bootedByOpen and the emulator really stops is unproven. The iOS run used T3 client 0.21.31, so the head client and CLI warning delivery are not shown either, and the report paths in the PR body are not readable here. Please run the head-built CLI (pnpm build, then the node bin from this checkout with a fresh --state-dir): (1) with the AVD shut down and Not blocking, take or leave: the policy fact is carried per request in req.internal.shutdownCapabilityDenied and hand-copied into the replay cleanup request, while the close handler could read it from its daemon dependencies; the new client warnings pass-through (index.ts:270, index.ts:380, and serializeCloseResult) has no test, since deleting either line keeps every test green, so one client test with a fake transport would cover it; the doc comment at device-selection-resolver.ts:101 still says the boot event holds "once it succeeds", but it is now predicted before dispatch and session selections can claim it; and the cli-help.ts:132 rewrite drops "runners/daemons self-idle after 5 minutes; stale leases self-reclaim", which are unrelated to this change, so please keep them and shorten the new close sentence instead. Could the request-stamped policy flag become a daemon dependency instead? handleSessionCloseCommands would receive deviceShutdownDenied, derived once from the loaded DaemonPolicy where daemon-runtime.ts:218 already derives assertShutdownAllowed, and pass it to runSessionCloseTeardown, the way platformResourceCleanup is threaded. That would delete withShutdownPolicyDeniedFlag, the new isDaemonPolicyCapabilityDenied export path, DaemonRequestInternal.shutdownCapabilityDenied, the router stamp and the replay-cleanup copy, about 25 production lines, with no propagation invariant to keep. bootedByOpen and updateOpenDevice can stay as they are, and setting bootedByOpen on the publish draft would be a small extra simplification. No ADR change looks needed. On the other threads: the threads on boot ownership for reopens and on replay close scope are fixed at this head and can be resolved. These do not apply and can be resolved: skills/agent-device/SKILL.md:16 already limits --shutdown to a local simulator or emulator, and provider shutdown goes through session-close.ts:144-163; skills/android-emulator/SKILL.md:24 states the policy-denied case and scoping to a local emulator is correct; the publish-then-update thread has no reader between the two synchronous calls, so the draft change is only a simplification. The typed-reason thread on warnings still holds but is not blocking, because warnings: string[] is the existing contract convention. |
|
Addressed the source and documentation feedback in fcd2ec8.
I retained the existing display-warning convention; no consumer branches on warning prose. The nonblocking structured-warning suggestion remains deferred rather than being presented as fixed. Live evidence remains limited: the e5 T3-bound iOS daemon cases passed, but its old bound client omitted the warning; Android cold selection failed twice and that route stopped. The new fake-response tests prove current client/serializer projection, not fresh end-to-end device delivery. I have not used an unbound head CLI to bypass the required T3 route. This PR remains draft. |
There was a problem hiding this comment.
All reported issues were addressed across 43 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on fcd2ec8. The verdict and the full list are in the summary comment.
|
Thanks for the update. At fcd2ec8 the per-request policy marker is gone and reopen selections are now classified, so those two earlier findings are fixed. Two problems remain from the earlier review (#4539 (comment)), and one check fails. The Android cold-open route still has no live run, and the PR says there was no fresh device execution at this head. The route is Close help says plain close stops a device "your session booted", but only The Coverage gate fails because of this delta. Open review threads that still apply: #4539 (comment) (close help owner wording, same rule as above) and #4539 (comment) (commands.md provider shutdown). The second one needs a fix: commands.md:107 says provider-owned devices are never stopped this way, but I did not run tests; I judged this from the diff. The new router case in The branch now conflicts with its base 0.22, so please rebase. Before merge, fix the Coverage gate, attach the Android cold-open and close run, and align the close wording and the commands.md sentence. |
fcd2ec8 to
ebce87f
Compare
|
The code from the earlier review (fcd2ec8) is mostly fixed at ebce87f, but two items remain. The Coverage failure is repaired and all 18 checks pass. There are no conflicts. The close owner wording is fixed at The workflow help still over-states who owns the boot. cli-help-workflows.ts:32 and line 288 say plain close stops a simulator or emulator "your session booted". Only The live Android evidence is still missing. The route is session-open.ts:422: cold boot by AVD name, the serial swap, Not blocking, take or leave: Of the open inline threads, the help owner wording thread still applies, because I did not run tests. This review comes from the diff and the code at ebce87f, and the CI result comes from the check summary, not the per-job logs. I did not trace which Limrun lease kinds reach Before merge, please fix the two help lines and attach the Android cold-open to close runs on this head. |
|
Exact local affected admission passed at Command (one invocation):
Independent actual-owner source recheck: NO FINDINGS. Hosted at this head: 16 successful / 1 skipped / 1 neutral. These lanes are separate. Current-client warning rendering and supported cold Android lifecycle proof remain open; stopped device paths were not retried. No merge clearance. |
ebce87f to
8c24143
Compare
|
Published rebased A5 head8c241431f249ce4040fc0f32e5261bc771d9c4a0 on0.22root0081. Independent rebase preservation/prose recheck found no findings: all14patches equal, binary layer byte-identical, disjoint base/layer changes and automatic merge tree equals candidate. Prior actual-owner semantic review applies to unchanged A5 bytes; inaccurate narrative/device-status statements from the new report are excluded rather than treated as live proof. New exact affected admission ran ONCE: raw0,42 passed/25 skipped, all67 FAIL-OPEN checks retained, exactCommit=true,checkoutChanged=false. Direct pnpm11.17.0 frozen install/build0. Defaultorigin/mainD78/mergebase d38; actual0.22root0081 separately. Receipt UTC2026-11-14 17:16:43.404–17:24:34.924. Matching clean fingerprint b3d88311b7cc7f25311dd86d230253375dd990b452d6c609da915f813ccdfb71. ReceiptSHA1dc54abc9653d62201579ab383e4e756a46eea02454a13453db6051f07a4347b. Parent verified all87manifest hashes in evidence directory and archive and all52original/copy evidence files byte-identically, refs/results/pinnedsetup/finalindex. ArchiveSHA d971b2758fe86a9b52f47934ce59b8bbb6dd79323c8f655ced710c9fc5f5c5de, VERIFIED-UNSEALED. Initial read-only shell/controller errors were separate from actual gate execution; no rerun. No printed lock wait; actual wait unmeasured. New-head hosted checks remain owed. Current-client warning delivery and supported cold Android ownership live proof remain BLOCKED. Pixel7 twice DEVICE_NOT_FOUND and Pixel9 KO shutdown routes remain STOPPED; Pixel9 last known ON/unclaimed, no cleanup claim. No device actions or alternate route occurred. No merge/release clearance. |
|
Thanks for the update. The The close help still names the wrong owner. cli-help-workflows.ts:32 and The Android cold-open route is still covered only by unit fakes at session-open-execution.ts:443. That route boots by AVD name, swaps the name for an ADB serial, calls
If the cold open fails with I did not run tests or any device. CI state comes from the check summary, not the per-job logs. The patch is identical to the one in the earlier review, so I did not re-trace the close and open code beyond the owner reads and writes. On the inline threads: the one on |
8c24143 to
93b40d7
Compare
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 93b40d7. The verdict and the full list are in the summary comment.
|
Thanks for the update. At 93b40d7 the owner wording in help now says "this session's open booted" at all three sites, so that part of the earlier review (#4539 (comment)) is fixed. One item remains: there is still no live Android run. The Android cold-open route is covered only by unit fakes. Open boots by AVD name, swaps the name for an ADB serial, then Not blocking, take or leave: the claim-currency condition gates only the permitted branch (https://github.com/callstack/agent-device/blob/93b40d7/packages/daemon/src/sessions/session-lifecycle/internal/session-close-lifecycle-teardown.ts#L100), so a lost claim under a deny policy still warns that close would stop the device, which it would not; deciding claim currency once before both branches and deriving the warning and On the other open threads: the owner-wording thread (#4539 (comment)) is fixed at this head, and the resolved-benign thread on open-boot ownership (#4539 (comment)) needs nothing more, since this change touches only the close-side claim check. Two other threads do not apply and can be resolved: #4539 (comment) (on Darwin iOS the device is refreshed before reopen, and on Android the reopen re-mark is idempotent, so the proposed The only check not passing is a review gate that is holding open thread r4578158108. That thread does not apply, so the gate needs a waiver or a reply on that thread, not a code change. The other 17 checks pass. Before merge, please attach the three live Android runs above. |
|
This branch now conflicts with main at 93b40d7. Please rebase onto main and push, together with the live Android runs from the earlier review, and I will re-check the new head. |
93b40d7 to
0e19c8d
Compare
|
This follows up on the earlier review at 93b40d7 (#4539 (comment)). The rebase to 0e19c8d keeps the same logical patch, so the earlier trace of the open and close route still holds. One gap remains: the Android cold-open route has no live run. The route boots by AVD name, swaps the AVD name for an ADB serial, and records bootedByOpen in session-open-execution.ts:443. Close then needs the claim renewal at session-close-lifecycle-teardown.ts:105 to return 'renewed' for a claim written before that swap. Only unit fakes cover this. The PR body still lists Android cold-open, claim, implicit-stop and the current-client warning as live gaps, and the earlier Pixel 7 DEVICE_NOT_FOUND failure is still not explained. If the swap drops bootedByOpen, or the renewal reports 'lost', plain close leaves the emulator running with no data.shutdown and no warning. That is the #4162 failure on Android, and it would ship silently. Please run Of the other open threads, the Darwin iOS reopen thread does not apply. The device is refreshed before reopen on iOS, and the Android re-mark is idempotent (session-open-execution.ts:273-284, session-store.ts:423), so a source==='local' guard would drop real reopen boots. The client-app.ts thread also does not apply. A skipped stop already shows as absent data.shutdown plus the kept-running warning (session-close-lifecycle-teardown.ts:100-105). Please resolve both. The checks show 18 passing at 0e19c8d and none failing. There are no conflicts. The device lanes do not run the Android cold-open lifecycle with a live boot-owned close, so green CI does not replace the runs above. Before merge, the three live Android runs must be attached. Not blocking: if an older @agent-device/replay plugin can run against this daemon, cleanup warnings returned through ReplayTestCleanupSession would be dropped by that older runtime. |
0e19c8d to
16f77f9
Compare
|
The code at 16f77f9 has one open gap: the Android cold-open close route still has no live run. The duplicate warning plumbing is gone, and nothing in that change looks wrong. The live evidence I asked for at 0e19c8d is still missing. The Android cold-open route boots by AVD name and stamps The two open inline threads on the cold-open boot stamp do not apply, so you can resolve them. The first (thread) is the external-reboot case: your 12:01Z reply moves it to #4585, and the exclusive claim still protects #4162. The second (thread) asks for a CI is unclear at 16f77f9. One check failed and seven are still running. 'Smoke Tests' failed in run 43953240485, but three workflows use that job name (android.yml, linux.yml, apple.yml), so which one failed is not attributed yet. The Android smoke job overlaps this PR, since it replays steps on a prebooted emulator, so please check it first. All checks were green at 0e19c8d. There are no conflicts. Before merge, please post the three live Android runs at 16f77f9 and get the failed Smoke Tests job explained or green. |
… deadline Cover the retried 5 s launch start time read and the zombie case. The ps read after lsof now gets only what the shared deadline still has, so one slow attempt stays inside the 10 s pair budget.
Plain close now owns the emulator process its own `open` launched, instead
of probing which emulator generation owns the console. `open` records
`{ pid, startTime }`; close reads the host facts for that pid once, keeps
the device when the process is gone, changed, or unverifiable, and stops
the recorded process when the emulator console kill does not take.
Removes the `lsof` console-listener generation probe, the
`DeviceShutdownGenerationService` wiring, and the `generation` field that
platform runtimes no longer answer for.
`check:layering` rejects the previous shape: R65 keeps the daemon's close orchestration from selecting a concrete platform, and the launched-emulator check did exactly that. The rule moves to where R65 points — a published `LaunchedDeviceProcessService` composed at the root, answered by the Android family and `not-applicable` for every device that launches no host process. The process reads themselves (one `ps`, liveness, and the pid escalation with the recorded start time) now live in `@agent-device/platform-android/device-boot` beside the launch that records the identity, which is where the timeout and escalation budgets belong.
9ac325a to
00f70c2
Compare
|
Pushed
Exact affected validation passed (42 passed, 28 skipped). The ready-for-human review covered the previous head. This head needs a review and one live run of the five cases, plus one run of the pid fallback. This also covers #4743, which I will close when this merges. |
This comment has been minimized.
This comment has been minimized.
|
The launched-process rule is simpler than the old console probe, but at 00f70c2 close can still stop an emulator this session did not boot, and the new rule has no live run yet. CI is green: 16 checks pass. No hosted job boots an emulator, so CI does not exercise the changed stop route. No conflicts. The earlier review at 9ac325a was clean. That head re-checked ownership inside The ownership rule in device-boot.ts changed from the lsof console probe to pid plus start-time identity, with a new pid-stop fallback after Not blocking, take or leave: when Before merge, move the launched-process check to the last read before the stop, then post the live Android runs above at that head. |
The ownership read ran when close decided the stop, up to about 12 s before adb emu kill, so a replacement that took the serial during platform close or hint cleanup could be stopped. The single read now runs just before finalizeApplicationClose, and shutdownTarget is passed only when the launched process still matches. Close also warns when it could not confirm that the process exited.
|
Pushed
Exact affected validation passed (42 passed, 28 skipped). |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 76b0043. The verdict and the full list are in the summary comment.
|
Thanks for the update. At 76b0043 the race from the earlier review is fixed: the ownership check now runs just before The Android ownership rule at device-boot.ts:77 now uses a pid plus start-time launch identity, with a start-time-checked pid stop after Please also close the remaining window while you are there: lifecycle.ts:88 still runs The open inline thread on There are no known conflicts. Before merge, the live Android runs above need to be posted at the final head. |
The decide step no longer reads the launched process, so the two outcomes live only on the teardown result. The teardown comment states the residual window inside the Android stop's IME flush wait.
|
Pushed
Live runs: not done by me. This host has only AVDs that are under the standing stop conditions, and the dedicated AVD is not on it. The six scenarios in the PR body need a run at |
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.
|
At 696e453 the teardown comment now states the residual 2.5 s IME-flush window before |
|
Live Android runs for the six close cases from the earlier review, at the current head One thing to note outside the six: Full transcriptAll six scenarios behaved as expected.
Environment
How the emulator pid was found: "External boot" below means: emulator -avd agent-device-pr4539-api37 -port 5560 -no-window -no-audio -no-boot-anim -no-metrics &
# then wait for: adb -s emulator-5560 shell getprop sys.boot_completed == 11. Stopped AVD, open then close — passagent-device open Settings --platform android --device agent-device-pr4539-api37 --session s1 --state-dir "$STATE" --json
agent-device close --session s1 --state-dir "$STATE" --json
Before close: Close output: {
"success": true,
"data": {
"session": "s1",
"shutdown": {
"success": true,
"exitCode": 0,
"stdout": "OK: killing emulator, bye bye\r\nOK\r\n",
"stderr": ""
},
"message": "Closed: s1"
}
}After close ( 2. Prebooted emulator, open then close — passExternal boot first, then: agent-device open Settings --platform android --device agent-device-pr4539-api37 --session s2 --state-dir "$STATE" --json
agent-device close --session s2 --state-dir "$STATE" --json
Before close: Close output (no {
"success": true,
"data": {
"session": "s2",
"message": "Closed: s2"
}
}After close (same pid, same start time; 3. Cold open, external restart on the same serial, close — passagent-device open Settings --platform android --device agent-device-pr4539-api37 --session s3 --state-dir "$STATE" --json
adb -s emulator-5560 emu kill # external kill; waited until the pid left
# external boot again on port 5560
agent-device close --session s3 --state-dir "$STATE" --json
Process that Replacement process, before close: Close output (warning present, no {
"success": true,
"data": {
"session": "s3",
"warnings": [
"This session's open booted this device, but its emulator process has changed, so close did not request a stop. The device is still running."
],
"message": "Closed: s3"
}
}After close, the original pid has no row ( 4. Policy denies device-shutdown, cold open then close — passThe isolated daemon was stopped and restarted with a policy file, set through echo '{"version":1,"capabilities":{"deny":["device-shutdown"]}}' > "$STATE/policy.json"
export AGENT_DEVICE_DAEMON_POLICY="$STATE/policy.json"
agent-device open Settings --platform android --device agent-device-pr4539-api37 --session s4 --state-dir "$STATE" --json
agent-device close --session s4 --verbose --state-dir "$STATE" --json
Before close: Close output: {
"success": true,
"data": {
"session": "s4",
"warnings": [
"This session's open booted this device and close would stop it, but this daemon's policy denies device-shutdown. The device is still running."
],
"message": "Closed: s4"
}
}After close (same pid, same start time; 5. close --shutdown on an emulator this open did not boot — passSame externally booted emulator as scenario 2 (still running), no policy: agent-device open Settings --platform android --device agent-device-pr4539-api37 --session s5 --state-dir "$STATE" --json
agent-device close --session s5 --shutdown --state-dir "$STATE" --json
Before close: Close output: {
"success": true,
"data": {
"session": "s5",
"shutdown": {
"success": true,
"exitCode": 0,
"stdout": "OK: killing emulator, bye bye\r\nOK\r\n",
"stderr": ""
},
"message": "Closed: s5"
}
}After close: Note: 6. Emulator that ignores adb emu kill — passStaging. A wrapper #!/bin/sh
# Swallow only "emu kill"; pass everything else to the real adb.
case " $* " in
*" emu kill "*) echo "$(date -u +%FT%TZ) swallowed: adb $*" >> "$STATE/adb-swallowed.log"
printf 'OK: killing emulator, bye bye\r\nOK\r\n'; exit 0;;
esac
exec "$REAL_SDK/platform-tools/adb" "$@"The daemon was restarted without a policy and with the shadow root: export ANDROID_SDK_ROOT="$STATE/fake-sdk" ANDROID_HOME="$STATE/fake-sdk"
agent-device open Settings --platform android --device agent-device-pr4539-api37 --session s6 --state-dir "$STATE" --json
agent-device close --session s6 --verbose --state-dir "$STATE" --json
Before close: Close output (no warnings): {
"success": true,
"data": {
"session": "s6",
"shutdown": {
"success": true,
"exitCode": 0,
"stdout": "OK: killing emulator, bye bye\r\nOK\r\n",
"stderr": ""
},
"message": "Closed: s6"
}
}After close ( Request diagnostics for this close (
Limits of this run
Cleanup
|
|
This PR is ready at 696e453. The live Android runs cover all six close cases on a dedicated AVD at this head. A cold open then close stops the emulator. A pre-booted emulator is kept. After an external restart on the same serial, close warns and keeps the replacement. A policy denial warns and keeps the device. Not blocking: |
…ed (#4539) * feat(close): stop a simulator or emulator the session's own open booted Squashed rebase of #4539 onto the rewritten 0.22 (91d3628). The content equals 29cb52b except for conflict adaptations: the interaction-contract harness keeps main's single settling read, and two tests pass main's new cache argument before the lifecycle loader. * fix(close): read the emulator console listener without blocking calls and retry a slow read Under heavy host load one lsof read took 1.7-4.2 s against a 3 s budget, so the launch identity read as unobserved and close kept an emulator it should stop. Use lsof -b -w -t, give each read 5 s, and retry once when a read times out or fails. A clean no-listener answer is final. * fix(close): bound the launch identity probe and keep -b off Linux lsof Open and close each run two agreeing observations, and each observation could take two 5 s reads, so the probe could add 20 s per step. The pair now shares one 10 s deadline that also caps each lsof and ps read. Linux lsof finds sockets through /proc, and -b can stop the port filter matching there, so -b and -w apply only on macOS. * fix(close): retry the launch start time read and name each identity miss Open read the launched emulator's start time with the 1 s ps default, so one slow ps left no launch identity and cold stop failed safe under load. The read now uses the listener probe's 5 s budget and one retry. Each observation reports why it produced no identity; open logs android_launch_identity_unbound and close logs android_launch_identity_unobserved with the step and the read that missed. The close warning now says when open recorded no identity. * refactor(close): drop the identity-only probe export Every caller now reads the miss reason through inspectAndroidEmulatorGeneration. * test(close): cover the launch start time retry and keep ps inside the deadline Cover the retried 5 s launch start time read and the zombie case. The ps read after lsof now gets only what the shared deadline still has, so one slow attempt stays inside the 10 s pair budget. * refactor(android): verify the launched emulator process on close Plain close now owns the emulator process its own `open` launched, instead of probing which emulator generation owns the console. `open` records `{ pid, startTime }`; close reads the host facts for that pid once, keeps the device when the process is gone, changed, or unverifiable, and stops the recorded process when the emulator console kill does not take. Removes the `lsof` console-listener generation probe, the `DeviceShutdownGenerationService` wiring, and the `generation` field that platform runtimes no longer answer for. * refactor(close): ask the root-composed owner about the launched process `check:layering` rejects the previous shape: R65 keeps the daemon's close orchestration from selecting a concrete platform, and the launched-emulator check did exactly that. The rule moves to where R65 points — a published `LaunchedDeviceProcessService` composed at the root, answered by the Android family and `not-applicable` for every device that launches no host process. The process reads themselves (one `ps`, liveness, and the pid escalation with the recorded start time) now live in `@agent-device/platform-android/device-boot` beside the launch that records the identity, which is where the timeout and escalation budgets belong. * fix(close): read launched-process ownership right before the stop The ownership read ran when close decided the stop, up to about 12 s before adb emu kill, so a replacement that took the serial during platform close or hint cleanup could be stopped. The single read now runs just before finalizeApplicationClose, and shutdownTarget is passed only when the launched process still matches. Close also warns when it could not confirm that the process exited. * refactor(close): keep launched-process outcomes on the teardown result The decide step no longer reads the launched process, so the two outcomes live only on the teardown result. The teardown comment states the residual window inside the Android stop's IME flush wait.
…ed (#4539) * feat(close): stop a simulator or emulator the session's own open booted Squashed rebase of #4539 onto the rewritten 0.22 (91d3628). The content equals 29cb52b except for conflict adaptations: the interaction-contract harness keeps main's single settling read, and two tests pass main's new cache argument before the lifecycle loader. * fix(close): read the emulator console listener without blocking calls and retry a slow read Under heavy host load one lsof read took 1.7-4.2 s against a 3 s budget, so the launch identity read as unobserved and close kept an emulator it should stop. Use lsof -b -w -t, give each read 5 s, and retry once when a read times out or fails. A clean no-listener answer is final. * fix(close): bound the launch identity probe and keep -b off Linux lsof Open and close each run two agreeing observations, and each observation could take two 5 s reads, so the probe could add 20 s per step. The pair now shares one 10 s deadline that also caps each lsof and ps read. Linux lsof finds sockets through /proc, and -b can stop the port filter matching there, so -b and -w apply only on macOS. * fix(close): retry the launch start time read and name each identity miss Open read the launched emulator's start time with the 1 s ps default, so one slow ps left no launch identity and cold stop failed safe under load. The read now uses the listener probe's 5 s budget and one retry. Each observation reports why it produced no identity; open logs android_launch_identity_unbound and close logs android_launch_identity_unobserved with the step and the read that missed. The close warning now says when open recorded no identity. * refactor(close): drop the identity-only probe export Every caller now reads the miss reason through inspectAndroidEmulatorGeneration. * test(close): cover the launch start time retry and keep ps inside the deadline Cover the retried 5 s launch start time read and the zombie case. The ps read after lsof now gets only what the shared deadline still has, so one slow attempt stays inside the 10 s pair budget. * refactor(android): verify the launched emulator process on close Plain close now owns the emulator process its own `open` launched, instead of probing which emulator generation owns the console. `open` records `{ pid, startTime }`; close reads the host facts for that pid once, keeps the device when the process is gone, changed, or unverifiable, and stops the recorded process when the emulator console kill does not take. Removes the `lsof` console-listener generation probe, the `DeviceShutdownGenerationService` wiring, and the `generation` field that platform runtimes no longer answer for. * refactor(close): ask the root-composed owner about the launched process `check:layering` rejects the previous shape: R65 keeps the daemon's close orchestration from selecting a concrete platform, and the launched-emulator check did exactly that. The rule moves to where R65 points — a published `LaunchedDeviceProcessService` composed at the root, answered by the Android family and `not-applicable` for every device that launches no host process. The process reads themselves (one `ps`, liveness, and the pid escalation with the recorded start time) now live in `@agent-device/platform-android/device-boot` beside the launch that records the identity, which is where the timeout and escalation budgets belong. * fix(close): read launched-process ownership right before the stop The ownership read ran when close decided the stop, up to about 12 s before adb emu kill, so a replacement that took the serial during platform close or hint cleanup could be stopped. The single read now runs just before finalizeApplicationClose, and shutdownTarget is passed only when the launched process still matches. Close also warns when it could not confirm that the process exited. * refactor(close): keep launched-process outcomes on the teardown result The decide step no longer reads the launched process, so the two outcomes live only on the teardown result. The teardown comment states the residual window inside the Android stop's IME flush wait.
…ed (#4539) * feat(close): stop a simulator or emulator the session's own open booted Squashed rebase of #4539 onto the rewritten 0.22 (91d3628). The content equals 29cb52b except for conflict adaptations: the interaction-contract harness keeps main's single settling read, and two tests pass main's new cache argument before the lifecycle loader. * fix(close): read the emulator console listener without blocking calls and retry a slow read Under heavy host load one lsof read took 1.7-4.2 s against a 3 s budget, so the launch identity read as unobserved and close kept an emulator it should stop. Use lsof -b -w -t, give each read 5 s, and retry once when a read times out or fails. A clean no-listener answer is final. * fix(close): bound the launch identity probe and keep -b off Linux lsof Open and close each run two agreeing observations, and each observation could take two 5 s reads, so the probe could add 20 s per step. The pair now shares one 10 s deadline that also caps each lsof and ps read. Linux lsof finds sockets through /proc, and -b can stop the port filter matching there, so -b and -w apply only on macOS. * fix(close): retry the launch start time read and name each identity miss Open read the launched emulator's start time with the 1 s ps default, so one slow ps left no launch identity and cold stop failed safe under load. The read now uses the listener probe's 5 s budget and one retry. Each observation reports why it produced no identity; open logs android_launch_identity_unbound and close logs android_launch_identity_unobserved with the step and the read that missed. The close warning now says when open recorded no identity. * refactor(close): drop the identity-only probe export Every caller now reads the miss reason through inspectAndroidEmulatorGeneration. * test(close): cover the launch start time retry and keep ps inside the deadline Cover the retried 5 s launch start time read and the zombie case. The ps read after lsof now gets only what the shared deadline still has, so one slow attempt stays inside the 10 s pair budget. * refactor(android): verify the launched emulator process on close Plain close now owns the emulator process its own `open` launched, instead of probing which emulator generation owns the console. `open` records `{ pid, startTime }`; close reads the host facts for that pid once, keeps the device when the process is gone, changed, or unverifiable, and stops the recorded process when the emulator console kill does not take. Removes the `lsof` console-listener generation probe, the `DeviceShutdownGenerationService` wiring, and the `generation` field that platform runtimes no longer answer for. * refactor(close): ask the root-composed owner about the launched process `check:layering` rejects the previous shape: R65 keeps the daemon's close orchestration from selecting a concrete platform, and the launched-emulator check did exactly that. The rule moves to where R65 points — a published `LaunchedDeviceProcessService` composed at the root, answered by the Android family and `not-applicable` for every device that launches no host process. The process reads themselves (one `ps`, liveness, and the pid escalation with the recorded start time) now live in `@agent-device/platform-android/device-boot` beside the launch that records the identity, which is where the timeout and escalation budgets belong. * fix(close): read launched-process ownership right before the stop The ownership read ran when close decided the stop, up to about 12 s before adb emu kill, so a replacement that took the serial during platform close or hint cleanup could be stopped. The single read now runs just before finalizeApplicationClose, and shutdownTarget is passed only when the launched process still matches. Close also warns when it could not confirm that the process exited. * refactor(close): keep launched-process outcomes on the teardown result The decide step no longer reads the launched process, so the two outcomes live only on the teardown result. The teardown comment states the residual window inside the Android stop's IME flush wait.
…ed (#4539) * feat(close): stop a simulator or emulator the session's own open booted Squashed rebase of #4539 onto the rewritten 0.22 (91d3628). The content equals 29cb52b except for conflict adaptations: the interaction-contract harness keeps main's single settling read, and two tests pass main's new cache argument before the lifecycle loader. * fix(close): read the emulator console listener without blocking calls and retry a slow read Under heavy host load one lsof read took 1.7-4.2 s against a 3 s budget, so the launch identity read as unobserved and close kept an emulator it should stop. Use lsof -b -w -t, give each read 5 s, and retry once when a read times out or fails. A clean no-listener answer is final. * fix(close): bound the launch identity probe and keep -b off Linux lsof Open and close each run two agreeing observations, and each observation could take two 5 s reads, so the probe could add 20 s per step. The pair now shares one 10 s deadline that also caps each lsof and ps read. Linux lsof finds sockets through /proc, and -b can stop the port filter matching there, so -b and -w apply only on macOS. * fix(close): retry the launch start time read and name each identity miss Open read the launched emulator's start time with the 1 s ps default, so one slow ps left no launch identity and cold stop failed safe under load. The read now uses the listener probe's 5 s budget and one retry. Each observation reports why it produced no identity; open logs android_launch_identity_unbound and close logs android_launch_identity_unobserved with the step and the read that missed. The close warning now says when open recorded no identity. * refactor(close): drop the identity-only probe export Every caller now reads the miss reason through inspectAndroidEmulatorGeneration. * test(close): cover the launch start time retry and keep ps inside the deadline Cover the retried 5 s launch start time read and the zombie case. The ps read after lsof now gets only what the shared deadline still has, so one slow attempt stays inside the 10 s pair budget. * refactor(android): verify the launched emulator process on close Plain close now owns the emulator process its own `open` launched, instead of probing which emulator generation owns the console. `open` records `{ pid, startTime }`; close reads the host facts for that pid once, keeps the device when the process is gone, changed, or unverifiable, and stops the recorded process when the emulator console kill does not take. Removes the `lsof` console-listener generation probe, the `DeviceShutdownGenerationService` wiring, and the `generation` field that platform runtimes no longer answer for. * refactor(close): ask the root-composed owner about the launched process `check:layering` rejects the previous shape: R65 keeps the daemon's close orchestration from selecting a concrete platform, and the launched-emulator check did exactly that. The rule moves to where R65 points — a published `LaunchedDeviceProcessService` composed at the root, answered by the Android family and `not-applicable` for every device that launches no host process. The process reads themselves (one `ps`, liveness, and the pid escalation with the recorded start time) now live in `@agent-device/platform-android/device-boot` beside the launch that records the identity, which is where the timeout and escalation budgets belong. * fix(close): read launched-process ownership right before the stop The ownership read ran when close decided the stop, up to about 12 s before adb emu kill, so a replacement that took the serial during platform close or hint cleanup could be stopped. The single read now runs just before finalizeApplicationClose, and shutdownTarget is passed only when the launched process still matches. Close also warns when it could not confirm that the process exited. * refactor(close): keep launched-process outcomes on the teardown result The decide step no longer reads the launched process, so the two outcomes live only on the teardown result. The teardown comment states the residual window inside the Android stop's IME flush wait.
Summary
Refs #4162 and #4585. Plain
agent-device closestops a local simulator or emulator that this session's own open booted, while the session's device claim is current. A device that was already running stays running. Explicitclose --shutdown, daemon policy, lost claims and provider release keep their existing paths.For an Android emulator, close stops only the process that open launched. Close reads that process once, right before it asks for the stop. A reopen of the same device keeps the recorded launch identity, and a serial change clears it.
Scope is 62 files against 0.22
9440141767.Ownership rule for an Android emulator
Plain close stops the emulator process this session's open launched. Open records
{ pid, startTime }from the spawn. Close reads that process once, after platform close and hint cleanup and right before the stop:adb emu kill, then close confirms that the pid exits, and falls back to a pid stop that checks the start time.There is no
lsofprobe, so the rule does not depend onlsofon the host.Validation
Current head
696e453f33ca5872fdc52ca9c8f941ca67d1e7e3on 0.229440141767. Exactpnpm check:affected --run --base origin/0.22 --head 696e453f33passed: 42 passed, 28 skipped, exact commit, unchanged checkout.Live Android evidence is required at this head, on a dedicated AVD: cold open then close (stops); a prebooted emulator (kept); an external restart with the same serial (warning, replacement kept); a policy denial (kept, warning);
close --shutdown(stops); and an emulator that ignoresadb emu kill(pid stop). The earlier live runs covered the removedlsofdesign.