Skip to content

bb.db unbounded growth (23.3 GB live data): unpruned event types, retained first deltas, archived history, and no wal_checkpoint(TRUNCATE) #8325

Backlog

Description

@vburojevic

1. Summary

Over ~4 months of daily heavy usage (~7,405 threads, 98% archived), ~/.bb/bb.db grew to 23.31 GB of live pages (only 8 freelist pages) plus a 457 MB -wal file. Four retention/checkpoint gaps combine to keep bb.db growing monotonically: high-volume provider/unhandled, thread/extensionState/updated, and item/started rows are excluded from pruning; resolved-item pruning retains the first delta of almost every completed item forever; 9.58M events across 7,256 archived threads remain in hot bb.db; and wal-checkpointer.ts only runs PASSIVE checkpoints and never truncates the WAL file.

2. Versions and environment

  • bb version: 0.50.1 (Desktop app on macOS), code verified on main at commit b0ddaad731565d7e4de68d824120d802fc78f7d5
  • OS: macOS 27.2.0 (arm64, Apple Silicon)
  • Setup: ~4 months continuous usage, 7,405 threads (7,256 archived), 11,018,557 rows in thread_events

3. Steps to reproduce

  1. Run read-only SQLite inspection against a long-lived ~/.bb/bb.db:
    • PRAGMA page_count; PRAGMA page_size; PRAGMA freelist_count;
    • SELECT type, COUNT(*), SUM(LENGTH(payload_json)) FROM thread_events GROUP BY type ORDER BY 3 DESC LIMIT 15;
    • SELECT COUNT(*) FROM thread_events te JOIN threads t ON t.id = te.thread_id WHERE t.archived_at IS NOT NULL;
  2. Inspect packages/db/src/data/thread-pruning.ts, packages/db/src/data/resolved-item-pruning.ts, and packages/db/src/wal-checkpointer.ts on main (b0ddaad731565d7e4de68d824120d802fc78f7d5).

4. Expected vs actual

Actual (measured read-only on live ~/.bb/bb.db):

  • bb.db: 23.31 GB (5,692,829 pages, 8 freelist pages) + 457 MB bb.db-wal.
  • thread_events: 11,018,557 rows total, of which 9,577,344 rows (87%) belong to the 7,256 archived threads (98% of threads).
  • Unpruned high-volume rows still retained in hot bb.db:
    • provider/unhandled: 901K rows (~3.2 GB)
    • thread/extensionState/updated: 20K rows containing repeated 38 to 53 KB bb/provider-commands dumps
    • First-delta rows retained permanently by probePhase === 0 -> 1 in resolved-item-pruning.ts: ~2.25M rows
    • item/started: excluded from PRUNABLE_THREAD_EVENT_TYPES
  • bb.db-wal stays hundreds of MB because wal-checkpointer.ts never executes PRAGMA wal_checkpoint(TRUNCATE).

Expected:

  • Prune/compact superseded or diagnostic event types (provider/unhandled, superseded thread/extensionState/updated snapshots, redundant first deltas on completed items, and eligible archived thread event payloads via cold-storage export or age policy).
  • Periodically truncate the WAL (wal_checkpoint(TRUNCATE) when idle/quiet, or bounded journal_size_limit) so bb.db-wal does not remain pinned at ~457 MB.

5. Evidence

  • THREAD_PRUNING_POLICIES & PRUNABLE_THREAD_EVENT_TYPES omit provider/unhandled, thread/extensionState/updated, and item/started:
    export const THREAD_PRUNING_POLICIES = [
    "rate-limits",
    "usage",
    "turn-diffs",
    "resolved-items",
    ] as const;
    export type ThreadPruningPolicy = (typeof THREAD_PRUNING_POLICIES)[number];
    const VERSION_BY_POLICY: Record<ThreadPruningPolicy, number> = {
    "rate-limits": 1,
    usage: 1,
    "turn-diffs": 1,
    "resolved-items": 2,
    };
    export const PRUNABLE_THREAD_EVENT_TYPES = [
    "provider/rateLimits/updated",
    "thread/tokenUsage/updated",
    "thread/contextWindowUsage/updated",
    "turn/diff/updated",
    "item/agentMessage/delta",
    "item/commandExecution/outputDelta",
    "item/reasoning/summaryTextDelta",
    "item/reasoning/textDelta",
    "item/backgroundTask/progress",
    ] as const satisfies readonly ThreadEventType[];
  • resolved-item-pruning.ts retains the first delta of every completed item (probePhase === 0 -> 1, except commandExecution/outputDelta when hasStartedRowBefore holds):
    const match = support.find((row) =>
    args.kind === "background"
    ? probe.probePhase === 0
    ? row.type === "item/backgroundTask/completed"
    : row.itemId === candidate.itemId
    : row.parentToolCallId === candidate.parentToolCallId &&
    (probe.probePhase === 1 ||
    (row.itemKind === kind &&
    (candidate.type !== "item/commandExecution/outputDelta" ||
    row.hasOutput !== 0))),
    );
    if (match) {
    if (
    args.kind === "background" ||
    probe.probePhase === 1 ||
    (candidate.type === "item/commandExecution/outputDelta" &&
    hasStartedRowBefore(db, args.threadId, candidate))
    ) {
    discarded.push(candidate.id);
    finished = true;
    } else {
    probe.probePhase = 1;
    probe.probeSequence = 0;
    probe.probeWitnessId = match.id;
    }
  • wal-checkpointer.ts only runs wal_checkpoint(PASSIVE) in both worker checkpoint and checkpointTail:
    function checkpoint(id, target) {
    const startedAt = performance.now();
    const row = target.database.pragma("wal_checkpoint(PASSIVE)")[0];
    const result = {
    walFrames: row.log,
    checkpointedFrames: row.checkpointed,
    durationMs: performance.now() - startedAt,
    };
    if (result.durationMs >= workerData.slowCheckpointMs) {
    parentPort.postMessage({ type: "slow", id, ...result });
    }
    return result;
    }

    function checkpointTail(database: Database.Database): number {
    const rows: unknown = database.pragma("wal_checkpoint(PASSIVE)");
    const row: unknown = Array.isArray(rows) ? rows[0] : undefined;
    return typeof row === "object" &&
    row !== null &&
    hasNumber(row, "checkpointed")
    ? row.checkpointed
    : 0;
    }

6. What you ruled out

7. Suggested priority and effort

Medium-to-high priority, medium effort: hits every heavy long-term user; 23 GB SQLite size degrades page cache locality, slows queries (3,244 slow queries / 731s sum in 18h), and consumes tens of GB of SSD space without a safe built-in prune path.

AGENT GENERATED

Activity

  1. added theissue type on Nov 28, 2026
  2. added
    threads
    partial-repro
    on Nov 28, 2026
  3. bb-slop-cop commented on Nov 28, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority: Medium · Effort: High · threads, perf.
    • Report: Reproduction and root-cause analysis.
    • Verdict: PARTIALLY REPRODUCED · root-cause confidence: high · label: partial-repro.
    • Root cause: Diagnostics and extension snapshots escape pruning. First text deltas intentionally preserve timeline placement; ordinary archiving does not enable cold storage. PASSIVE checkpoints retain allocated WAL space, but subsequent writes reuse it.
    • Verification: 63 tests pass in each of two clean trusted-main checkouts. The reported production size and latency were not verified.
    • No PR: Retention changes modify stored event data and require product/replay-safety decisions, outside the simple-fix gate.

    AGENT GENERATED

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

    partial-reproperfthreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions