Skip to content

bb's database grows without limit, and archiving doesn't shrink it #5730

Description

@brsbl

bb's database keeps growing for heavy users, and archiving threads doesn't make it smaller. One user's database reached 1.5 GB (about 670,000 events across about 1,300 threads). At that size some reads wait on the disk, which is slower still on a Mac that's low on memory.

Why it happens

  • Automatic cleanup only removes a few kinds of events: rate limits, usage, turn diffs and resolved items (THREAD_PRUNING_POLICIES in packages/db/src/data/thread-pruning.ts). Messages and tool history are kept forever.
  • Archiving hides a thread but deletes nothing. The only way to shrink the database today is deleting threads, by hand or automatically with the opt-in Storage & retention plugin's "delete after N days" setting. Both lose the thread's history.

Proposed direction

Add a storage step after archiving: archived → compacted. A compacted thread's history moves out of the main database into a compressed cold store. It still shows up as archived, reopening it reads from the cold store, and unarchiving moves it back. Nothing is lost, and the main database only holds threads people actually use.

  • Core owns the mechanism: the compacted state, the cold store, reading it back, and moving it back on unarchive.
  • The Storage & retention plugin owns the policy: a new setting such as "Compact archived threads after N days", next to its existing archive-after and delete-after settings. That gives a ladder of active → archived → compacted → (optionally) deleted.
  • Archiving stays instant and cheap to undo. Only threads that have been archived for a while get compacted.
  • Reduce chat database storage without losing history #5563 (lossless compression, off by default; 4.04 GB → 1.64 GB on a test copy) can provide the cold store's format, and still helps active threads on its own.

Open questions:

  • Search: whether compacted chats stay in normal search or need an explicit "include archived" search.
  • Parent/child threads: compact a thread tree only once every member is archived. The retention plugin already processes whole trees and skips ones with pinned members.
  • Backups, and the cost of unarchiving many compacted threads at once.
  • Whether "compacted" is ever shown to users, or stays an internal detail of archived threads.

Related: #5005 (cleanup stalls on busy workspaces), #4714 (snapshot threads outside the database).

Done when

Archiving old threads makes the database smaller, or at least stops it growing, while their chat history stays available. Users also have a documented way to check how big their database is.

Activity

  1. changed the title [-]Database grows without bound for heavy users, and archiving doesn't shrink it[/-] [+]bb's database grows without limit, and archiving doesn't shrink it[/+] on Oct 18, 2026
  2. added
    threads
    on Oct 18, 2026
  3. bb-slop-cop commented on Oct 18, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Applied Type: Feature · Priority: Medium · Effort: High and labels threads, perf. No existing classifications needed preserving; final Type verified as Feature.

    Trusted main preserves conversation history when archiving; archive updates lifecycle state and schedules limited event pruning, not full history compaction. Making archive reclaim database space while retaining reopenable history adds a storage capability and requires a storage-policy/design decision. Medium priority reflects the heavy-use performance impact with existing opt-in retention controls; high effort reflects the data-lifecycle design involved.

    No reproduction report or pull request: this is a feature request, not a demonstrated regression in existing archive behavior.

  4. brsbl commented on Oct 20, 2026

    @brsbl
    CollaboratorAuthor

    Two more data points from one user's servers:

    • An old local server: bb.db at 9.1 GB, of which 6.7 GB is the events table and about 1.1 GB its indexes. 3,618 threads, 3,351 of them archived. zstd -10 shrinks it to 1.4 GB.
    • A remote server: bb.db at 4.2 GB. 1,670 threads, 1,622 of them archived. Exporting each archived thread as its thread row plus all of its events, as JSONL compressed with xz, takes 212 MB in total (about 130 KB per thread).

    So nearly all of the database is timelines of archived threads, and they compress by roughly 20×.

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

    perfthreads

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions