fix(mcp): reap dropped daemon children without leaking pending exit statuses - #1371
Open
ohdearquant wants to merge 3 commits into
Open
fix(mcp): reap dropped daemon children without leaking pending exit statuses#1371ohdearquant wants to merge 3 commits into
ohdearquant wants to merge 3 commits into
Conversation
… spawn Positively reap owned exited daemon children via waitpid(WNOHANG) in the exit-wait path, keeping the ps-based zombie check for non-owned PIDs, and re-probe daemon identity after a successful kill while holding the boot lock so a healthy replacement spawned by a concurrent peer is never double-spawned. Regression tests cover both behaviors. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…est fixture process_is_alive could report a child dead via the ps zombie check without reaping it: when the child exited between the waitpid(WNOHANG) probe and the ps stat read, the exit status stayed pending for the life of the process. Reap on the zombie branch before returning; non-children fail with ECHILD and are left for their own parent. The kill_and_respawn_skips_spawn_when_peer_replaces_daemon_during_incumbent_wait fixture held KHIVE_LOCK across an await on the incumbent exit gate while run_daemon blocked acquiring the same lock, deadlocking the serial test convoy. Bind the replacement probe socket directly and serve acks from the already-bound listener instead of driving a full run_daemon. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…stant Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ohdearquant
marked this pull request as ready for review
July 24, 2026 02:24
ohdearquant
enabled auto-merge (squash)
July 24, 2026 02:26
ohdearquant
disabled auto-merge
July 24, 2026 12:22
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.
Closes #1271.
Two defects in the daemon replacement path:
Zombie exit statuses left pending.
forward_or_spawndrops theChildhandle for a killed incumbent without callingwait().process_is_alivenow reaps viawaitpid(WNOHANG)on its probe path, and also on theps-stat zombie branch: previously a child that exited between theWNOHANGprobe and thepsread was reported dead without being reaped, leaving its exit status pending for the life of the process. Non-children fail withECHILDand are left for their own parent.Replacement-race test fixture deadlock. The peer-replacement test held
KHIVE_LOCKacross an await on the incumbent exit gate whilerun_daemonblocked acquiring the same lock, wedging the serial test convoy (suite hung ~20 min). The fixture now binds the replacement probe socket directly and serves acks from the already-bound listener.Verification:
cargo test -p khive-mcp259+90 green in 46s (previously deadlocked); the reap regression test passes 8/8 consecutive runs (previously 1/5); clippy-D warningsand fmt clean.