fix(watch): exit when the observer emitter thread dies silently - #879
Open
yzxcj797 wants to merge 1 commit into
Open
fix(watch): exit when the observer emitter thread dies silently#879yzxcj797 wants to merge 1 commit into
yzxcj797 wants to merge 1 commit into
Conversation
code-review-graph reviewOverall risk: 0.35 (LOW) — 11 changed function(s)/class(es), 0 affected flow(s), 4 test gap(s) Risk-scored changes
Test gaps
Token savings: this graph-backed report used ~31,387 fewer tokens (~93%) than reading every changed file in full (estimated, chars/4 approximation). Powered by code-review-graph — local-first analysis; no code leaves the CI runner. |
A watchdog emitter reader thread can crash under heavy create/delete churn (the inotify _wd_for_path KeyError on Maven target/, or the ReadDirectoryChangesW equivalent on Windows) while the observer thread itself stays alive. The child process then keeps passing the daemon's poll-based health check while delivering no filesystem events, so the graph silently freezes (tirth8205#811). The watch loop now checks the observer and every emitter thread each second. On death it logs critical and exits the child with SystemExit(1), letting the daemon's existing restart path recover instead of serving a stale built_at_sha indefinitely.
yzxcj797
force-pushed
the
fix/811-watch-observer-death
branch
from
August 19, 2026 06:18
fc4ba2e to
22ec5c3
Compare
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
A watchdog emitter reader thread can crash under heavy create/delete churn — the inotify
_wd_for_pathKeyErrorwhen Maven Surefire forks churntarget/surefire/, or the WindowsReadDirectoryChangesWvariant (both documented in #811) — while the observer thread itself stays alive. The child process keeps passing the daemon'sproc.poll()-based health check while delivering no filesystem events:daemon statusstays green,built_at_shafreezes, and every subsequent edit/git pullis missed until a manual restart.The watch loop now checks
_observer_threads_alive(observer)— the observer thread and every emitter thread — once per second. On the first dead thread it logscriticaland raisesSystemExit(1), exiting the child so the daemon's existing restart path recovers watch instead of silently serving a stale graph forever.This deliberately implements the issue's fix option 2 (exit so poll-based health checks catch it) rather than option 1 (per-subdirectory scheduling): it covers both the Linux and Windows thread variants, and the reproducer requires churn that a Windows-CI test cannot drive. A follow-up can layer schedule-time ignore filtering on top without conflicting.
Testing
TestWatchObserverLiveness(3 cases): alive observer + alive emitter → healthy; dead observer → not healthy; dead emitter with alive observer → not healthy (the exact silent-death shape from watch: observer thread silently crashes on Maven target/ dir churn (KeyError in watchdog inotify) — daemon looks alive but stops updating #811).pytest tests/test_graph.py tests/test_incremental.py— 178 passed (2 symlink-privilege tests deselected, the same pre-existing Windows-environment limitation noted in fix(incremental): reconcile reverted file content #860/fix(graph): purge orphan rows during reconciliation #861/fix(graph): survive malformed extra JSON in get_all_files #870).ruff check code_review_graph/incremental.py tests/test_incremental.py— all checks passed.Verification boundary: the end-to-end kill (driving a real inotify race under Maven churn) requires the Linux/WSL environment from the report; the unit tests pin the liveness predicate and the exit decision it feeds.
Fixes #811