Skip to content

fs: Handle removed Linux watch paths#47462

Closed
iNViTiON wants to merge 3 commits intozed-industries:mainfrom
iNViTiON:fix-broken-watcher
Closed

fs: Handle removed Linux watch paths#47462
iNViTiON wants to merge 3 commits intozed-industries:mainfrom
iNViTiON:fix-broken-watcher

Conversation

@iNViTiON
Copy link
Copy Markdown

fs_watcher failed to track change of removed watching path on Linux. Turns out that the removed directory broke the watcher by treating newly created same-named directory as different one.
This PR track those watching but removed directory in order to re-register the watcher.

Closes #46580 #46709

Release Notes:

  • Fixed broken watcher that make the Project/Git Panel to not showing updated content and displaying an incorrect list of files.

Stable release on the left | This PR build on the right
Project Panel after running issue reproducer script.
image

Git Panel after running issue reproducer script.
image

Copilot AI review requested due to automatic review settings January 23, 2026 10:20
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Jan 23, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @iNViTiON on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Jan 23, 2026
@iNViTiON
Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 23, 2026
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Jan 23, 2026

The cla-bot has been summoned, and re-checked this pull request!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the Linux filesystem watcher where changes to directories that were removed and then recreated with the same name were not being detected. The issue occurs because inotify watches on Linux become invalid when a directory is deleted, and the watcher needs to be re-registered for a newly created directory with the same path.

Changes:

  • Added tracking of removed watched paths on Linux using a HashSet
  • Modified the add logic to detect when a path was previously removed and re-register the watcher
  • Updated the remove event handler to mark paths as removed when they are deleted

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AdamJedl
Copy link
Copy Markdown
Contributor

There are already two pull requests that fix this same issue, each in a different way.
#46036
#47099

I don't know what is the best way.

The tests in my pull request also passed with these changes.

I don't think this closes issue #46580 or #46709 or #38109, because there are multiple issues with file watching. For example, it doesn't handle rescan events and it doesn't work on filesystems that don't support notify events, see https://github.com/lilith/zed/tree/feature/pollwatcher-support.

@iNViTiON
Copy link
Copy Markdown
Author

Thanks @AdamJedl. I missed these PRs!
I took a look at the changes. I think the watcher issue should be handled in the same module, since we can’t assume only worktree usage will hit it.
That said, this PR looks very similar to #47099, with the added optimization of an early return when re-registering isn’t necessary.

@maxdeviant maxdeviant changed the title fix(fs): Handle removed Linux watch paths fs: Handle removed Linux watch paths Jan 23, 2026
@iNViTiON iNViTiON force-pushed the fix-broken-watcher branch 2 times, most recently from 0eaf256 to 62225d6 Compare February 5, 2026 06:31
pcfreak30 added a commit to pcfreak30/zed that referenced this pull request Feb 13, 2026
Applied 5 PRs to fix Zed getting out of sync with filesystem changes:
- zed-industries#48691: Include file size in DiskState to fix stale buffer reload
- zed-industries#48695: Map EventKind::Other to Changed instead of None
- zed-industries#48698: Reload after undo when file changed while dirty
- zed-industries#48704: Rescan repositories when window regains focus
- zed-industries#47462: Handle removed Linux watch paths
Track paths that were removed on Linux to work around inotify behavior.
Add a removed_paths HashSet and mark a path when a Remove event contains
the watched root. If a subsequent add finds the path already registered
but marked removed, remove the old registration before re-adding.
Initialize and clone removed_paths into the watcher callback.
@iNViTiON
Copy link
Copy Markdown
Author

I just added the integration test that failed with the current code and pass with this fix.
Apologize for not doing this from the start.

@iNViTiON
Copy link
Copy Markdown
Author

iNViTiON commented Mar 3, 2026

Sorry to nagging you a bit @probably-neb . But last week I found the CI test were running for one time, but after I fix the code, it's not running again. Do I have to trigger it somehow?

@iNViTiON
Copy link
Copy Markdown
Author

iNViTiON commented Mar 3, 2026

The test failed for unused import on Windows and macOS. Fixed by doing conditional import only on Linux. cc @probably-neb

@probably-neb
Copy link
Copy Markdown
Collaborator

Hey @iNViTiON, thanks for trying to fix this. I think your solution works, however, I've decided to go with #50412 as it's a less heavy-handed solution and passes your tests as well.

@iNViTiON
Copy link
Copy Markdown
Author

iNViTiON commented Mar 3, 2026

Thanks @probably-neb . That's one look straighter forward than this one and I favor that more too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zed doesn't track newly created files/folders made by a script

5 participants