Repository navigation
fix(daemon): give a closing daemon its full teardown before anything kills it - #4806
Conversation
…kills it A closing daemon stops listening first and removes its registration last. Another client read that as unreachable and sent SIGKILL 3 s after SIGTERM, and daemon stop did the same after 10 s, while the daemon's own teardown is bounded at up to 65 s. One grace of 75 s now covers graceful retirement, daemon stop and the ensureDaemon judge-again budget. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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: 4 new findings on 13a4927. The verdict and the full list are in the summary comment.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
|
This PR is ready at c3d0f3c: nothing needs a change before merge, and CI is green (19 checks, 0 not passing). There are no conflicts, and the PR can merge once the open review threads below are resolved. Not blocking, and you can take or leave these: (1) the 75 s that The inline thread on the hand-summed 19_000 budget still applies (#4806 (comment), same as note 3), so please keep it open. The cli-help.ts and commands.md thread is fixed at this head (#4806 (comment)). Two threads do not apply, so please resolve them: a daemon that accepts a quiesce holds no session, so the 60 s wait covers its teardown (#4806 (comment)), and a closing daemon counts as starting up, so the takeover path is not reached for it (#4806 (comment)). |
…down budget, name the exceptions Review follow-up on the teardown grace. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Review notes addressed in 153b871.
The two threads that do not apply were already resolved. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 153b871. The verdict and the full list are in the summary comment.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
* origin/main: refactor(apple-runner): generate the Swift runner error-code enums from runner-contract.ts (#4810) fix(daemon-client): report a newer daemon that won a startup race as daemon-incompatible (#4801) feat(shake): add a shake command for iOS simulators and Android emulators (#4741) fix(daemon): give a closing daemon its full teardown before anything kills it (#4806) fix(android): use typed evidence in the readiness boot poller (#4717)
Problem
A closing daemon stops listening at its first teardown step and removes
daemon.jsonat its last. Until it exits, another client sees a live, registered process that refuses connections.daemon stopsent SIGKILL 10 s after SIGTERM.A killed teardown skips lease release, claim release, runner shutdown and the shutdown report. On a host shared by several agents, the trigger is another agent's command that arrives while a daemon closes (idle reap, an accepted drain, or
daemon stop).ensureDaemon()also judged a leaving daemon again for only 10 s (40 × 250 ms) and then failed withdaemon-lifecycle-contended, although its comment says "for as long as a drain can take".Change
One constant,
DAEMON_TEARDOWN_GRACE_MS(75 s) indaemon-contracts/daemon-process:stopAndRetireDaemon) waits this long after SIGTERM by default (was 3 s). The wait ends when the process exits.daemon stoppasses the same grace explicitly (was 10 s), and its test asserts 75 s.DAEMON_STOP_GRACE_TIMEOUT_MSis deleted.replay(cleanupDaemonAfterRequestindaemon-client-lifecycle.ts, includingreplay --save-script) uses the default, so it now waits up to 75 s before SIGKILL (was 3 s). That daemon also tears down a session.ensureDaemon()judge-again budget is derived from it (was a fixed 10 s).Cost: a daemon that is stuck in its teardown delays the caller by up to 75 s before SIGKILL (was 4 s, or 12 s for
daemon stop).Not in this PR: the request-timeout path still decides with one 1 s liveness probe, where
ensureDaemon()uses three.Evidence
daemon-client-ensure-drain.test.ts, "a compatible daemon that is closing is waited for, not killed, by another client": a registered same-version daemon refuses connections and takes 30 virtual seconds to leave. On the branch the client sends one SIGTERM and no SIGKILL, then starts the successor. With the production change reverted the test fails:SIGKILLis recorded.session-teardown-budget.test.ts, "the grace a client gives a closing daemon covers the largest teardown the daemon bounds": fails if a teardown budget grows past the grace.packages/daemon-client,packages/daemon-contractsand the budget test: 64 files, 593 tests pass. Eager-closure gate (913 tests), typecheck, lint and the layering scan pass. No allowlist, baseline or budget rows.Size
Production: +33 −8, net +25 lines (12 are comments). No new module, so the built CLI startup cost does not change.
Part of #4649.
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.