Skip to content

watch: ignore read-only inotify events (opened / closed_no_write) so the watcher does not re-trigger on its own reads - #7

Merged
Azeem1985 merged 3 commits into
v8from
fix/watch-ignore-read-only-events
Aug 24, 2026
Merged

Azeem1985 merged 3 commits into
v8from
fix/watch-ignore-read-only-events

Conversation

@Azeem1985

Copy link
Copy Markdown

What

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 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

Azeem and others added 3 commits August 23, 2026 11:53
…) 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).
@Azeem1985
Azeem1985 merged commit f3881b4 into v8 Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant