Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): storage cleanup no longer keeps worktrees whose subagents recorded another branch #44276

Openmanakjiri(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/44276/headopened View on GitHub

Problem

Storage cleanup keeps a worktree with "A subagent thread's branch differs from this worktree's branch" on every sweep while the threads sharing it record different branches. The guard returns before the branch sync that #34984 added to cleanup. On a detached HEAD the branch sync records nothing, so a review subagent that checks out a pull request and leaves HEAD detached keeps the worktree from being cleaned up.

Change

  • The guard now keeps only worktrees that cannot follow a branch: a thread with no recorded branch, and task and scratch folders.
  • On a named branch, cleanup tries to sync the stale records and keeps the worktree for the next sweep.
  • A clean detached worktree whose HEAD is on a local or remote branch goes through the usual rules.
  • Before removal, cleanup compares each thread with its own earlier branch record, so a branch change during the sweep still blocks removal.

Scope

Follow-up to #34984 and #34967, which fixed #17813 without changing this guard. #36549 reports this case and was closed as a duplicate of #17813.

Verification

  • Found on 0.1.11 on Linux. Cleanup kept 31 clean worktrees with this reason, 25 of them detached. 30 HEADs were on remote branches and one was on a local branch.
  • One turn on main with Claude Haiku: subagent 1 created and pushed review/pr-5, subagent 2 started, and subagent 3 detached HEAD. The owner and subagent 1 kept t3/<id>, subagents 2 and 3 kept review/pr-5, and the records still differed after the turn.
  • Both new tests in storageCleanup.test.ts failed on main. The named-branch test still saw ['feature', 'review/pr-1'], and the detached worktree was kept. With the fix, the named-branch test synced on the first sweep and removed on the second, and the detached test removed on the first, both with "Settled for 20 days".
  • Dev server with two seeded stale records and worktreeSettledAfterDays: 0: Delete now reported 0 removed, 2 kept on main and 2 removed, 0 kept with the fix, both "Settled for 0 days". git worktree list showed only the main checkout, and all branches remained.

Written by Claude Opus 5.5 (Claude Code) in T3 Code on behalf of Jiří Maňák.

    1. Pushed808f4f2

Sign in to join this conversation.