Skip to content
Source
Sign inSign up
pingdotgg/t3code

Settled worktree never cleaned up when a child thread on it records an older branch name #36549

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

What happened

When a thread is settled, storage cleanup should remove its worktree (worktreeSettledAfterDays: 0, clean tree). It keeps the worktree indefinitely when another thread on the same worktree is recorded with a different branch name. In our case those were subagent child threads created before the parent changed the worktree's branch.

Diagnosis

On one worktree, the settled parent and 15 child threads record branch X, which is the branch the worktree is on now. Two child threads, created earlier, record branch X-plan, which was the branch name when they started. The cleanup's owner and branch checks (worktreeOwner, branchChanged, "repository or branch changed") compare each thread's recorded branch with the worktree. The mismatch makes the cleanup keep the worktree, even though every thread on it is done. Nothing ever updates the children's recorded branch, so the worktree stays.

A related gap makes this worse: child threads aren't settled when their parent is. An idle child on a shared worktree keeps the worktree's thread family unsettled, so a settled parent's worktree is kept for that reason as well.

Steps to reproduce (likely)

  1. Start a thread in a new worktree on branch a.
  2. Have it start a native subagent (Agent tool). The child thread is recorded with branch a.
  3. In the parent, rename the branch or switch the worktree to branch b, and start more subagents.
  4. Let everything finish, then settle the parent (and the children).
  5. Wait for storage cleanup: the worktree is never removed.

Version

0.1.9 (service-managed, Linux x64)

Environment

Linux (Arch), T3 Code as a systemd user service, Claude Code provider, storageCleanup.worktreeSettledAfterDays: 0.

Evidence

SELECT json_extract(payload_json,'$.branch'), count(*) FROM orchestration_v2_projection_threads
 WHERE json_extract(payload_json,'$.worktreePath') = '<worktree>' GROUP BY 1;
X-plan | 2
X      | 15

Seen on two machines, both with the same shape: children recorded on an older branch name of a shared worktree.

Workaround

Remove the worktree by hand once every thread on it is settled and its work is pushed.


Reported by Claude Opus 5.5 (Claude Code), working for the T3 Code user who hit it.

  1. tanstack-source added labelsbug

  2. This is the same problem as #17813, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.

  3. juliusmarminge closed this

Sign in to join this conversation.