Repository navigation
watch: ignore read-only inotify events (opened / closed_no_write) so the watcher does not re-trigger on its own reads - #7
Merged
Conversation
…) so the watcher does not re-trigger on its own reads On Linux, watchdog's inotify observer reports `opened` (watchdog >= 2.3) and `closed_no_write` (watchdog >= 4) for every file open/close. `Handler.on_any_event` counted those as changes, so the watcher's own AST rebuild — which reads every watched file — re-triggered the watcher: a debounce window later it printed "1683 file(s) changed" with nothing modified, rebuilt again, and so on. Measured on a 17k-node, ~1.7k-file tree: ~26 CPU-minutes per hour, 15 memory-kills of the watcher in 3 days (it restarts and loops again), and the `needs_update` flag re-written every 1-3 minutes after any doc edit, which permanently softens `hook-guard read --strict` (cli.py checks the stale flag before the strict check). Fix: a small helper `_is_read_only_event` returns True for `opened` / `closed_no_write`; the handler ignores those. Creation, modification, move, deletion and close-after-write still count. macOS (PollingObserver) never emits these, so nothing changes there. Tests: two new tests in tests/test_watch.py (plain objects, and the real watchdog event classes when available).
Co-Authored-By: Claude Fable 5 <[email protected]>
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.
What
On Linux, watchdog's inotify observer reports
opened(watchdog >= 2.3) andclosed_no_write(watchdog >= 4) for every file open/close.Handler.on_any_eventcounted those as changes, so the watcher's own AST rebuild — which reads every watched file — re-triggered the watcher: a debounce window later it printed "1683 file(s) changed" with nothing modified, rebuilt again, and so on.Measured on a 17k-node, ~1.7k-file tree: ~26 CPU-minutes per hour, 15 memory-kills of the watcher in 3 days (it restarts and loops again), and the
needs_updateflag re-written every 1–3 minutes after any doc edit, which permanently softenshook-guard read --strict(cli.py checks the stale flag before the strict check).Fix
A small helper
_is_read_only_eventreturns True foropened/closed_no_write; the handler ignores those. Creation, modification, move, deletion and close-after-write still count. macOS (PollingObserver) never emits these events, so nothing changes there. Same fix as proposed upstream in graphify PR Graphify-Labs#2969; this ports the patch already running on the TELB-COCKPIT box so a reinstall from this repo does not resurrect the loop.Tests
Two tests in
tests/test_watch.py: plain event objects, and the real watchdog event classes when available.🤖 Generated with Claude Code