Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Storage cleanup never sees archived threads, so their worktrees are never removed and do not count as sharers #17811

Closedtris203(GitHub profile, opens in a new tab) opened this issue 1 comment

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

In the app:

  1. In Settings → Storage, enable a worktree rule, e.g. remove worktrees after N inactive days.
  2. Archive a thread that owns a clean T3-managed worktree whose last activity is older than N days.
  3. Choose Delete now.

In a test (smallest form), against the real ProjectionStore.layer on in-memory SQLite:

  1. Seed one active thread and one archived thread, each with a worktreePath.
  2. Run the read StorageCleanup.readThreads performs:
    const active = yield* projections.getShellSnapshot();
    const archived = yield* projections.getShellSnapshot({ location: "archive" });
    const threads = [...active.threads, ...archived.threads];
  3. threads contains only the active thread.

Expected behavior

Archived threads go through the same cleanup checks as active ones: their worktree is removed when a rule applies, or listed as kept with a reason, and they count as sharers of a worktree.

Actual behavior

Cleanup never sees archived threads. The worktree is not removed and has no entry in the cleanup report.

readThreads (apps/server/src/storageCleanup.ts:251-255) reads getShellSnapshot({ location: "archive" }).threads. Both projection store implementations return archived shells in archivedThreads and filter threads to archivedAt === null (ProjectionStore.ts:5834-5835 for SQL, :6016-6017 for the in-memory store), so that list is always empty. runtimeLayer.test.ts:1914-1919 asserts exactly this shape: archiveOnlyShell.threads has length 0.

The unfiltered getShellSnapshot() call already returns the archived threads in active.archivedThreads, which is how CheckpointRestoreSafety.ts:42, ProjectService.ts:467 and ws.ts:1755 read them.

This regressed in the V2 port (#2829). Before it, the code was snapshots.getArchivedShellSnapshot() followed by the same [...active.threads, ...archived.threads], and that API returned archived shells in .threads.

The harness mock in storageCleanup.test.ts:269-270 returns { threads: location === "archive" ? [] : threads } behind a cast, so no existing test can catch it.

Impact

  • Worktrees referenced only by archived threads stay on disk under the inactivity, unchanged and merged rules. They are only picked up once the thread is deleted with Delete worktrees with deleted threads on.
  • An archived thread sharing a worktree is not counted by the "shared by N threads" guard or by the re-check before removal, so an active thread's rules alone can remove a worktree the archived thread still points at.
  • Deleting a thread with Delete worktrees with deleted threads on removes its worktree even when an archived thread still references the same path.

The local-changes, open-session and open-terminal guards still apply, and branches and thread history stay, so this is mainly unreclaimed disk plus an incorrect sharing guard rather than data loss.

Version or commit

0.0.46-nightly.20261010.2922 (bd2346eda2). Unchanged on main at f7664fdf42.

Workaround

Unarchive the thread so cleanup can see it, or delete it with Delete worktrees with deleted threads enabled.

References

  • #16473 fixes the read by using one unfiltered snapshot and both lists. It was opened without an issue and currently conflicts with main. Its test covers the read; the shared-worktree guard and the delete path with an archived sharer are not yet covered.
  • #15080 is described in #16473 as making the same change inside a larger rewrite.
  • #9085 is a different defect (the web client skips worktree cleanup when deleting an archived thread), listed here only to avoid confusion.
  1. Note

    Grok responding on behalf of Julius.

    Fixed by #16473, which just merged: storage cleanup now reads archived threads alongside active ones, so their worktrees go through the same cleanup rules and count as sharers. Closing as completed. Thanks for the detailed report!

  2. juliusmarminge closed this

Sign in to join this conversation.