Prevent archival of manually-created worktrees - #58275
Merged
Merged
Conversation
rtfeldman
force-pushed
the
AI-352/worktree-archive-provenance
branch
2 times, most recently
from
June 1, 2026 22:01
9259a21 to
7422d1c
Compare
rtfeldman
force-pushed
the
AI-352/worktree-archive-provenance
branch
from
June 1, 2026 22:15
7422d1c to
aec08a8
Compare
|
Just a question, would this mark worktrees created from the interface but unrelated to an agent chat? I create my worktrees within Zed a lot of the time, but I wouldn't personally want them to be archived when closing an agent chat as they weren't created for that agent. Or is this case too niche? Thanks for the hard work! You guys are making my life better every day |
Instead of writing a marker file into the worktree's git metadata directory, record each Zed-created worktree in the local database along with the creation time of its gitdir. Before deleting a worktree during thread archival, re-stat the gitdir and refuse to delete if the time doesn't match (the worktree was recreated outside Zed) or can't be read. All failure modes leave the directory untouched. This also replaces the is_zed_managed_worktree snapshot/proto plumbing with a GitWorktreeCreatedAt request so the stat runs on the remote host for SSH projects.
rtfeldman
marked this pull request as ready for review
June 16, 2026 14:27
tomhoule
approved these changes
Jun 16, 2026
This was referenced Jun 18, 2026
Closed
This was referenced Jul 1, 2026
jolutz
pushed a commit
to jolutz/zed
that referenced
this pull request
Aug 8, 2026
This fixes archive cleanup for agent threads so Zed only removes worktrees it explicitly created, rather than treating every linked worktree under the configured managed directory as safe to delete. When Zed creates a worktree, it now records it in the local database along with the creation time of the worktree's git metadata directory (`.git/worktrees/<name>/`). Archive planning requires that record, and right before deleting anything, Zed re-stats the directory and compares creation times: if the worktree was removed and recreated outside Zed (or the time can't be read at all), deletion is skipped and the stale record is dropped. Every failure mode fails safe by leaving the directory untouched. For remote (SSH) projects, the stat runs on the remote host via a new `GitWorktreeCreatedAt` request. Worktrees created by a different Zed install (another release channel, or another machine connecting to the same host) have no record in the local database and are therefore never auto-archived, which is the intended conservative behavior. Closes zed-industries#57155 Closes AI-352 Release Notes: - Fixed archiving an agent thread incorrectly deleting manually-created git worktrees.
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 fixes archive cleanup for agent threads so Zed only removes worktrees it explicitly created, rather than treating every linked worktree under the configured managed directory as safe to delete. When Zed creates a worktree, it now records it in the local database along with the creation time of the worktree's git metadata directory (
.git/worktrees/<name>/). Archive planning requires that record, and right before deleting anything, Zed re-stats the directory and compares creation times: if the worktree was removed and recreated outside Zed (or the time can't be read at all), deletion is skipped and the stale record is dropped. Every failure mode fails safe by leaving the directory untouched.For remote (SSH) projects, the stat runs on the remote host via a new
GitWorktreeCreatedAtrequest. Worktrees created by a different Zed install (another release channel, or another machine connecting to the same host) have no record in the local database and are therefore never auto-archived, which is the intended conservative behavior.Closes #57155
Closes AI-352
Release Notes: