Repository navigation
Restore a deleted thread worktree from its preserved branch - #1622
Conversation
A thread whose worktree folder vanished (hand delete, `git worktree remove`, or retention GC) now resumes on its retainedBranch at its tip instead of a suffixed branch cut from the start snapshot, which dropped every commit made on the old branch. A missing ref fails with an actionable error and keeps the flags; retainedBranch clears only after the checkout succeeds. gcClean also re-arms pendingWorktree so a GC'd thread no longer falls back to the project checkout (#511). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 777e3580ea
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| // A worktree lost to GC or a hand delete resumes on its own branch, not a | ||
| // fresh one from the start snapshot that would drop its commits (#1400). | ||
| const retained = thread.retainedBranch || null; |
There was a problem hiding this comment.
Clear retained refs when moving threads between projects
When GC has removed a thread's worktree, the thread has worktreePath: null, pendingWorktree: true, and a retainedBranch belonging to its original repository. setThreadProject permits that thread to move, deliberately preserves pendingWorktree, and clears other repository bindings but not retainedBranch; the next send therefore treats the old branch name as a branch in the destination repository and either fails permanently at this check or, if a same-named branch exists, restores unrelated history. Clear retainedBranch as part of project recategorization, or otherwise associate it with and validate its source project.
Useful? React with 👍 / 👎.
macOS CI failed the afterEach with ENOTEMPTY: the store's async flush dropped a .tmp into messages/ while rmSync was deleting the tree. Use the shared rmTree helper, which retries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What changed
If a thread's worktree folder disappeared (deleted by hand, removed with
git worktree remove, or cleaned up by retention GC), the next run created a new branch with a suffixed name, cut from the start snapshot. Every commit on the old branch was left out. Now the thread picks up where it stopped, on itsretainedBranchat the tip (#1400).electron/worktrees-lifecycle.js:setupWorktreeretainedBranch, the worktree is checked out from that branch withgit worktree add <path> <branch>. It no longer creates a new branch fromresolveWorktreeStart, and it doesn't claim a pooled worktree.git worktree prunefirst so the deleted folder's stale registration doesn't block the checkout. If the branch is checked out in a live worktree, git's own error is still shown unchanged.refs/heads/<retainedBranch>no longer exists, setup fails with a clear error: either recreate the branch (git branch <name> <commit>) or continue in a new thread. The thread's flags stay as they were.retainedBranchis cleared only after the checkout succeeds. Failures readFailed to restore branch <name>rather thanFailed to create worktree, and still include git's full stderr (Worktree creation failure must never silently run the agent in the main checkout #511).electron/worktrees-gc.js:gcCleanpendingWorktree: truenext toretainedBranch. The next run then restores that branch instead of falling back to the project checkout.Tests
electron/test/worktree-cleanup.test.js: covers rematerializing from a retained branch and the error when the branch is missing.electron/test/worktree-gc.test.js: checks thatgcCleansetspendingWorktreealong withretainedBranch.🤖 Generated with Claude Code