Repository navigation
Conversation
…r subagent used Provider-native subagent threads run in their parent's checkout and are never archived or deleted with it, so counting them as sharing the worktree kept it forever. Closes pingdotgg#19144.
Contributor
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a small, self-contained server bug fix that corrects worktree sharing counts for provider-native subagents while preserving protection for user-addressable delegated children. The behavior is covered by a focused regression test and does not change defaults, contracts, or deployment configuration. You can add or adjust custom eligibility rules. Learn more. |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Automatic worktree cleanup keeps any worktree that more than one thread uses ("Shared by N threads"). Each subagent a provider spawns (Claude's Agent tool, Codex or Cursor native subagents) is stored as its own thread with its parent's
worktreePath, and it is never archived or deleted with its parent. So once a thread starts one subagent, its worktree is kept forever, even after the user deletes the thread.Reported in #19144. On my machine a run reported
0 removed, 111 kept. Subagent threads blocked 44 of 81 worktrees.Repro: turn on "Delete unchanged worktrees", let the agent in a worktree thread start one subagent, settle or delete the thread, then run Settings → Storage → Delete now. The worktree is kept with "Shared by 2 threads".
Change
storageCleanup.tsignores provider-native subagent threads (isProviderNativeSubagentThread) when it counts the threads that use a worktree. It counts in two places: the first check, and the recheck just before removal. Both now use oneusesWorktreepredicate.delegate_taskchildren (creationSource: "mcp") still count, because the user can message, archive and delete them separately. A subagent that is still working stays protected by its parent's active run and by the existing open-provider-session check.Scope and approval
This is a small, focused fix for an obvious bug, filed as #19144. It changes one predicate in one server file and adds one test. It changes no contract, client, setting or default.
Verification
apps/server/src/storageCleanup.test.ts, "does not count a provider-native subagent as sharing its parent's worktree". With adelegate_taskchild, the worktree is kept ("Shared by 2 threads"). With a provider subagent child listed first, the worktree is removed and reported under the parent thread.× … expected { … } to match object { outcome: 'removed', … }Tests 1 passedvp test run src/storageCleanup.test.ts: 55 passed, 2 failed. The same 2 tests ("compares the checked-out branch without a full status" and "aggregates expired artifacts and rotated logs…") also fail on unchangedmainon my machine (macOS, Node 26.11 where the repo asks for Node 24), so this change does not cause them.vp run typecheckinapps/server: exit 0.vp fmtandvp lintare clean on both files.Made with Claude Opus 5.5 in Claude Code, run from T3 Code.