[Bug]: No retention for thread history: statev2.sqlite reached 40.4 GB (16,900 threads) on one install, deleting threads frees nothing, and the only way to shrink the file is an offline VACUUM that took the server down 27 minutes #21371
Before submitting#
- I searched existing issues and did not find a duplicate. Related, each narrower: #17845 (delete keeps every row), #20203 (compaction checkpoint blocks the server), #19105 (write amplification), #20534 (unused indexes), #19780 (snapshots outside compaction), #20922 (closed; V1 table kept). None asks for a retention policy or an online shrink path, which is what a long-lived multi-thread server needs.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- Run a headless server with ~50 concurrent threads (several ACP/GLM threads emit 50–90k
node.updatedevents an hour each) for a few weeks. ls -l ~/.t3/userdata/statev2.sqlite.- Open Settings: the retention setting covers worktrees, captures and logs only. Archive or delete old threads: the file does not change (#17845).
Expected behavior#
- A retention setting for thread history (age and/or count of finished threads), applied online in small batches off the main thread.
- The database opened with
auto_vacuum=INCREMENTALand a periodicPRAGMA incremental_vacuum(N), so freed pages return to the OS without an offline VACUUM. - Deleting a thread deletes its events, turn items and messages (a tombstone row is fine).
- High-frequency progress events (
node.updated) coalesced or stored out of the event table, so one chatty provider thread does not write a gigabyte a day.
Actual behavior#
| date | file | note |
|---|---|---|
| 2026-09-24 | 19.3 GB (V1 state.sqlite) | heap crash the same day (#21370) |
| 2026-10-04 | 24.7 GB V1 left behind at the V2 cutover; statev2.sqlite starts | |
| 2026-10-06 | 32.7 GB | 16,887 threads, ~2.2 M activity rows; ~13 GB in 3 weeks |
| 2026-10-17 | 40.4 GB | plus a 816 MB logs/ directory rolling ten 10 MB server.trace.ndjson.* files every ~6 minutes (~1.7 MB/s of trace) |
- There is no prune or retention command in the binary; we wrote one. Its first run (delete the messages, turn items, nodes, runs and checkpoints of threads archived more than 14 days ago) cost a 27 min 27 s outage to free 4.3 GB: DELETE 94 s, then VACUUM +
wal_checkpoint+integrity_checkon a 33 GB file 23 minutes, with VACUUM's temp copy on the root disk (51% to 63% used, IO stalled, PSI io 23–29). - Done online instead, the deletes free pages inside the file but the file never shrinks (4 GB freelist); the only shrink path is still ~25 minutes offline.
- The main thread blocks on its own database: in 30 stack traces taken 2026-09-21..10-01 the server was waiting on page reads and fsync of the 24 GB file (
folio_wait_bit_common,jbd2_log_wait_commit), and in 25 of 30 onlock_mm_and_find_vma. #20203 is the same shape. - The sustained 2–11 MB/s of writes is WAL churn from
node.updatedevents: 129k of ~180k events in one day, led by GLM threads at 50–90k events/h each.
Impact#
Major degradation or frequent failure
Version or commit#
0.0.46-nightly.20261008.2819 (sizes above); growth observed on every nightly since 0.0.43. Our local patches do not touch persistence.
Environment#
Linux (Ubuntu, kernel 7.0.0-38-generic), compiled @t3code/t3-linux-x64 binary (Node.js v26.8.2 in crash traces), t3 serve --host 127.0.0.1 --port 3773 --base-dir ~/.t3 as a systemd --user service, headless; Tailscale serve in front; clients: macOS desktop app, iOS app, web. 40–50 live threads at a time over 8 Claude Code instances (claudeAgent), 3 Codex instances and ACP providers (Grok CLI, OpenCode with GLM). ~16,900 threads in statev2.sqlite (40.4 GB). Threads are created, woken and stopped by our own tooling over the /ws RPC (orchestration.dispatchCommand), not by a human in the UI.
Running build: 0.0.46-nightly.20261008.2819 with two local server patches (GitHub PR-sync cadence, Grok multi-task wait). Each draft says whether the patch touches the reported area.
Logs or stack traces#
$ ls -l ~/.t3/userdata/statev2.sqlite*
-rw-r--r-- 1 matt matt 40436936704 Oct 17 21:30 statev2.sqlite
-rw-r--r-- 1 matt matt 131072 Oct 17 21:30 statev2.sqlite-shm
-rw-r--r-- 1 matt matt 33554432 Oct 17 21:30 statev2.sqlite-wal
$ sqlite3 -readonly statev2.sqlite 'select count(*) from orchestration_v2_projection_threads' # 16,887 on 2026-10-06
Workaround#
A nightly job of ours deletes the V2 rows of threads archived and untouched for 14+ days online (no shrink), and an occasional offline VACUUM window of ~25 minutes when the box is otherwise idle. Neither is something a product user can do.
juliusmarminge added labelsduplicate
juliusmarminge added labelsvia-triage
juliusmarminge closed this
Sign in to join this conversation.
Note
Grok responding on behalf of Julius.
Closing this one. Most of it is tracked, and the shrink path landed after your build (0.0.46-nightly.20261008).
t3 doctor, which reclaims space in existing databases. It does stop the server while it runs. #19437 suggests running it when there's space to reclaim. Please retest on a current nightly.node.updatedchurn and write amplification: tracked in #21154, #19461 and #19105.