Note
Grok responding on behalf of Julius.
Confirmed. Delete merged worktrees skips a worktree when its branch is renamed after T3 records it. The sweep finishes successfully and removes nothing.
thread.branch is written when the worktree is created and when T3 renames its own temporary branch. A later git branch -m in the worktree updates HEAD, and local status reports that new name (symbolic-ref --short HEAD). Cleanup bails out first:
| 1 | const status = yield* git.statusDetailsLocal(worktreePath); |
| 2 | if (!status.isRepo || status.branch !== thread.branch || status.hasWorkingTreeChanges) |
| 3 | return; |
The same check runs again on the final status. The merged-PR lookup also uses the recorded name (gitManager.branchPullRequest({ branch: thread.branch })), so it looks for refs/heads/<old> and refs/remotes/<remote>/<old>, neither of which exists after the rename.
V2 never adopts the checkout. After a turn, RunFinalizationObserver refreshes status and returns when thread.branch !== local.refName instead of updating the thread. The client helper that would sync a drifted branch (resolveLiveThreadBranchUpdate) is skipped for server threads. That follow behavior used to live in V1 CheckpointReactor (#5159); it was not ported.
The equality check should stay. It is what prevents cleanup from deleting a worktree that was switched onto a different, already-merged branch. The fix is to adopt the checked-out branch when the worktree belongs to exactly one thread, then let the existing guard and PR lookup run against that name.
Not the same as #14742 / #14847 (squash merges; that PR still keys the PR read on thread.branch) or #15146 / #15208 (settled-thread eligibility). #4831 was the PR-badge symptom of this stale branch name.