Skip to content
Source
Sign inSign up
pingdotgg/t3code

Storage cleanup rebuilds every thread's shell, archived ones included, once an hour #38792

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

What happened

Every hourly storage-cleanup sweep rebuilds the full shell of every thread, archived threads included, to decide which worktrees to remove. On our server (9,343 threads, 8,435 of them archived) a sweep spends a median 21 s in these reads (6–123 s over one day), and other reads queue behind them on the reader connections.

Diagnosis

StorageCleanup.readThreads (apps/server/src/storageCleanup.ts, line 491 on main f1d64aa0b6) calls projections.getShellSnapshot() with no options, so it builds every thread's shell with item counts. The cleanup uses a few fields of each thread: id, project, worktree path, branch, lineage and the fields its settlement chain checks. On the same clone, the same snapshot with the item counts left out takes 9–11 s instead of 12–21 s.

Filtering on worktree threads would not narrow it: 9,135 of the 9,343 threads have a worktree path. What would: a read of only the fields cleanup uses, or reading only the threads changed since the previous sweep.

Steps to reproduce

  1. Use a database with several thousand threads, most of them archived, that have worktree paths.
  2. Turn storage cleanup on.
  3. Time StorageCleanup.readThreads, or getShellSnapshot() on a copy of the database.

Version

Production: server 0.1.11-nightly.20261117.4838 (t3 serve as a systemd service) with local patches to some SQLite reads; one of them leaves out the item counts in this read, so main costs more than the production figures below. Clone measurement: main f1d64aa0b6, unmodified.

Environment

Linux (Proxmox LXC, 16 CPUs, ZFS with 32K records), statev2.sqlite 49 GB.

Evidence

Production statement log, 22 h: 21 sweeps; reads under StorageCleanup.readThreads < StorageCleanup.cleanWorktrees per sweep: median 21 s, minimum 6.3 s, maximum 123 s. The largest single statement was the shell row read, 84 s.

Block clone of that database, no other load, getShellSnapshot() three times in a row (908 active and 8,435 archived threads):

Pass 1Pass 2Pass 3
main, as cleanup calls it20.7 s14.0 s11.8 s
item counts left out11.0 s9.3 s9.3 s

#18927 (sweeps re-read every thread for each candidate; closed as not planned). #17811 (cleanup now includes archived threads, which is why they are read).

Fix applied or workaround

Locally the item counts are left out of this read. No workaround for the rest.

Filed by

Measured and written by Claude (Opus 5.5) in T3 Code; posted with the owner's approval.

  1. tanstack-source added labelsbug

  2. Still the case ten days later, now with #38908 applied: the hourly read of every thread takes longer as the database grows. The production server has gone from 9,343 to about 12,300 threads, and over 24 h of its statement log (statements over 250 ms):

    StatementSweepsMeanRows
    ProjectionStore.getStorageCleanupThreads < StorageCleanup.readThreads2329.1 s12,306

    #38908 builds shells only for threads with a worktree on disk, but it still reads and parses each thread's row to find them. On main 5385, StorageCleanup.readThreads still calls getShellSnapshot() with no options. Version: a local build of 0.1.12-nightly.20261123.5165 with #38908 applied.

    Measured and written by Claude (Opus 5.5) in T3 Code; posted with the owner's approval.

Sign in to join this conversation.