Repository navigation
Description
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 onmainat commitb0ddaad731565d7e4de68d824120d802fc78f7d5 - 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
- 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;
- Inspect
packages/db/src/data/thread-pruning.ts,packages/db/src/data/resolved-item-pruning.ts, andpackages/db/src/wal-checkpointer.tsonmain(b0ddaad731565d7e4de68d824120d802fc78f7d5).
4. Expected vs actual
Actual (measured read-only on live ~/.bb/bb.db):
bb.db: 23.31 GB (5,692,829pages,8freelist pages) + 457 MBbb.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 KBbb/provider-commandsdumps- First-delta rows retained permanently by
probePhase === 0 -> 1inresolved-item-pruning.ts: ~2.25M rows item/started: excluded fromPRUNABLE_THREAD_EVENT_TYPES
bb.db-walstays hundreds of MB becausewal-checkpointer.tsnever executesPRAGMA wal_checkpoint(TRUNCATE).
Expected:
- Prune/compact superseded or diagnostic event types (
provider/unhandled, supersededthread/extensionState/updatedsnapshots, 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 boundedjournal_size_limit) sobb.db-waldoes not remain pinned at ~457 MB.
5. Evidence
THREAD_PRUNING_POLICIES&PRUNABLE_THREAD_EVENT_TYPESomitprovider/unhandled,thread/extensionState/updated, anditem/started:
bb/packages/db/src/data/thread-pruning.ts
Lines 32 to 55 in b0ddaad
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.tsretains the first delta of every completed item (probePhase === 0 -> 1, exceptcommandExecution/outputDeltawhenhasStartedRowBeforeholds):
bb/packages/db/src/data/resolved-item-pruning.ts
Lines 244 to 268 in b0ddaad
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.tsonly runswal_checkpoint(PASSIVE)in both workercheckpointandcheckpointTail:
bb/packages/db/src/wal-checkpointer.ts
Lines 30 to 42 in b0ddaad
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; }
bb/packages/db/src/wal-checkpointer.ts
Lines 212 to 220 in b0ddaad
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
- Still present on
mainatb0ddaad731565d7e4de68d824120d802fc78f7d5. - Checked recent related commits:
264df353e(Move archived threads to cold storage from Storage & retention, with a thread.delete_finalize hook, export and import #7107 cold-storage archive export/import),df9619d8e(Prune duplicated command output and started file-change diffs #7806 duplicated command output & started file-change diffs), andbe3ca2cc3(Checkpoint SQLite WALs from a worker thread instead of inside commits (behind an experiment) #7108 worker-thread WAL checkpointer). None addwal_checkpoint(TRUNCATE)or pruneprovider/unhandled/ supersededthread/extensionState/updated/ first-deltas inbb.db. - Distinct from Slow / command lookup on remote servers: server stalls (hourly vacuum, timeline builds) dominate, not round trips #5192 (hourly vacuum / timeline stalls on remote servers): here the DB had only 8 freelist pages (the 23.3 GB is unpruned live rows, not unvacuumed freelist).
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
bb-slop-cop commentedon Nov 28, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotthreads,perf.partial-repro.