Retention for settled and archived threads: archiving frees nothing, and a 3-week-old database already stalls the server #42372
Before submitting#
- I searched existing issues. #40677 asked for database retention and was closed with that part not done ("open a new issue if what is left still matters"). #17845 covers delete keeping every row. This issue asks for the missing feature: a supported way to drop old thread history.
Area#
apps/server
Setup#
- T3 Code v0.1.10, desktop app, macOS (Apple Silicon)
- One machine, about 3 weeks of use, 5 projects
- Threads are started by a script with
t3 thread start ... --worktree ...(Codex and Cursor providers). Usually 3–6 run at once, never dozens.
What happens#
statev2.sqlitegrows all the time: 564 MB, then 595 MB about 2 hours later, with 3–5 threads running.t3 doctor --dry-runsays:Database: 562.5 MiB, 0 KiB reclaimable.So all of it is live data.Where the space is (read-only
dbstat):Table MB orchestration_v2_projection_turn_items 230 orchestration_events 129 orchestration_v2_projection_nodes 62 orchestration_v2_projection_messages + message search ~35 535 threads in total. In one project, 189 threads are settled. They hold about 96 MB of turn-item payload, and nobody will open them again.
With this database the server hung.
event-loop-stalls.ndjsonshows stalls of 26 s and 37 s, and SQLite transactions onstatev2.sqlitetook 6–9 s. The main process sat at ~100% CPU, and every CLI call failed with:ServerAuthSessionTokenIssueError: Failed to issue session token. at cli.thread.withThreadTools ... [cause]: Error: database is lockedNo new trace lines were written for ~50 minutes. SIGTERM did nothing, and only SIGKILL plus the launcher's restart fixed it.
I archived 9 settled threads in the app to free space. All their rows stayed. For example, one thread still has 68 turn items and another has 45:
SELECT t.title, count(i.turn_item_id) FROM orchestration_v2_projection_threads t LEFT JOIN orchestration_v2_projection_turn_items i USING (thread_id) WHERE t.archived_at IS NOT NULL GROUP BY t.thread_id;Archive only sets
archived_at. Together with #17845 (delete only setsdeleted_at), this leaves a user with no way to make the database smaller.
Expected behavior#
A supported way to drop the stored history of threads that are done, for example:
- a setting: "delete the history of archived (or settled) threads after N days", or
- a command:
t3 doctor --prune-archived --older-than 30d(or similar),
that deletes their events, turn items, nodes and messages, keeps a small tombstone, and then frees the space with an incremental vacuum.
Why it matters#
The database grows with every turn, and per #37877 the server's cost per event grows with database size. So a machine that runs a few agents every day slowly gets slower until it stalls, even with few threads running. Today the only fix a user has is to delete statev2.sqlite and lose everything.
Related#
tanstack-source added labelsfeature
juliusmarminge closed this
Sign in to join this conversation.
Thanks for writing this up. It asks for new behaviour rather than reporting a defect, so it does not belong in the bug tracker and I'm closing it as not planned here. Feature ideas are discussed in Discussions: please post it there.