worktree: Include file size in DiskState to fix stale buffer reload#48691
Closed
lex00 wants to merge 2 commits intozed-industries:mainfrom
Closed
worktree: Include file size in DiskState to fix stale buffer reload#48691lex00 wants to merge 2 commits intozed-industries:mainfrom
lex00 wants to merge 2 commits intozed-industries:mainfrom
Conversation
This was referenced Feb 7, 2026
Contributor
Contributor
Author
|
Good catch, you're right. Updated to "Related to" instead. Thanks! |
Contributor
When an external tool writes a file using `std::fs::write()` (truncate +
write), the scanner can read the 0-byte file during the truncation window.
The buffer reloads to empty. If the subsequent write produces the same
mtime, `file_updated()` sees no DiskState change and never triggers a
second reload — the buffer is permanently stuck empty.
Add `size: u64` to `DiskState::Present { mtime, size }`. The derived
PartialEq now detects size changes even when mtime matches, so a 0-to-N
byte transition always triggers ReloadNeeded. The scanner already tracks
file size in `Entry.size` — this threads it through `File::for_entry()`
and `local_worktree_entry_changed()` into the reload comparison.
Remote/collab callers pass `size: 0` since remote buffers don't make
local reload decisions.
Closes zed-industries#38109
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7ad2d06 to
399e9df
Compare
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
This was referenced Mar 8, 2026
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.
Related to #38109
When an external tool writes a file using
std::fs::write()(truncate + write), the scanner can read the 0-byte file during the truncation window. The buffer reloads to empty. If the subsequent write produces the same mtime,file_updated()sees noDiskStatechange and never triggers a second reload. The buffer is permanently stuck empty.Adds
size: u64toDiskState::Present { mtime, size }. The derivedPartialEqnow detects size changes even when mtime matches, so a 0→N byte transition always triggersReloadNeeded. The scanner already tracks file size inEntry.size, this threads it throughFile::for_entry()andlocal_worktree_entry_changed()into the reload comparison.Remote/collab callers pass
size: 0since remote buffers don't make local reload decisions (the reload path checks!self.is_via_collab()).Root cause analysis: #38109 (comment)
Related issues:
Note: the two RealFs tests use
allow_parking()+flush_fs_events()and must be run individually (--exact), not in parallel with other RealFs tests. This matches the existing pattern in the crate.Release Notes: