Repository navigation
fix(daemon): stop counting zombie sidecar leaders as alive - #3302
Closed
github-actions[bot] wants to merge 1 commit into
Closed
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
The ledger's startup reaper treated an unreaped (zombie) sidecar leader as a live process, so it took the cmdline-identity branch, failed to match a zombie's empty cmdline, and logged "pid reused, leaving it alone" — the re-parented child still holding the port was never cleaned up. Zombies now route to the group-kill branch that exists for exactly that case. _pid_alive now delegates to gaia.daemon.instance.pid_alive, the same helper #3229 adopted in sidecars/registry.py, including its AccessDenied -> pid_exists fallback: a pid we cannot inspect is one we also cannot safely kill, and the cmdline gate below already fails closed for it. Closes #3300
3 tasks
itomek
added a commit
that referenced
this pull request
Sep 2, 2026
#3302 fixed #3300 independently while this branch was in flight. Its version is better in three ways, so take it wholesale rather than keep mine: - it pins os.name to "posix", without which the assertion would fail on Windows, where the dead-leader branch returns before the group-kill - it tests _pid_alive directly in both directions, not only through the reaper, which is the tighter regression anchor - it updates the reap_stale docstring, which the behaviour change had otherwise left describing the old classification #3302 is superseded by this branch and closed.
Collaborator
|
Superseded by #3229, which now carries this fix — closing. Your implementation was better than the one #3229 had, so I took yours wholesale rather than keep mine: the The two landed together in #3229 because they're the same bug in the same subsystem — the stop path and the reap path both counted a zombie as alive. |
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.
If the daemon was killed while a sidecar's leader process had exited but not yet been reaped, the next daemon start left the sidecar's orphaned child running and holding its port. The startup reaper counted that zombie leader as "alive", took the wrong branch, logged "pid reused, leaving it alone", and skipped the group-kill recovery that exists for exactly this situation — so the port stayed occupied and the next spawn had to work around it. Zombies now correctly read as dead and get cleaned up.
Closes #3300
Test plan
python -m pytest tests/unit/test_daemon_agents_routes.py -xpasses (includes two new tests that fail against the old implementation)python -m pytest tests/unit/ -xpassespython util/lint.py --allpasses🔍 Technical details
Root cause.
_pid_aliveinsrc/gaia/daemon/sidecars/ledger.pywas a barepsutil.pid_exists(), which returnsTruefor a zombie. Inreap_stalethe zombie then took the live-pid branch, failed_cmdline_matches(a zombie's cmdline is empty on Linux), and fell through to the "pid reused" log — never reaching the_group_kill(pid)branch designed for "leader died, re-parented child survives".Fix.
_pid_alivenow delegates togaia.daemon.instance.pid_alive, the same helper #3229 adopted insidecars/registry.py. That includes itsAccessDenied→pid_existsfallback, which is the right call here too: a pid we can't inspect is one we also can't safely kill, and the cmdline gate below already fails closed for it._pid_alivestays a function so it remains the monkeypatch seam the existing reap tests use. Thereap_staledocstring now says a zombie counts as dead.Tests (
tests/unit/test_daemon_agents_routes.py):test_pid_alive_excludes_zombiespins the helper directly;test_reap_stale_zombie_leader_takes_the_group_kill_pathruns the real_pid_aliveagainst a fakedpsutiland asserts the group-kill path. Both fail on the pre-fix implementation — verified by stashing the source change and re-running.Out of scope, as the issue notes: the copies in
eval/sidecar_harness.pyandeval/runner.pyare lock-holder checks where treating an uncertain pid as alive is the deliberate safe direction.