Skip to content

fix(close): wait for the emulator process to exit on close --shutdown - #4815

Merged
thymikee merged 2 commits into
0.22from
fix/0.22-close-shutdown-waits-for-exit
Nov 20, 2026
Merged

thymikee merged 2 commits into
0.22from
fix/0.22-close-shutdown-waits-for-exit

Conversation

@thymikee

@thymikee thymikee commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #4807.

close --shutdown asked the device to stop (adb emu kill) and returned, so a caller could not tell
whether the emulator host process this session launched had exited. Plain close already waits for
that exit. Both stops now confirm it through the launched-process owner (confirmLaunchedProcessStopped)
after the stop, and an unconfirmed exit carries the existing "could not confirm that its emulator
process exited" warning.

--shutdown still never asks the ownership CHECK, so the stop is not gated by what the recorded
process says. implicitShutdownStopUnconfirmed is renamed to shutdownStopUnconfirmed to cover both
paths.

On a session with no recorded launch identity (a prebooted emulator) there is no recorded process to
confirm, so nothing is asked of the owner. No probe by serial is added: the removed lsof probe stays
removed. The close orchestration still names no platform.

Touched files: 5 (2 daemon, 1 test, 2 docs). No scope expansion, no changesets.

Validation

Base c30537bd66, head 6f229bb7ef.

  • pnpm check:affected --run --base origin/0.22 --head 6f229bb7ef: passed, exactCommit=true,
    receipt .tmp/validation/run-aop6r6/receipt.json. 18 checks selected, no fail-open: 11 runnable
    passed; 7 skipped as GitHub-authoritative or parked lanes.
  • Focused: session-close-external-reboot.test.ts 13/13; packages/daemon/src/sessions 170 files /
    1289 tests; src/platform-runtime-device-boot.test.ts 7/7.
  • pnpm typecheck, pnpm format, fallow audit --base origin/0.22: clean.
  • Reverting the confirmation guard fails exactly the two new --shutdown cases.

CI obligations: the skipped lanes above. A live Android run on a dedicated AVD showing the emulator
pid gone when close --shutdown returns is still required.

Plain close confirms that the emulator process its own open launched has
exited after the stop it owes. close --shutdown only asked the device to stop
and returned, so a caller could not tell whether the emulator host process was
gone (#4807).

Both stops now go through the same launched-process confirmation. An explicit
--shutdown still skips the ownership check: the user commanded the stop, so
what the recorded process says cannot gate it. A --shutdown on a session with
no recorded launch identity (a prebooted emulator) has no process to confirm,
so nothing is asked of the owner and no process probe is added. The result
flag is renamed to shutdownStopUnconfirmed to cover both paths, and the
existing unconfirmed-exit warning now rides the explicit path too.
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.19 MB 6.19 MB -55 B
Package (unpacked) 6.19 MB 6.19 MB -55 B
Package (download) 1.88 MB 1.88 MB -21 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 52.5 ms 33.6 ms -19.0 ms
CLI --help 73.2 ms 66.8 ms -6.3 ms

@thymikee

Copy link
Copy Markdown
Member Author

The code at 6f229bb looks right, but this device-facing change has no live run yet, so it is not ready to merge. Explicit close --shutdown on a local Android emulator now runs the post-stop exit confirmation and the pid TERM/KILL fallback (session-close-lifecycle-teardown.ts#L288). Issue #4807 requires a live run, and the PR body says it is still owed. Today only fixture doubles cover this route, so nothing shows that adb emu kill plus the confirmation leaves the emulator pid gone when the command returns, or that it stays within the time budget. Please run it on a dedicated AVD: open --platform android cold-boots it so the session records a launch identity, then record the emulator pid (for example pgrep -f qemu-system.*@<avd>) and run close --shutdown --json. The output should show kill -0 <pid> failing right after the command returns, no stop-unconfirmed warning in the response, and the elapsed time. A close --shutdown on a prebooted emulator returning with no confirmation would be a useful extra.

The tests use the launched-process owner fixture, so the real owner's confirm path is covered only by src/platform-runtime-device-boot.test.ts and the Android lanes. The 14 finished checks passed. Not blocking, take or leave: the new sentence in sessions.md#L136 says --shutdown "waits for the process ... to exit", but device-boot.ts also sends SIGTERM and then SIGKILL to the recorded pid after 3 s, so "waits for, and if needed stops, the process this session's open launched" would be more exact. Before merge, the live AVD run above needs to land in the PR.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Live run: close --shutdown on a dedicated AVD

Head under test: 6f229bb7ef (built in the PR worktree, branch CLI, isolated --state-dir). AVD: agent-device-4539-live, never booted before this run. It took serial emulator-5558 because 5554 and 5556 were in use by other devices; no other device was touched.

Step Result
Cold open com.android.settings --platform android --device agent-device-4539-live success, 79 s
Emulator process pid 39881, started Fri Nov 20 15:00:18 2026 (qemu-system-aarch64 -avd agent-device-4539-live)
close --shutdown --json exit 0, elapsed 4531 ms
ps -p 39881 immediately after return no process, exit 1
warnings none (no stop-unconfirmed warning)
{
  "success": true,
  "data": {
    "session": "live4815",
    "shutdown": {
      "success": true,
      "exitCode": 0,
      "stdout": "OK: killing emulator, bye bye\r\nOK\r\n",
      "stderr": ""
    },
    "message": "Closed: live4815"
  }
}

The process check used ps -p <pid> instead of kill -0 <pid>; it gives the same answer. The isolated daemon was stopped after the run.

The follow-up commit only changes the wording in sessions.md ("waits for, and if needed stops, the process this session's open launched").

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 943fa14

Since the review of 6f229bb: 0 new · 0 still open · 0 no longer raised

No open findings.

Reviewed with this repository's own Sentinel configuration (bfc09800bd5b).

💬 Talking to Sentinel

In a finding's thread, reply with:

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.

@thymikee

Copy link
Copy Markdown
Member Author

This PR is ready at 943fa14. The live run on a dedicated AVD shows the changed route: after a cold open, close --shutdown --json returned in 4.5 s with no warnings, and the emulator process it launched was gone the moment the command returned. The only change since 6f229bb is the sessions.md wording, which now says the command waits for, and if needed stops, the process this session's open launched.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
@thymikee
thymikee merged commit 5a9eb42 into 0.22 Nov 20, 2026
14 checks passed
@thymikee
thymikee deleted the fix/0.22-close-shutdown-waits-for-exit branch November 20, 2026 15:11
thymikee added a commit that referenced this pull request Nov 20, 2026
…#4815)

* fix(close): wait for the emulator process to exit on close --shutdown

Plain close confirms that the emulator process its own open launched has
exited after the stop it owes. close --shutdown only asked the device to stop
and returned, so a caller could not tell whether the emulator host process was
gone (#4807).

Both stops now go through the same launched-process confirmation. An explicit
--shutdown still skips the ownership check: the user commanded the stop, so
what the recorded process says cannot gate it. A --shutdown on a session with
no recorded launch identity (a prebooted emulator) has no process to confirm,
so nothing is asked of the owner and no process probe is added. The result
flag is renamed to shutdownStopUnconfirmed to cover both paths, and the
existing unconfirmed-exit warning now rides the explicit path too.

* docs(sessions): say close --shutdown stops the launched process when needed
thymikee added a commit that referenced this pull request Nov 20, 2026
…#4815)

* fix(close): wait for the emulator process to exit on close --shutdown

Plain close confirms that the emulator process its own open launched has
exited after the stop it owes. close --shutdown only asked the device to stop
and returned, so a caller could not tell whether the emulator host process was
gone (#4807).

Both stops now go through the same launched-process confirmation. An explicit
--shutdown still skips the ownership check: the user commanded the stop, so
what the recorded process says cannot gate it. A --shutdown on a session with
no recorded launch identity (a prebooted emulator) has no process to confirm,
so nothing is asked of the owner and no process probe is added. The result
flag is renamed to shutdownStopUnconfirmed to cover both paths, and the
existing unconfirmed-exit warning now rides the explicit path too.

* docs(sessions): say close --shutdown stops the launched process when needed
thymikee added a commit that referenced this pull request Nov 21, 2026
…#4815)

* fix(close): wait for the emulator process to exit on close --shutdown

Plain close confirms that the emulator process its own open launched has
exited after the stop it owes. close --shutdown only asked the device to stop
and returned, so a caller could not tell whether the emulator host process was
gone (#4807).

Both stops now go through the same launched-process confirmation. An explicit
--shutdown still skips the ownership check: the user commanded the stop, so
what the recorded process says cannot gate it. A --shutdown on a session with
no recorded launch identity (a prebooted emulator) has no process to confirm,
so nothing is asked of the owner and no process probe is added. The result
flag is renamed to shutdownStopUnconfirmed to cover both paths, and the
existing unconfirmed-exit warning now rides the explicit path too.

* docs(sessions): say close --shutdown stops the launched process when needed
thymikee added a commit that referenced this pull request Nov 21, 2026
…#4815)

* fix(close): wait for the emulator process to exit on close --shutdown

Plain close confirms that the emulator process its own open launched has
exited after the stop it owes. close --shutdown only asked the device to stop
and returned, so a caller could not tell whether the emulator host process was
gone (#4807).

Both stops now go through the same launched-process confirmation. An explicit
--shutdown still skips the ownership check: the user commanded the stop, so
what the recorded process says cannot gate it. A --shutdown on a session with
no recorded launch identity (a prebooted emulator) has no process to confirm,
so nothing is asked of the owner and no process probe is added. The result
flag is renamed to shutdownStopUnconfirmed to cover both paths, and the
existing unconfirmed-exit warning now rides the explicit path too.

* docs(sessions): say close --shutdown stops the launched process when needed
thymikee added a commit that referenced this pull request Nov 23, 2026
…#4815)

* fix(close): wait for the emulator process to exit on close --shutdown

Plain close confirms that the emulator process its own open launched has
exited after the stop it owes. close --shutdown only asked the device to stop
and returned, so a caller could not tell whether the emulator host process was
gone (#4807).

Both stops now go through the same launched-process confirmation. An explicit
--shutdown still skips the ownership check: the user commanded the stop, so
what the recorded process says cannot gate it. A --shutdown on a session with
no recorded launch identity (a prebooted emulator) has no process to confirm,
so nothing is asked of the owner and no process probe is added. The result
flag is renamed to shutdownStopUnconfirmed to cover both paths, and the
existing unconfirmed-exit warning now rides the explicit path too.

* docs(sessions): say close --shutdown stops the launched process when needed
hannojg pushed a commit to hannojg/agent-device that referenced this pull request Nov 23, 2026
…callstack#4815)

* fix(close): wait for the emulator process to exit on close --shutdown

Plain close confirms that the emulator process its own open launched has
exited after the stop it owes. close --shutdown only asked the device to stop
and returned, so a caller could not tell whether the emulator host process was
gone (callstack#4807).

Both stops now go through the same launched-process confirmation. An explicit
--shutdown still skips the ownership check: the user commanded the stop, so
what the recorded process says cannot gate it. A --shutdown on a session with
no recorded launch identity (a prebooted emulator) has no process to confirm,
so nothing is asked of the owner and no process probe is added. The result
flag is renamed to shutdownStopUnconfirmed to cover both paths, and the
existing unconfirmed-exit warning now rides the explicit path too.

* docs(sessions): say close --shutdown stops the launched process when needed
thymikee added a commit that referenced this pull request Nov 24, 2026
…#4815)

* fix(close): wait for the emulator process to exit on close --shutdown

Plain close confirms that the emulator process its own open launched has
exited after the stop it owes. close --shutdown only asked the device to stop
and returned, so a caller could not tell whether the emulator host process was
gone (#4807).

Both stops now go through the same launched-process confirmation. An explicit
--shutdown still skips the ownership check: the user commanded the stop, so
what the recorded process says cannot gate it. A --shutdown on a session with
no recorded launch identity (a prebooted emulator) has no process to confirm,
so nothing is asked of the owner and no process probe is added. The result
flag is renamed to shutdownStopUnconfirmed to cover both paths, and the
existing unconfirmed-exit warning now rides the explicit path too.

* docs(sessions): say close --shutdown stops the launched process when needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant