fix: wait for daemon health before reclaiming occupied port - #1858
Merged
nicoloboschi merged 1 commit intoMay 29, 2026
Conversation
Contributor
Author
|
The failing check appears to be a transient dependency download issue in The job failed while Cargo was updating the crates.io registry: The local checks I ran before opening the PR completed successfully:
|
nicoloboschi
approved these changes
May 29, 2026
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.
Summary
/healthreturns Hindsight's initialized health payload.Reproduction
A concurrent daemon start can bind the profile port before
/healthis ready. The previous_clear_portbehavior checked health once, saw the warming daemon as unhealthy/non-Hindsight, and moved into PID lookup/reclaim instead of waiting for the daemon to finish starting.The regression coverage reproduces that race deterministically without real services or private data:
_is_port_in_use(port)returnsTrue./healthresponses are simulated as503,503, then200with{"status": "healthy", "database": "connected"}.Falseafter the first health probe and calls_find_pid_on_port.Truewhen the daemon becomes healthy, and does not call_find_pid_on_portor_kill_process.Fix
HINDSIGHT_EMBED_PORT_HEALTH_GRACE_TIMEOUTHINDSIGHT_EMBED_PORT_HEALTH_CHECK_INTERVALTest Plan
uv run pytest tests/test_daemon_client.py::TestClearPort -quv run pytest tests/test_embed_manager.py -quv run pytest -quv run ruff check hindsight_embed/daemon_embed_manager.py tests/test_daemon_client.pygit diff --check --cached -- hindsight-embed/hindsight_embed/daemon_embed_manager.py hindsight-embed/tests/test_daemon_client.py