Skip to content

worktree: Close single-file worktrees when file is deleted#49366

Merged
probably-neb merged 1 commit intozed-industries:mainfrom
dastrobu:worktree-fix-deleted-single-file
Mar 31, 2026
Merged

worktree: Close single-file worktrees when file is deleted#49366
probably-neb merged 1 commit intozed-industries:mainfrom
dastrobu:worktree-fix-deleted-single-file

Conversation

@dastrobu
Copy link
Copy Markdown
Contributor

@dastrobu dastrobu commented Feb 17, 2026

When a single-file worktree's root file no longer exists, the background scanner would previously enter an infinite retry loop attempting to canonicalize the path. This caused continuous error logging and resource waste.

This fix detects when a single-file worktree root cannot be canonicalized (after attempting the file handle fallback) and emits a new Deleted event, allowing the worktree to be properly closed.

This is most commonly encountered with temporary files, logs, and similar files that are opened in Zed and then deleted externally, but persist in the workspace database across sessions.

Closes #34864

Test

Logs from manual testing:

2026-02-17T16:16:11+01:00 INFO  [worktree] inserting parent git repo for this worktree: "tmp.md"
2026-02-17T16:16:17+01:00 ERROR [worktree] root path could not be canonicalized: canonicalizing "/Users/***/tmp/tmp.md": No such file or directory (os error 2)
2026-02-17T16:16:17+01:00 INFO  [worktree] single-file worktree root "/Users/***/tmp/tmp.md" no longer exists, marking as deleted
2026-02-17T16:16:17+01:00 INFO  [worktree] worktree root /Users/***/tmp/tmp.md no longer exists, closing worktree

Release Notes:

  • Fixed an issue where Zed would enter an infinite retry loop when the backing file for a single-file worktree was deleted

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 17, 2026
@dastrobu dastrobu force-pushed the worktree-fix-deleted-single-file branch from c3a39e4 to 249f70e Compare March 6, 2026 06:59
@dastrobu
Copy link
Copy Markdown
Contributor Author

dastrobu commented Mar 6, 2026

rebased onto current main.

When a single-file worktree's root file no longer exists, the background
scanner would previously enter an infinite retry loop attempting to
canonicalize the path. This caused continuous error logging and resource
waste.

This fix detects when a single-file worktree root cannot be canonicalized
(after attempting the file handle fallback) and emits a new Deleted event,
allowing the worktree to be properly closed.

This is most commonly encountered with temporary files, logs, and similar
files that are opened in Zed and then deleted externally, but persist in
the workspace database across sessions.

Closes zed-industries#34864

Release Notes:

- Fixed Zed continuously logging errors and wasting resources when a
  single-file buffer references a deleted file (commonly tmp files, logs).
  The worktree now closes properly when the file no longer exists.
@dastrobu dastrobu force-pushed the worktree-fix-deleted-single-file branch from 249f70e to 27a703e Compare March 13, 2026 17:12
@probably-neb
Copy link
Copy Markdown
Collaborator

Thanks for fixing!

@probably-neb probably-neb merged commit 03c5d37 into zed-industries:main Mar 31, 2026
29 checks passed
@dastrobu dastrobu deleted the worktree-fix-deleted-single-file branch April 1, 2026 08:18
@probably-neb
Copy link
Copy Markdown
Collaborator

@zed-zippy approved

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zed goes crazy when a buffer points to a nonexistent file in /tmp/.

2 participants