Skip to content

[Bug]: Worktree not removed after its PR merged, with worktree cleanup enabled and no explanation shown #24188

Open

Description

@RishabhTayal

Before submitting

Area

apps/server

Steps to reproduce

  1. Enable automatic worktree cleanup in Settings → Storage.
  2. Start a worktree thread, have the agent commit, push and open a PR from the worktree branch.
  3. Merge the PR. The thread stays open and the agent session keeps running in the worktree.
  4. Wait for the hourly cleanup sweep.

Expected behavior

The worktree is removed once the PR is merged, or the UI clearly says why it was kept.

Actual behavior

The worktree is still on disk after the PR merged and after several hours. Nothing in the UI I looked at explained why.

What I verified locally:

  • git status in the worktree is clean (no uncommitted changes).
  • Worktree HEAD equals the merged PR's head commit (9c6348b…).
  • PR state is MERGED; head branch and base (main) match what storageCleanupPullRequestMerged requires.
  • git worktree list still lists it.

Reading apps/server/src/storageCleanup.ts, my best guess is that the thread is still active (agent session running with its cwd inside the worktree), which maps to the "thread is running or has pending work" or "provider session is still open" keep reasons. I have not confirmed this from the cleanup report.

Impact

Minor bug or occasional failure

Version or commit

Unknown

Environment

macOS (Darwin 27.0.0), T3 Code with the Claude Code harness, model Claude Sonnet 5.5. Date: 2026-10-23.

Logs or stack traces

N/A

Workaround

Settle or delete the thread so the session closes, then run cleanup now, or run git worktree remove manually.

Suggestions

  • If a merged-PR worktree is kept only because its thread or session is still active, say so in the Storage cleanup report and in the thread UI.
  • Consider whether a merged PR should count as enough to settle the thread, so cleanup is not blocked by an idle-but-open session.

Activity

  1. juliusmarminge commented on Oct 24, 2026

    @juliusmarminge
    Member

    On current main (d53873b6a4), I ran the web app and server on Linux with a clean worktree and a real Claude Sonnet 5.5 turn. With Delete merged worktrees enabled, Delete now kept the running worktree and Settings → Storage → Cleanup → Last run displayed “Thread is running or has pending work.” I could not reproduce the missing explanation.

    The historical merged-PR head used for this attempt was not an ancestor of current main; after the turn finished, its report said “Not merged,” so this does not establish the idle-session behavior for your integrated branch.

    Please provide your T3 version, the merged PR URL, and the entry for this worktree under Storage → Cleanup → Last run after Delete now. That will distinguish an active-session guard from an integration check or a missing report entry.

    Storage cleanup report showing the running-thread keep reason

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

    needs more infoInitial triage showed no bug. Awaiting more info

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions