Option to watch fs events for subdirs separately from root dir#1329
Open
bvinc wants to merge 4 commits into
Open
Option to watch fs events for subdirs separately from root dir#1329bvinc wants to merge 4 commits into
bvinc wants to merge 4 commits into
Conversation
When set, the notify file watcher registers a recursive watch for each non-ignored top-level subdirectory of the project root rather than a single recursive watch on the root itself. Ignored top-level directories (e.g. buck-out) are never registered with the watcher backend. Defaults to false; existing behavior is unchanged.
When watch-included-root-dirs-only is enabled, `rescan_root` runs on every sync and tracks (size, mtime) of non-ignored top-level files. Modifications, creations, and removals at the project root are synthesized as events and merged into notify's stream. New top-level directories created mid-session are picked up by the same scan and registered for recursive watching. Adds two debug logs: * a new root subdirectory has a watch registered * a root-level file was modified
Cover the state transitions: ignored dir filtered at startup, ignored dir appearing mid-session stays invisible, new top-level dir is reported with a watch, root file modified/removed, top-level dir removed, no-op on a clean rescan.
Contributor
|
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this in D106542582. (Because this pull request was imported automatically, there will not be any future comments.) |
cormacrelf
reviewed
May 28, 2026
| let watch_included_root_dirs_only = root_config | ||
| .parse::<bool>(BuckconfigKeyRef { | ||
| section: "project", | ||
| property: "watch-included-root-dirs-only", |
Contributor
There was a problem hiding this comment.
Snake case for buckconfig keys isn't it? Also maybe bike shed it a bit more
Contributor
There was a problem hiding this comment.
I really wish you could grep BuckconfigKeyRef::new and get a big list of all of them to see where you might put a new one and what you might name it. But it ain't so.
`rescan_root` already detects when a previously-watched top-level subdirectory disappears and emits a synthetic `Remove(Folder)` event, but the matching `notify` watch was never released. On Linux this is masked by inotify auto-removing the watch in response to `IN_IGNORED`. On macOS (fsevent) and Windows (ReadDirectoryChangesW) there is no such auto-cleanup, so a long-running daemon would slowly leak watch handles as workspace subdirs are created and destroyed. Have `rescan_root` return the set of vanished directories alongside the existing `new_watches`, and unwatch them from `sync2`. Swallow `WatchNotFound` since it's the expected case on Linux. Bundle the return values into a `RescanResult` struct so the signature scales to a future fourth field without breaking call sites.
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.
This creates a new project setting "watch-included-root-dirs-only" which watches subdirectories at the root level separately. This allows real ignoring of the buck-out folder, which makes the possibility of missing fs change events much less likely.
This is the most important on mac, where fsevent has no knobs to turn, and no way to really ignore the buck-out folder. Without this change, large builds will easily and consistently overflow the internal fsevent buffers and cause file system events to be missed. After this change, almost no events happen, as changes outside of the buck-out folder are rare.
Unfortunately, this requires manual non-recursive polling of the root directory occasionally. I chose to put this in calls to sync2, which usually happen once at the beginning of a build.