Repository navigation
fix(mcp): daemon exits when its project root is deleted (fixes #3245) - #3259
Open
johnhldiver-beep wants to merge 1 commit into
Open
johnhldiver-beep wants to merge 1 commit into
johnhldiver-beep wants to merge 1 commit into
Conversation
…#3245) The daemon kept running with its recursive watcher open after its project root (a git worktree) was deleted, only exiting when the last client disconnected and the 300s idle timeout passed. It now checks every 5s (CODEGRAPH_DAEMON_ROOT_CHECK_MS, 0 disables) and stops promptly, removing its registry entry and stopping its watcher. Daemon.stop() also wraps engine.stop() in try/finally so the lockfile cleanup and deregistration always run.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3245.
Problem
A CodeGraph daemon kept running with its recursive
fs.watch/ FSEvents stream open after its project root (a git worktree) was deleted. It only exited when the last client disconnected and the 300s idle timeout had passed, leaving a stale registry entry and a watcher on a deleted tree.Fix
<root>/.codegraph) still exists. If either is gone it callsstop('project root deleted'): stops the watcher, removes its registry entry, and exits. The interval is overridable withCODEGRAPH_DAEMON_ROOT_CHECK_MS(0disables the check). The timer isunref'd, so it cannot keep the process alive on its own.Daemon.stop()now wrapsengine.stop()intry/finally, socleanupLockfile()andderegisterDaemon()always run even ifengine.stop()throws.Verification (all numbers from disk/logs, Linux)
__tests__/daemon-root-deleted.test.tsfail 2/2 on unfixed code (daemon keeps running after root deletion) and pass 2/2 with the fix. The gate-1 check was redone by hand: stashdaemon.ts+ rebuilddist(verified by grep thatdistcontains no fix) → 2 failed; restore + rebuild → 2 passed.tscexit 0.npm test, 887 files, ~34 min): 867 passed | 1 failed | 19 skipped; 10964 tests: 10518 passed | 1 failed | 2 expected fail | 443 skipped.npm run build) succeeds in 6.01s, re-run after the last edit;distcontains the fix.One failure, disclosed, proven unrelated
mcp-daemon.test.ts#1963: daemon exit times out within 1500ms after SIGTERM, in the full-suite run only. It is not a regression from this change:rootCheckTimerisunref'd and only fires when the root is gone (it does not trigger while the root exists), and thetry/finallyinstop()takes the exact same cleanup path whenengine.stop()does not throw.