# worktree: Close single-file worktrees when file is deleted \(\#49366\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/03c5d379724e4b2e74418be6c7ec706eb7d44033)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 03c5d379724e4b2e74418be6c7ec706eb7d44033

Requested commit: 03c5d379724e4b2e74418be6c7ec706eb7d44033

Commit: 03c5d379724e4b2e74418be6c7ec706eb7d44033

Tree: 593fb22df80a24258b20f99efd877da83e9ce865

Author: Daniel Strobusch

Committer: GitHub

## Message

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

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
````

## Parents

- [88d12750feaa05429ec64ac5fe96f885c1c1f0bf](https://git.cafe/gitcafe/zed/commit/88d12750feaa05429ec64ac5fe96f885c1c1f0bf?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/03c5d379724e4b2e74418be6c7ec706eb7d44033?format=markdown)
