Repository navigation
fix(daemon): close a detached daemon that finds its registration deleted or replaced - #4837
Conversation
…ted or replaced A daemon whose daemon.json was deleted or taken over only logged daemon_metadata_lost and kept running: with an open session, until someone killed it. No new client can find such a daemon, so it now closes by itself. An embedded runtime keeps serving its host. 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: 2 new findings on f023aeb. 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.
|
This PR is ready at 9a758e2: a detached daemon now closes when its registration is deleted or replaced, and the code and its regression test hold up on review. All 19 checks pass at this commit, and no conflicts are known. Nothing blocks merge. Not blocking, and fine to take or leave: when the whole state directory is removed, the watch in daemon-metadata-loss.ts:76 cancels without calling Of the two open inline threads, the one on the Not verified here: the tests were not run, the live stop and successor-race run in the PR body was not reproduced, and runner teardown against a successor on the same device was not traced (the same teardown already ran on idle reap of an orphan before this PR). |
Problem
A daemon polls its own
daemon.jsonevery 15 s. When the record is deleted or names another process, the daemon writesdaemon_metadata_lostto its log and keeps running. No new client can find it. An idle one leaves at the idle reap; one with an open session stays until someone kills it, with its sessions and runner.This is reachable today by anything that removes or replaces a live daemon's record. It becomes easy to reach with #4682: an older CLI cannot compare the new start-time token, so its
daemon stopreports "not running", deletes the record, and leaves the newer daemon alive. The older CLI's own error for a newer daemon tells the user to run that stop.Change
When the watch reports the loss, a detached daemon closes through the same
close()that a signal, a quiesce and the idle reap use. The log line is written first. An embedded runtime does not close: its host still uses it.armDaemonMetadataLossWatchtakes the callback; the runtime passesclosefor a detached daemon. The watch, its poll and the close path are unchanged. The existing fence still stops a closing daemon from removing a successor's record.Evidence
Unit (
daemon-runtime-metadata-ownership.test.ts):closedsettles, teardown ran, and its lock is released. Both fail onmain(the runtime never closes).Live, macOS, released 0.21.41 CLI against a build of this branch merged with #4682 (
af8197c), one simulator, isolated claim, lease and state directories:daemon stopin its state directoryLocal:
packages/daemon/src/server(125 files, 974 tests), typecheck, lint, the eager-closure gate and the layering scan pass. No allowlist, baseline or budget rows.Size
Production: +22 −6, net +16 lines, 5 of them comments. No new module, so the built CLI startup cost does not change.
Notes
daemon_shutdown_record_failedanddaemon_registration_finish_failedwhen the lock is already gone. Both are warnings from the existing close path.Part of #4649. Recommended before #4682.
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.