Repository navigation
Description
What happened
Storage cleanup removed a settled thread's worktree. git worktree remove deleted the checkout but failed on the worktree's git metadata (<repo>/.git/worktrees/<id>). T3 logged one warning, and the failure appeared in Settings → Storage → Cleanup only until the next hourly sweep replaced that report. After that nothing mentioned it again. On one Linux server, three such leftovers piled up over five days and held about 519k inodes and 38 GB, unnoticed until the host ran out of inodes.
The trigger in this case was a Docker container that bind-mounted a cache folder from inside the worktree's git dir and wrote root-owned drwx------ folders there. T3 can't delete those, and shouldn't try. This issue is about what T3 does once the removal has failed.
Diagnosis
Source at v0.1.11. main (7180578) is unchanged in these spots.
- The failure is non-retryable by construction on Linux/macOS.
removeLinkedWorktree(apps/server/src/vcs/worktreeRemoval.ts) runs plaingit worktree remove [--force]there. Git deletes the checkout first and then the admin dir. It stops at the first entry it can't delete and exits 255, with the checkout already gone. The Windows branch of the same function takes care to leave something a retry can remove ("Putting.gitback … leaves a worktree that a retry can remove"). The non-Windows path has no equivalent. - The next sweep skips the thread silently. In
cleanWorktrees(apps/server/src/storageCleanup.ts), every candidate starts withconst exists = yield* fs.exists(worktreePath); if (!exists) return;. The thread keeps itsworktreePath/branchon purpose ("Preserve branch/path so ProviderTurnStartService can recreate the checkout on resume"). Because the checkout is gone, every later sweep returns before reporting anything, so a half-finished removal looks exactly like a successful one. - The only record is ephemeral. The
catchpushes anoutcome: "failed"entry into the sweep's report and logsstorage cleanup failed for worktree. The report lives in aSubscriptionRefholding only the latest sweep, and the sweep runs hourly. A toast appears only for a manual "Delete now". Nothing is persisted on the thread. - Nothing else finds it.
reportOrphanWorktreeswalks the managed worktree folders, and asks git for linked worktrees nested inside them. It never looks at a repository's.git/worktrees/*.git worktree prune, whichrestoreMissingWorktreeruns before recreating a checkout, prints the same error but exits 0, so the failure looks like success there too. If the thread resumes,git worktree addregisters the new checkout under<id>1and the old admin dir stays behind permanently.
Suggested behaviour, most valuable first:
- Check before destroying anything. On non-Windows, before running
git worktree remove, confirm that the admin dir can be deleted by this user: every directory readable, and every parent writable. If it can't,keepthe worktree with a reason naming the first offending path, e.g. "Git metadata holds files this user can't delete (…/.git/worktrees/<id>/…/fanal)". The checkout stays intact, the reason shows on every sweep, and once the user fixes ownership the next sweep removes it normally. Admin dirs are normally a handful of files, so the check is cheap. - Recover when the checkout is already gone. Instead of
if (!exists) return;, check whether the repository still has an admin dir for this path. Match by itsgitdirfile, or by.git/worktrees/<basename>when git has already deletedgitdir. If one exists, rungit worktree pruneand then check whether the dir is actually gone, because prune's exit code says nothing. If it remains, report afailedentry on every sweep, with the leftover path and git's error. That fixes transient causes on the retry (for example NFS.nfs*silly-rename files, or a process still writing) and keeps permanent ones visible. - Optional: include the admin dir in the size cleanup reports for a worktree (here it held far more than the checkout), and surface failures of automatic sweeps somewhere persistent, not only after a manual run.
Retrying alone wouldn't have helped in this case, because root-owned files never become deletable. Making the failure visible, and keeping it visible, is the part that matters.
Steps to reproduce
Without T3, on a throwaway repo (git 2.47.3, Docker 29):
git init -q -b main main && git -C main commit -q --allow-empty -m init
git -C main worktree add -q ../wt -b throwaway
docker run --rm -v "$(git -C wt rev-parse --absolute-git-dir)/scratch/c:/c" alpine:3.20 \
sh -c 'mkdir /c/fanal && chmod 700 /c/fanal && echo x > /c/fanal/f'
git -C main worktree remove --force ../wt # exit 255: error: failed to delete '.git/worktrees/wt': Permission denied
ls wt # No such file or directory: the checkout is gone
ls main/.git/worktrees # wt: the admin dir remains
git -C main worktree prune -v # prints the same error, exit 0
git -C main worktree add ../wt throwaway # succeeds and registers wt1; wt stays foreverDepending on which entries git deletes before it hits the unremovable one, the leftover either shows as prunable in git worktree list --porcelain or is missing from the list entirely: in the run above, git had already deleted gitdir and HEAD. The error text also varies (Permission denied or Directory not empty).
In T3: enable a worktree cleanup rule (for example "settled after N days"), and plant root-owned content inside a settled thread's .git/worktrees/<id> as above. Let a sweep run, then open Settings → Storage after the next hourly sweep. The failure is gone and the leftover is never reported again.
Version
0.1.11 (background service, t3 serve).
Environment
Linux x64, Debian 13 (kernel 6.12), Node v26.13.1, git 2.47.3.
Evidence
Three failures, one per worktree (18, 19 and 21 Nov). No later log line mentions these worktrees or threads:
[05:31:12.209] WARN: storage cleanup failed for worktree
{ threadId: 'mcp:launch:…', error: { _tag: 'GitCommandError', operation: 'StorageCleanup.cleanupGit',
command: 'git worktree remove', cwd: '~/<repo>',
detail: "error: failed to delete '.git/worktrees/t3-<id>': Directory not empty" } }
The thread rows still hold the removed worktreePath and branch, with nothing recording the failure.
Related issues
- [Bug]: Storage cleanup fails every run on a worktree folder that lost its .git (Windows) #37276 and Storage cleanup fails when a retained worktree directory has no .git file #31136: cleanup fails on every run for a checkout folder that has lost its
.git. That's the opposite state, and there the failure is at least repeated on every run. - Deleting an archived thread silently orphans its git worktree #9085: deleting an archived thread orphaned its checkout folder. Here the git metadata is orphaned instead, which the orphan report doesn't look for.
- Thread resumes in a worktree folder without .git instead of recreating the checkout #24390 and [Bug]: Thread can't start a turn after its worktree and branch are removed by a merge #19124: resume and recreate behaviour after a worktree is gone. They're related only because recreating hides the leftover under a new
<id>1name.
Fix applied or workaround
Fixed ownership of the three leftovers (chown -R to the user) and ran git worktree prune. The repository that bind-mounted into the git dir is changing its containers to run as the user. No T3 change was made.
Filed by
Claude Code (Claude Opus 5.5, claude-opus-5-5) via T3 Code triage.
Activity