Skip to content

[Bug]: Storage cleanup never removes worktrees whose PR merged into an integration branch, or whose repo has an upstream remote #39956

Closed

Description

@fahimanwer

Area: Storage cleanup (worktree cleanup)

Version: T3 Code 0.1.10-nightly.20261111.4529, macOS (arm64). The merge check below is unchanged on main (apps/server/src/storageCleanup.ts, storageCleanupPullRequestMerged).

Storage cleanup with "remove once the pull request is merged" (worktreeOnMerge) keeps worktrees forever in two common set-ups, and reports them only as "Not merged".

1. PRs merged into an integration branch. storageCleanupPullRequestMerged counts a squash or rebase merge only when pullRequest.baseRef === defaultBranch and the PR's head equals the worktree's HEAD. In a repo where feature PRs merge into a long-lived integration branch (say develop, later merged into main), every finished worktree fails baseRef === defaultBranch and is never removed, even after the integration branch itself reaches main. We had about 160 such worktrees (over 150 GB) on one Mac: each with no local changes, one settled thread, its PR merged and its HEAD equal to the PR's final commit.

2. Repos with an upstream remote. When a fork has both origin (the fork) and upstream (the parent), the PR lookup picks upstream first when choosing which GitHub repo to search, finds no PR for the branch, and keeps the worktree as "Not merged", although the PR was merged into the fork's default branch.

Expected: a worktree whose own PR is merged is removable whatever the PR's base, or at least its base being a branch that is itself merged; and the PR lookup uses the repository the thread's PR lives in.

Suggestions:

  • The thread already stores its PR (repository and number, with a merged snapshot). Cleanup could read that PR directly instead of searching by branch name in a repo chosen by remote name.
  • Optionally count merges into any base, or add a setting listing integration branches that count.
  • Name the real reason in the cleanup report ("merged into develop, not the default branch"; "no PR found in upstream") instead of "Not merged".

Workaround we use: a per-project worktreeCleanup with worktreeSettledAfterDays, with a settle script (runOnSettle) that copies git-ignored notes and env files before removal.

Steps to reproduce (1):

  1. A repo whose default branch is main, with a branch develop.
  2. Start a thread in a worktree, commit, open a PR from its branch into develop, squash-merge it, settle the thread.
  3. With worktreeOnMerge: true, run storage cleanup: the worktree stays, reason "Not merged".

Steps to reproduce (2): as in (1), but merge into main of a fork whose clone has origin = the fork and upstream = the parent repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions