GeezerVison is showing github.com — fix(server): storage cleanup no longer keeps shared worktrees forever by only21mil · Pull Request #24672 · pingdotgg/t3code
Conversation
Problem
When two or more top-level threads use one worktree, storage cleanup never removes it. Settings → Storage → Last run shows "Shared by 2 threads" on every sweep, however old, merged or unchanged the checkout is. "New thread on <branch>", create_threads, forks and V1 imports all create such pairs.
cleanWorktrees returned keep("shared by N threads") for any group without a single subagent owner, before any other rule ran. The recheck before removal also required that owner.
Fixes #17816.
Change
Without one owner, cleanup holds every thread on the worktree to the single-thread rules:
- all idle with no pending work, inactivity counted from the latest activity across them;
- "settled" only once every thread has settled, counted from the latest settle;
- the unchanged and merged rules run once, on the shared branch.
The rules resolve from one project and branch, so threads in different projects or on different branches still keep it ("Shared by threads in different projects", "Shared by threads on different branches").
The recheck before removal now compares the owner it finds with the first pass's owner (none, for a shared group). A new or removed sharer, a sharer that starts running, changes branch or settles, open terminals, live sessions and local changes still cancel removal. Subagent owner groups and deleted-thread cleanup are unchanged. Threads keep branch and worktreePath, so the next turn recreates the checkout. The storage guide line "shared worktrees prevent removal" now states the new rule.
Scope and approval
Issue: #17816, untriaged. This changes intended behavior: the single-owner rule comes from #11598, and the triage on #16472 said forks and other genuine co-owners "likely should keep blocking removal". Here a co-owner blocks removal only while it would keep the worktree on its own. It awaits maintainer review. The choice to confirm: a shared worktree is removed only when every sharer would allow it, and sharers across projects or branches keep it. If you would rather keep shared worktrees until one thread remains, this PR can close.
Server only. No contract, client, adapter or MCP change; web and desktop already render the report reasons, and mobile has no Storage screen.
Verification
Focused tests in apps/server/src/storageCleanup.test.ts:
- New table "worktrees shared by top-level threads", two threads on one worktree: removed when both are settled or both inactive; kept when one is unsettled, recently active or running, or the branches or projects differ.
- New case: a second thread that starts running during measurement cancels the removal.
- The owner-group test's non-owner scenarios now pass the shared check and stop at "Not settled", since their second thread never settled.
The seven new table cases fail on main with "Shared by 2 threads" and pass with this change:


vp test run src/storageCleanup.test.ts: 129 passed, 1 failed. The failure, "compares the checked-out branch without a full status", also fails on unmodified main here (git 2.56 reports a broken .git file as a git error). vp fmt --check and vp lint on the changed files and vp run typecheck in apps/server pass.
Real app, web and desktop (Electron) on Linux, isolated state with the repo's mock ACP agent: a thread in a new worktree, then "New thread on <branch>" with one message, and Delete unchanged worktrees on.
Web, on main, Delete now keeps the worktree as shared (machine name masked):

With this change the same flow passes the shared check, then keeps the worktree because a provider session is still open:

After a server restart ends the sessions, a second pair started the same way on coupon-field loses its worktree on the next run:

Desktop, same flow. On main, Delete now keeps the worktree as shared:

With this change, after a restart ends the sessions, turning on Delete unchanged worktrees runs cleanup and removes a shared pair's worktree:

Not checked:
- the settled, inactive and merged rules in the real app (tests only);
- a follow-up turn on a remaining thread recreating the removed checkout;
- full CI suites and repo-wide knip.
Prior PRs
Production fix, tests, PR description and images by Claude Opus 5.5 in T3 Code Nightly.
🤖 Generated with Claude Opus 5.5 in T3 Code Nightly
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…ead is eligible
A worktree used by several top-level threads was kept on every sweep with
"Shared by N threads". Without a single owner, cleanup now checks every
thread on the worktree: all idle, inactivity from the latest activity across
them, and settled only when every one is settled. Threads in different
projects or on different branches still keep it.
Fixes pingdotgg#17816
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Approvability
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — Storage cleanup will now remove certain shared worktrees that the existing server always retained, based on all sharers meeting the configured cleanup rule. Because this changes an existing automated deletion policy and its observable side effects, the change warrants maintainer review.
You can add or adjust custom eligibility rules. Learn more.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review.
Recent review info
-
Run configuration
-
Commits
-
Reviewing files that changed from the base of the PR and between 8f26ed7 and ced60a9.
Files selected for processing: 3
-
apps/server/src/storageCleanup.test.ts
apps/server/src/storageCleanup.ts
docs/user/project-settings.md
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
Walkthrough
-
Worktree cleanup now evaluates shared threads when ownership is ambiguous. It retains worktrees whose threads span projects or branches, and otherwise checks settlement and activity across the required members. Final revalidation compares the current owner ID with the previously determined owner.
Changes: Shared worktree cleanup
| Layer / File(s) |
Summary |
Shared-worktree eligibility apps/server/src/storageCleanup.ts, apps/server/src/storageCleanup.test.ts, docs/user/project-settings.md |
Cleanup checks project and branch consistency for shared worktrees. When ownership is ambiguous, all members must meet the settlement and activity rules. Tests cover eligible and ineligible shared threads, including a measurement race. The documentation describes these conditions. |
Priority: Normal
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers: maria-rcks, bil0000
Merge Risk: Minimal · up to ced60
-
Shared-worktree cleanup appears ready to merge after normal checks; no actionable eligibility issue remains.
Pre-merge checks: 4
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title names the main change: storage cleanup no longer keeps shared worktrees indefinitely. The raw summary and objectives confirm the server-side cleanup rules now apply to worktrees shared by to… |
| Description check |
 |
The description follows the template. It has Problem, Change, Scope and approval, and Verification sections, all filled in with specific content. The problem is stated with reproduction context (Setti… |
| Linked Issues check |
 |
The changes satisfy [#17816]. storageCleanup.ts no longer rejects a shared worktree only because it has multiple top-level threads. It keeps groups with different projects or branches. For compatibl… |
| Out of Scope Changes check |
 |
The changes stay within the linked issue. The server change implements cleanup behavior. The test changes verify that behavior and preserve subagent-owner coverage. The documentation change updates th… |
Full details: Title check
-
Explanation
The title names the main change: storage cleanup no longer keeps shared worktrees indefinitely. The raw summary and objectives confirm the server-side cleanup rules now apply to worktrees shared by top-level threads. The title uses the conventional commit form and is specific enough for a teammate scanning history. It is 69 characters, which is within a reasonable length.
Full details: Description check
-
Explanation
The description follows the template. It has Problem, Change, Scope and approval, and Verification sections, all filled in with specific content. The problem is stated with reproduction context (Settings > Storage > Last run, 'Shared by 2 threads'). The change explains the single-owner rule and the revalidation update. The scope section links issue #17816, cites prior PRs and maintainer triage, and names the decision the maintainer must confirm. The verification section lists focused tests, their counts, a known pre-existing failure on main, lint and typecheck results, and real-app checks, along with what was not checked. The template's required structure is present and the content is substantive. Minor gaps: the Change section does not explain why the multi-component changes are needed (the PR states it is server-only), and the verification includes external gist image links that cannot be validated here. These are non-critical.
Full details: Linked Issues check
-
Explanation
The changes satisfy [#17816]. storageCleanup.ts no longer rejects a shared worktree only because it has multiple top-level threads. It keeps groups with different projects or branches. For compatible groups, it applies the cleanup rules to all sharers, uses the latest activity and settle times, and preserves the removal recheck for concurrent changes. The new tests cover settled, inactive, unsettled, recent, running, different-branch, different-project, and measurement-race cases.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within the linked issue. The server change implements cleanup behavior. The test changes verify that behavior and preserve subagent-owner coverage. The documentation change updates the storage cleanup rule to match the implementation. No unrelated client, contract, adapter, or MCP changes are present.
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Note Written by gpt-6.1-sol on behalf of Maria
this does not meet the prior-approval rule. maintainer triage in #16472 identifies subagent copies as the ownership defect and explicitly distinguishes genuine independent co-owners that should keep blocking removal. this pr deliberately changes that shared-worktree retention behavior, and its description acknowledges that difference without linking approval.
please obtain explicit maintainer agreement for removing genuinely shared worktrees, or keep those co-owners blocking and restrict the repair to the accepted ownership defect. merged #19748 already addresses the subagent ownership case, so establish the remaining failure on current main before requesting reconsideration.
policy: contribution guide. assessed head ced60a929b7b3ba0091fac8065b01e6f69570f90. this is an unexecuted dry-run draft.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
size:S
10-29 changed lines (additions + deletions).
vouch:unvouched
Author is not yet trusted in the VOUCHED list.
Milestone
No milestone
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.
|