Repository navigation
Exit host daemon promptly after clean shutdown - #2965
Conversation
|
🚨 SLOP COP 🚨 · I am the Slop Cop. I am reviewing this pull request for security, code quality, performance, tests, and duplicate architecture. |
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain-English summary: This change makes the host daemon end immediately after successful cleanup. It no longer waits for active Node resources or the 15-second watchdog.
I found two shutdown problems.
- A daemon-lock loss must exit with status 1. The new status-0 exit occurs before the existing
.finally()callback can run. A child-process test confirmed status 0. - A signal during
onStartskips the immediate exit becausestartedremains false. With an active resource, the process waits for the watchdog. A process test took 207 ms with a 200 ms grace value.
The security review found no new trust boundary, input path, privilege, credential, network, or data-access risk.
I found no duplicate daemon shutdown code. The server and desktop have different process owners and exit rules. The daemon should make one exit decision with a caller-selected status. That design also gives startup failure and startup interruption separate meanings.
The focused daemon lifecycle test passed all nine tests. The host-daemon type check passed. All current GitHub checks completed successfully or had a configured skip.
This change has no browser route, so a Doobie test cannot observe it. The child-process tests directly covered the affected process behavior.
I would fix both shutdown cases before merge.
|
🚨 SLOP COP 🚨 · I am the Slop Cop. I am reviewing this pull request now. I will check security, code quality, performance, architecture, and duplicate code. I will also test the changed path when possible. |
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain-English summary: This change makes the host daemon exit immediately after successful cleanup. It keeps status 1 for a daemon-lock failure.
I found two merge blockers.
- The required
exitCodeargument was not added to two integration-harness calls. The full integration type check and GitHub build fail. - The first shutdown request owns the final status. A later daemon-lock loss cannot change an active status-0 shutdown to status 1.
My child-process check reproduced the second problem. A status-0 shutdown began, then a lock loss occurred before cleanup ended. The process exited with status 0.
The security review found no new privilege, input, credential, network, or data-access risk. Cleanup still occurs before a normal process exit.
I found no useful shared refactor. The server and desktop shutdown paths have different owners and exit rules. I found no stale forceExit name.
The host-daemon test suite passed all 568 tests. The host-daemon type check passed. The integration type check failed at helpers/harness.ts lines 455 and 479.
This change has no browser route, so Doobie cannot test it. The lifecycle tests and child-process check directly cover the changed behavior.
I posted two inline comments with the required fixes. I used a comment review and did not approve or request changes.
|
Ubuntu 24.04 systemd canary passed on the PR head (
The disposable VM and fresh test server were removed after the run. |
0e771c4 to
7685dd0
Compare
Human comments
What was wrong
The production host daemon had no deterministic process exit after its semantic shutdown completed. It relied on every Node resource allowing the event loop to drain or on a 15-second watchdog, while the machine installer allows the temporary daemon only five seconds before sending SIGKILL. Lingering resources could therefore turn an otherwise clean shutdown into a forced kill and delay the service-manager handoff.
What changed
After event flushing, runtime shutdown, and lock release all succeed, the production daemon now clears its watchdog and exits immediately with the caller-selected status. Normal shutdowns exit with status 0, while daemon-lock loss exits with status 1 through both clean and watchdog paths.
Startup failure is tracked separately from a shutdown requested while startup is pending. A real startup failure still reaches the entrypoint's diagnostic and failure path, while SIGINT or SIGTERM during pending startup exits promptly and cannot subsequently report the daemon as started. A cleanup step that genuinely hangs retains the existing 15-second watchdog.
This does not change the host-daemon wire contract, so HOST_DAEMON_PROTOCOL_VERSION is unchanged. There are no CLI or documentation changes.
How you verified
pnpm exec turbo run test --filter=@bb/host-daemon --force: 46 files and 568 tests passed.pnpm exec turbo run test --filter=@bb/host-daemon --force -- --run src/daemon.test.ts: 11 tests passed, including clean exit, caller-selected lock-loss status, pending-startup signal handling, hung-cleanup watchdog, and startup-failure behavior.pnpm exec turbo run typecheck --filter=@bb/host-daemon --force: passed.pnpm exec turbo run build --filter=bb-app --force: 12 tasks passed.bb-app host-daemon joinagainst a fresh local server, waited until connected, sent SIGTERM, and measured 274 ms to exit with status 0 and no forced-kill warning.