Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Worktree cleanup still keeps worktrees whose branch the agent renamed (fix PR #19870 was closed unmerged) #22312

Closedmahirozdin(GitHub profile, opens in a new tab) opened this issue 1 comment

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Turn on Delete merged worktrees (I also have inactive/settled after 3 days on).
  2. Start a thread in a new worktree. T3 names the branch from the first prompt, e.g. chore/list-available-work.
  3. Let the agent rename it once it knows what it's building: git branch -m feat/backend-core-flutter-foundation-gate-fixes.
  4. Open a PR from the renamed branch, merge it, leave the tree clean and the thread idle/settled.
  5. Wait for the sweep, or run cleanup from Settings → Storage.

Expected behavior

The worktree gets removed, since the PR is merged and the tree is clean.

Actual behavior

It's never removed. thread.branch still holds the original name, so cleanup bails out at branchChanged with "Repository or branch changed" before any rule is checked:

https://github.com/pingdotgg/t3code/blob/67c0fc0cda/apps/server/src/storageCleanup.ts#L769-L770

The merged-PR lookup also uses the old name (L856), so even without that check it wouldn't find the PR.

I know this was reported in #16559 (and #17813 covers the same thing plus detached HEAD), and #19870 fixed it, but that PR was closed without being merged and nothing replaced it. #20079 only carries T3's own t3/<hash> rename over to subagents; a rename done by the agent still isn't picked up. So it's still there on 0.1.0 and on main today. Opening this so it doesn't get lost now that the fix PR is gone.

For context on how often this hits: on my server 9 of the 15 worktrees T3 tracks have a recorded branch that doesn't match the checked-out one (7 from git branch -m, 2 from switching branches). 5 of those have merged PRs and clean trees. My agent loops always rename the branch before opening the PR, because the name from the first prompt ("list the next tasks") doesn't mean anything.

Together with the subagent issue (#16472, fixed in #19748 but that landed right after the 0.1.0 cut) this left ~39 GB of finished worktrees on a 244 GB disk. It filled up, SQLite started failing with database or disk is full, and the server kept restarting until I cleaned up by hand.

Impact

Major degradation or frequent failure

Version or commit

v0.1.0 (stable); code still the same on main @ 67c0fc0cda

Environment

Ubuntu server, remote T3 over Tailscale, Claude provider, lots of workflow/subagent threads

Logs or stack traces

# reflog of one of the kept worktrees
feat/backend-core-flutter-foundation-gate-fixes@{2026-10-19 22:21:49 +0300} Branch: renamed refs/heads/chore/list-available-work to refs/heads/feat/backend-core-flutter-foundation-gate-fixes

# thread row: branch = chore/list-available-work (root and all 83 subagent threads)
# PR #13 for feat/backend-core-flutter-foundation-gate-fixes: MERGED

Workaround

A cron job that removes clean worktrees whose HEAD is already on the default branch or whose PR is merged, using the branch that's actually checked out. Running git checkout back to the old branch name would work too, but nobody's going to do that by hand.

  1. Duplicate of #16559, which remains open and tracks this exact Delete merged worktrees failure after an agent renames the branch. Closing the proposed fix without merging did not close that original report. The stale recorded branch and merged-PR lookup described here belong to that same bug; #17813 also tracks the broader rename/switch/detached case.

  2. juliusmarminge closed this

Sign in to join this conversation.