t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: "Check out → In a separate worktree" leaves a permanent worktree when the draft thread is never sent

Open JMHSV opened this issue 1 month ago • 0 comments

Before submitting

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

Area

apps/web

Steps to reproduce

  1. Turn on Delete worktrees with deleted threads and Delete merged worktrees in storage settings.
  2. Open a pull request in the pull request panel and click Check out → In a separate worktree.
  3. On the draft thread that opens, don't send a message. Go to another thread, or start a new draft in the same project.
  4. Look in ~/.t3/worktrees/<project>/.

Expected behavior

When the draft is discarded or replaced without a message, the worktree the checkout created for it is removed. At minimum, one of the storage cleanup rules covers it.

Actual behavior

The worktree stays, and nothing removes it later.

The checkout creates the worktree and runs the setup script before the draft opens. startHandoff in usePullRequestActions.ts:333-366 calls newThread, then prepareThread.run, then newThread again with the worktreePath. The draft exists only on the client, so no server thread references the worktree. As a result:

  • worktreeOnDelete, worktreeOnMerge, and the inactivity rules never apply. They act on server threads.
  • Storage cleanup lists the worktree as "No thread uses this worktree" and keeps it. reportOrphanWorktrees (storageCleanup.ts:354) only reports.
  • A new draft replaces the empty one through setLogicalProjectDraftThreadId (composerDraftStore.ts:2587-2606). That deletes the draft record but not its worktree. Discarding the draft from the sidebar also leaves the worktree. The only web caller of removeWorktree runs when a server thread is deleted (useThreadActions.ts:559).

The client also can't tell whether it owns the worktree. GitPreparePullRequestThreadResult doesn't say whether preparePullRequestThread created the worktree or reused an existing one, and a reused worktree can belong to other threads. So a fix can't simply remove the draft's worktreePath.

PullRequestDetailPanel.tsx:890-919 has a copy of the same sequence and behaves the same way.

Line numbers are at main @ 5b89a53. I observed steps 1-4 on my machine: the checkout of a same-repository PR left a clean worktree on the PR branch, and no row in orchestration_v2_projection_threads references it. I didn't wait for a storage cleanup run. The cleanup behavior above comes from reading the source.

Impact

Minor bug or occasional failure

Version or commit

0.1.4-nightly.20261028.3824

Environment

macOS 27.0.1, desktop app

Workaround

Remove the worktree by hand with git worktree remove <path>, then delete the local branch with git branch -D <branch>.

Related

#25843 reports the general case: storage cleanup never removes worktrees that no thread owns. This issue is one specific source of them. T3's own PR checkout creates the unowned worktree, and the draft that owns it in practice is never tracked. A fix for #25843 could remove these worktrees after a delay. A fix here would remove them when the draft goes away.

My use case: a branch is built on another machine, and I check out its PR on my Mac to run the dev server from the draft's terminal, look at it, and throw it away without starting an agent turn.

Filed with Claude (Opus 5.5) in T3 Code, from source reading and the state on my machine.

JMHSV avatar Oct 28 '26 22:10 JMHSV