Repository navigation
fix(watch): ignore read-only inotify events so the watcher stops re-triggering on its own reads - #3070
fix(watch): ignore read-only inotify events so the watcher stops re-triggering on its own reads#3070Azeem1985 wants to merge 1 commit into
Conversation
…riggering on its own reads On Linux, watchdog >= 2.3 emits `opened` and watchdog >= 4 emits `closed_no_write` for every file open/close. `on_any_event` counted both as file changes — so the watcher's own AST rebuild, which reads every watched file, re-triggered the watcher, which rebuilt, which read the tree again. A permanent loop: "N file(s) changed" printed while nothing was modified. Measured on a ~1,700-file tree: ~26 CPU-minutes per hour, 15 memory-kills in 3 days, and the `needs_update` flag rewritten every 1-3 minutes. `_is_read_only_event` drops exactly those two event types. Creation, modification, move, deletion and close-after-write still count, so no real change is missed. macOS uses PollingObserver, which never emits these events, so the filter is a no-op there. Tests: read-only events ignored, write/create/delete/move still trigger.
There was a problem hiding this comment.
Graphify reviewed this change.
Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).
Formal verification. No changes could be formally verified in this run.
Graphify review — findings
Filters read-only inotify events out of graphify watch: on_any_event now drops opened (watchdog ≥ 2.3) and closed_no_write (watchdog ≥ 4) via _is_read_only_event, so the watcher's own AST rebuild reading every file no longer re-triggers the watcher in a permanent loop. Creation, modification, move, deletion and close-after-write still count as changes, and macOS's PollingObserver never emits these events so the filter is a no-op there.
No blocking issues surfaced.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 709 functions depend on the 547 functions this change touches.
Health — this change adds coupling hotspots:
- new:
_rebuild_code()— 98 callers, 50 callees - new:
dispatch_command()— 2 callers, 122 callees - new:
watch()— 5 callers, 7 callees - new:
_reconcile_graph_html()— 6 callers, 5 callees - new:
_reconcile_existing_graph()— 1 callers, 7 callees - new:
test_poisoned_manifest_is_healed()— 0 callers, 6 callees
Verification — 709 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 559 function(s) in the blast radius were not formally verified this run
Formal verification
Could not verify: Could not verify on\_any\_event.
The verifier did not have enough to check on\_any\_event, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: method — first parameter is `self`, which needs a constructed instance (not synthesizable)
Could not verify: Could not verify watch.
The verifier did not have enough to check watch, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: parameter `watch_path` is annotated `Path` — outside the synthesizable primitive/collection set
· 6 more finding(s) on lines outside this diff (see the check run).
|
Independent reproduction, same root cause — confirming this from a separate codebase before you land it. We hit this in a Docker dev container (Debian bookworm, graphifyy 0.9.49, watchdog 6.0.0) on an ~876-file repo: Confirmed it's the read events, not writes. A probe that only read a source directory, touching nothing: And a probe placed on the handler during a single Matches your analysis exactly, including why it's invisible on macOS: Our workaround (until this ships) drops the same two event types, just one level higher — in Keeping +1 on merging. Happy to test a pre-release against our repo if that's useful. |
|
Thanks — an independent reproduction from a second codebase is exactly what this needed, and yours covers the environment mine couldn't: a Docker dev container, watchdog 6.0.0, and a polyglot repo where the loop starves neighbouring dev servers rather than just burning a core. Your pure-read probe ( Your stopgap is sound: dropping the same two event types in Taking you up on the test offer — this branch installs directly with: If your 876-file container repo shows 1 edit → 1 rebuild and an idle watcher between edits on that build, a one-line note here would give the maintainers a third independent datapoint (bare metal, scratch rig, and your container). |
|
Shipped in v0.9.50 via authorship-preserving cherry-pick so you keep contributor-graph credit. Thanks @Azeem1985! Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.50 |
|
Thanks @safishamsi — confirmed the read-only-event filter is in the v0.9.50 tag, and the authorship-preserving cherry-pick is appreciated. |
Replaces #2969, which is the same fix but was opened from a branch that also carried unrelated work from our fork — 13 files and 25 commits, when the change itself is one function. That was my mistake in how I cut the branch, not a change in what I am proposing. This branch is cut from
v8and carries only the fix. #2969 is being closed with a pointer here.The defect
On Linux, watchdog >= 2.3 emits
openedand watchdog >= 4 emitsclosed_no_writefor every file open and close.Handler.on_any_eventcounted both as file changes.The watcher's own AST rebuild reads every watched file. So: rebuild reads the tree → inotify reports
opened/closed_no_writefor each file → the watcher counts them as changes → it rebuilds → it reads the tree again. A permanent loop that printsN file(s) changedwhile nothing was modified.Hook guards that stat sources, editors, and agents reading files feed the same loop.
Measured
On a ~1,700-file tree, over 3 days:
needs_updateflag rewrittenAfter the fix the watcher is idle between real edits.
The change
_is_read_only_event(event)returns True for exactlyopenedandclosed_no_write;on_any_eventreturns early on those, next to its existingis_directoryearly return.Creation, modification, move, deletion and close-after-write (
closed) all still count, so no real change is missed. macOS usesPollingObserver, which never emits these event types, so the filter is a no-op there.Diff
3 files:
graphify/watch.py(+20/-1),tests/test_watch.py(+29),CHANGELOG.md(+4).tests/test_watch.pypasses 130/130.