Skip to content

[Bug] State database grows without bound: no way to delete threads, and free space is never reclaimed #46035

Duplicate

Description

@manstfu

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

  1. Use T3 for a long time, or run many delegated tasks (each subagent run becomes its own thread).
  2. Watch the size of ~/.t3/userdata/statev2.sqlite over days or weeks.
  3. Settle or archive old threads.
  4. Check the file size again, and the share of free pages:
    sqlite3 statev2.sqlite 'PRAGMA page_count; PRAGMA freelist_count;'

Expected behavior

Old threads can be deleted, deleting them frees disk space, and the database does not keep growing until the disk is full. Free pages are reclaimed automatically.

Actual behavior

  • Threads cannot be deleted. Settle and archive only hide them, and their events, messages, turn items and search index rows stay in the database, including those of finished subagent threads.
  • The file never shrinks. Free pages stay inside it (no VACUUM or auto_vacuum), and they can be a large share of the file.
  • v1 tables and an old state.sqlite can stay on disk after the v2 migration.
  • With heavy delegated-task use the database reaches tens of gigabytes and can fill the disk. T3 then fails in other places, for example Workspace preparation failed during provision worktree: Git command failed in GitVcsDriver.createWorktree.

Impact

Blocks work completely

Version or commit

No response

Environment

No response

Logs or stack traces

Screenshots, recordings, or supporting files

No response

Workaround

Stop T3, back up the file, then run:
sqlite3 statev2.sqlite 'PRAGMA wal_checkpoint(TRUNCATE); PRAGMA integrity_check; VACUUM;'
This recovers only the free pages. The database starts growing again right away.

Suggested fix:

  1. Delete threads in the UI and through the MCP tools, one at a time and in bulk ("delete archived/settled threads older than N days"), including all of their data and child subagent threads.
  2. A retention setting for finished delegated-task threads (keep only the final summary in the parent).
  3. auto_vacuum = INCREMENTAL with incremental_vacuum after deletes, or VACUUM on startup when free pages go over a threshold.
  4. Drop the v1 tables and the old state.sqlite once the v2 import has been verified.
  5. Show the database size in settings or diagnostics.

Activity

  1. added
    bug
    needs-triage
    on Nov 30, 2026
  2. juliusmarminge commented on Nov 30, 2026

    @juliusmarminge
    Member

    This is the same problem as #17845, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.

  3. manstfu commented on Nov 30, 2026

    @manstfu
    Author
    1. Freed pages are never returned to disk. Once rows are deleted (for example after the [Bug]: Deleting a thread says it permanently clears its history, but V2 keeps every event and projection row #17845 fix), statev2.sqlite keeps the freed pages, because nothing runs VACUUM and auto_vacuum is off. On a heavily used install about a third of the file was free pages. A fix could be auto_vacuum = INCREMENTAL plus incremental_vacuum after deletes, or a VACUUM on startup when free pages go over a threshold.
    2. No bulk deletion or retention for finished delegated-task threads. These threads make up most of the data on orchestration-heavy installs.

    If (1) counts as a bug and (2) as a feature request, I will move (2) to Discussions.

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

    bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions