Skip to content

Retention for settled and archived threads: archiving frees nothing, and a 3-week-old database already stalls the server #42372

Not planned

Description

@gileck

Before submitting

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

  1. statev2.sqlite grows all the time: 564 MB, then 595 MB about 2 hours later, with 3–5 threads running.

  2. t3 doctor --dry-run says: Database: 562.5 MiB, 0 KiB reclaimable. So all of it is live data.

  3. 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
  4. 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.

  5. With this database the server hung. event-loop-stalls.ndjson shows stalls of 26 s and 37 s, and SQLite transactions on statev2.sqlite took 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 locked
    

    No new trace lines were written for ~50 minutes. SIGTERM did nothing, and only SIGKILL plus the launcher's restart fixed it.

  6. 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 [Bug]: Deleting a thread says it permanently clears its history, but V2 keeps every event and projection row #17845 (delete only sets deleted_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

#40677, #17845, #21154, #37877, #38792, #41997

Activity

  1. juliusmarminge commented on Nov 24, 2026

    @juliusmarminge
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions