Repository navigation
Prune exited terminals, drop dead pruning cursors, and vacuum plugin databases - #7106
Merged
Merged
Conversation
ymichael
force-pushed
the
bb/implement-storage-cleanup-pr-thr_6zhhx8g7xk
branch
from
November 6, 2026 00:01
49a7044 to
c3bc1ca
Compare
…databases Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/implement-storage-cleanup-pr-thr_6zhhx8g7xk
branch
from
November 6, 2026 00:03
c3bc1ca to
aec42eb
Compare
This was referenced Nov 7, 2026
Merged
ymichael
added a commit
that referenced
this pull request
Nov 9, 2026
…y on failure (#7240) ## Human comments ## What was wrong Production logs (Nov 6 08:00 to Nov 7 10:46) show slow terminal API calls: `POST /api/v1/terminals` (1,444 slow, median 160 ms), `GET /terminals/:id/output` (1,079, median 133 ms) and `POST /terminals/:id/close` (354, median 199 ms). Nearly all of them come from the usage plugin, which starts 10 to 15 terminals at once about every 12 minutes. 90% of these calls overlap an event-loop stall record (median max delay about 200 ms). During those bursts, the sampled stall stacks are mostly the usage plugin's own SQLite work on its `data.db` and its JS (about 15 of 30 sampled seconds), plus GC (6 s). Core's terminal code accounts for about 0.2 s. The daemon terminal handlers that the stall summary names (`ws:daemon terminal.exited/replay/output`) run for a median of 1 to 2 ms wall time, so that bucket is a labelling problem (O4), not slow work. The queries are indexed, and #7106 already prunes exited `terminal_sessions` rows (the snapshot has 25,542, down from 186k). Reproducing the plugin's pattern against a real server and daemon (15 concurrent create, then poll `get` and `output` with `tailBytes=900000`, then force close, with 300 KB of output per terminal) found two real per-call costs in core: - **Every `terminal.output` chunk from the daemon read the `terminal_sessions` row before checking whether any browser was attached.** Headless terminals never have a browser attached, so each chunk cost a query for nothing. The handler also advanced `forwardedNextSeqByTerminalId` for output nobody received. Because of that, a browser that reattaches while the daemon is disconnected caught up from that sequence and missed the output in between. - **`normalizeRpcJsonResult` built a path string for every node of every plugin RPC result.** It shows up in the stall stacks as `host-policy.ts` `visit` (about 1 s of sampled stall time). On the usage plugin's real `dashboard` result (4,888 rows, 2.35 MB of JSON) it took 10 to 14 ms median, about 4× `JSON.stringify`. ## What changed - `apps/server/src/services/terminals/terminal-session-lifecycle.ts`: for `terminal.output`, the handler still records flow-control output, then returns before the DB lookup when the terminal has no browser clients. Forwarding to attached browsers works as before. - Same file: `detachBrowserTerminal` forgets the forwarded sequence when the last browser leaves. Otherwise a browser that watched and left kept it at its last position, and a new browser attaching during a daemon disconnect caught up from there and missed the earlier output. - `packages/plugin-sdk/src/internal/host-policy.ts`: `normalizeRpcJsonResult` keeps a stack of path segments and builds the path only when it reports a problem. It uses `Object.keys`/`Reflect.get` instead of `Object.entries` and `Object.getOwnPropertySymbols` instead of `Reflect.ownKeys().some(...)`. Messages, sparse-array handling and the cycle/DAG rules are unchanged. - Plugin SDK bumped to 0.6.134 (`scripts/bump-plugin-sdk.mjs --patch`), because `dist/internal/host-policy.js` and `dist/testing/index.js` changed. - No wire, CLI or docs changes. The usage plugin's own main-thread cost (its SQLite transactions and its 335 ms dashboard query) is not changed here. A proposal for isolating plugin server work is in the coordinator's report. ## How you verified - New test `public-terminals.test.ts` › "catches a reattached browser up from its own position after output no browser was watching". On origin/main it fails with `sinceSeq: 3` (expected `0`); with the fix it passes. Its second case ("a browser watched and then left") fails with `sinceSeq: 2` without the detach change. - Live repro (real server and daemon, a WebSocket client attaching like a browser, `kill -STOP`/`-CONT` on the daemon): a viewer opening a terminal with `sinceSeq=0` during the disconnect started at `tick 3`/`tick 6` on main and on the first commit, and starts at `line 0` with both changes. - New `packages/plugin-sdk/src/__tests__/rpc-json-result.test.ts`: covers the exact path messages for non-finite, undefined, class-instance, symbol-key and cyclic values, and checks that shared non-cyclic values and sparse arrays still copy. - Burst repro (real server and daemon in one process, 3 rounds of 15 terminals with 300 KB of output each): | | before | after | |---|---|---| | SQL statements executed | 7,623 | 1,477 | | `terminal_sessions` lookups by id | 7,378 (one per output chunk + per API call) | 1,236 (per API call only) | | `getTerminalById` from `handleDaemonTerminalMessage` in the CPU profile | 485 ms | 0 | Wall and CPU times in that repro were not usable: the load average was 35 to 60 from other fix threads. - `normalizeRpcJsonResult` on the real dashboard payload: median 9.9 to 14.5 ms (min 5.8) before, 2.4 to 2.6 ms (min 2.2) after, over 3 runs of 40 at load average about 55. `JSON.stringify` of the same value takes 2.5 to 3.8 ms. - `pnpm exec turbo run typecheck --filter=@bb/server --filter=@get-bb/plugin-sdk --filter=@bb/domain`: passes. - `pnpm exec turbo run test --filter=@get-bb/plugin-sdk --filter=@bb/domain`: passes (418 and 316 tests). - `pnpm exec turbo run test --filter=@bb/server`: 3,939 passed and 2 timed out (`install-machine-script`, `timeline-in-turn-window`, both 15 s timeouts at load about 40). Both files pass on rerun, along with `public-terminals` and `plugin-wire`. - `node packages/plugin-sdk/scripts/check-npm-version-guard.mjs`: passes after the bump. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 9, 2026
… (behind an experiment) (#7108) ## Human comments ## What was wrong bb's main SQLite connection kept SQLite's default `wal_autocheckpoint=1000`, so whichever commit pushed the WAL past 1,000 frames ran the checkpoint inside that commit on the event loop. That meant copying frames into the database file plus two fsyncs. On a large database this stalls writes for seconds: the cold-tier investigation measured checkpoint p999 at 256 ms and a max of 2.75 s for 250 frames on an 8.4 GB file (PLAN.md §4). The hourly incremental-vacuum sweep also ran explicit `wal_checkpoint(PASSIVE)` calls on the main thread around every 256-page chunk. Plugin `data.db` handles have the same problem at a smaller scale. On a synthetic 200 MB plugin-sized database, each inline autocheckpoint costs the commit 18–22 ms (commit p999 18–20 ms with autocheckpoint on, 2.2 ms with it off). ## What changed **Behind an experiment.** Everything below runs only while the `walCheckpointWorker` experiment is on (Settings → Experiments → "Background database checkpoints", `bb settings experiment walCheckpointWorker true`). It is off by default and also off for early adopters. `startGatedWalCheckpointer` (`apps/server/src/services/system/wal-checkpoint-experiment.ts`) wraps `startWalCheckpointer` with the same interface and follows `config-changed` live. Turning it on starts the worker and attaches bb.db and the open plugin databases; turning it off runs a final checkpoint, stops the worker and restores `wal_autocheckpoint=1000`. While it is off, behaviour matches main: commits checkpoint inline, and the incremental vacuum runs a PASSIVE checkpoint before and after each chunk (moved out of `runIncrementalVacuum` into the chunk loop; with the experiment on, those calls wait for a worker pass instead). Test servers still use `startWalCheckpointer` directly. Documented in `docs/configuration.md` and `bb guide customization`. - `packages/db/src/wal-checkpointer.ts` (new): `startWalCheckpointer({ logger })` starts one `worker_threads` worker. It opens its own `better-sqlite3` connection (the same addon file as the main thread, so one SQLite copy per process) for each attached database and runs `wal_checkpoint(PASSIVE)`: - every 100 ms; - immediately again while the WAL is at 4,096 frames or more and still growing or not fully backfilled. `attach(database)` sets `wal_autocheckpoint=0` on the caller's connection once the worker has opened the file. Until then, and whenever the worker isn't running, commits keep checkpointing as before. `checkpoint(database)` waits for one worker pass. `detach(database)` closes the worker's connection and restores the old autocheckpoint value. `stop()` runs a final checkpoint and exits the worker. - **Starvation backstop.** PASSIVE never takes the writer lock. But with back-to-back writes, SQLite only restarts the WAL when a write begins while the log is fully backfilled, and that may never happen while the worker is mid-pass. If the WAL keeps growing past 16,384 frames (64 MB at 4 KB pages) across two worker passes, the worker pauses and asks the main thread to checkpoint the remaining tail between tasks. The worker has already backfilled almost everything, so the tail is small: the unit test logged 38 frames in 0.2 ms. The next write then restarts the log. This is the one place a checkpoint still runs on the main thread, it only happens under sustained write starvation, and it is logged ("Sustained writes outpaced the WAL checkpoint worker…"). It never fired in the server benchmarks below. A reader that pins the WAL (for example a `VACUUM INTO` copy) also stops the WAL from backfilling, but the main thread can't get past that reader either. So the worker only reports starvation, or re-runs a pass immediately, when the previous pass made checkpoint progress or the WAL restarted. While a reader pins the WAL, it simply retries every 100 ms until the reader finishes. Before this guard, an 8.6 GB production-snapshot clone logged about 2,000 "Sustained writes…" lines per 15 s reader. - FULL/RESTART from the worker were rejected. They hold the writer lock, and a main-thread deferred transaction that reads and then writes gets `SQLITE_BUSY` immediately when another connection holds that lock; SQLite skips the busy handler for a read-to-write upgrade. - **Worker crash.** If the worker exits unexpectedly, every attached connection returns to commit checkpoints right away, the pending `checkpoint`/`detach` promises resolve, a warning is logged, and a worker that had started successfully is restarted after 10 s and re-attaches everything. A worker that cannot start (or a database it cannot open) leaves those connections on commit checkpoints and logs a warning, with no restart loop. Invalid worker messages terminate the worker instead of throwing on the main thread. - **Server** (`start-server.ts`): attaches bb.db after `initDb` and stops the checkpointer last in shutdown, after plugins stop and the HTTP server closes. `walCheckpointer` is now an `AppDeps` field. - **Incremental-vacuum sweep:** `runIncrementalVacuum` no longer checkpoints. `runChunkedIncrementalVacuum` awaits `walCheckpointer.checkpoint(client)` between chunks, so the WAL still restarts every chunk, but the copy and fsync happen off the event loop. This covers bb.db and the plugin databases that the hourly sweep now also vacuums (#7106). - **Plugin databases:** `storage.database()` attaches each plugin `data.db`. The runtime detaches after closing the handle on dispose and on candidate discard, and awaits the detach (`discardCandidate` is now async) before snapshot restore or uninstall can touch the files. This matters most on Windows and for `restorePluginStateSnapshot`, which deletes `-wal`/`-shm` and overwrites `data.db`. `PluginServiceDeps.walCheckpointer` is optional: isolated plugin tests omit it, and those plugin databases keep commit checkpoints. - **Not changed:** plugin-update snapshots still `TRUNCATE`-checkpoint the plugin file once before copying it. - No `HOST_DAEMON_PROTOCOL_VERSION` bump: the daemon never opens bb.db. No CLI, SDK or setting surface. ## How you verified **Experiment gate:** `apps/server/test/services/wal-checkpoint-experiment.test.ts` checks that bb.db keeps `wal_autocheckpoint=1000` while the experiment is off, goes to 0 once it is turned on, and returns to 1000 when it is turned off (fails if the gate is bypassed). Live on `pnpm start:worktree`: toggling with `bb settings experiment walCheckpointWorker` took the server from 13 to 14 threads and back. Rerun on a 10 GB copy of a production bb.db (≈410 commits/s for 60 s, two runs each): with the worker, main-thread samples in `sqlite3WalCheckpoint` went from 695/620 to 0, commit p99 from 12.7/11.5 ms to 1.0/0.8 ms, and the slowest commit from 148/64 ms to 15/35 ms. **Independent check on an 8.6 GB production-snapshot clone (perf audit thread, 18 s runs):** main-thread samples in `sqlite3WalCheckpoint` went from 1,656–2,526 per run (about 80% of them in fsync) to 0. Commits that checkpointed inline went from 110–124 per run to 0. Total transaction time fell from 7,688 to 3,510 ms, and transaction p99 from 39.6 to 8.1 ms. **Tests (each fails with its mechanism removed, checked by mutation):** - `packages/db/test/wal-checkpointer.test.ts`: - Back-to-back writes from the main connection with no inline checkpoints still restart the WAL (header checkpoint sequence advances). With the starvation backstop disabled: 0 restarts. - A reader that pins the WAL while it grows past twice the starvation threshold logs no "Sustained writes…" line, and the WAL restarts once the reader commits. Without the progress guard: 65–158 lines. - `stop()` backfills the remaining WAL and restores `wal_autocheckpoint=1000`. - After `detach()` resolves, the worker has released the files (the last close deletes `-wal`). - A database the worker cannot open stays on commit checkpoints, with a warning. - `apps/server/test/services/database-maintenance-sweep.test.ts`: the vacuum sweep restarts the WAL between chunks without main-thread checkpoints (without the `checkpoint()` wait: 0 restarts). - `apps/server/test/services/plugins/plugin-settings-storage.test.ts`: a plugin's `data.db` runs with `wal_autocheckpoint=0`, and its WAL file is gone once the plugin service stops (without the runtime's detach: the file remains). - Locally: `turbo run typecheck --filter=@bb/db --filter=@bb/server`, plus the files above and `periodic-sweeps`, `plugin-update` and `plugin-state-snapshot` tests. CI runs the full suites. **Dev server over a scrubbed heavy.db clone** (3.9 GB, 4,426 threads): - Setup: - origin/main `fa30b0a7dc` vs this branch, the same production `apps/server` bundle built from each. - A fresh `cp -c` clone of heavy.db per run; `env -i` (no account-pool or BB_* variables); 60–90 s warm-up. - 180 s of load: list/get/timeline/events reads about every 50 ms, a rename → `thread:changed` push probe every second, and 4 writers renaming archived threads back to back (≈400–500 writes/s through the main connection). - Runs alternate main and branch. The machine was shared with another thread's 70-minute benchmark (load average up to 30), so neighbouring pairs are the fair comparison. Ten runs, in this order: main1, branch1, main2, branch2, branch3, main3, main4, branch4, branch5, main5. The other benchmark was loading the machine during pairs 1–3 (load average up to 30). Pairs 4–5 ran on a quiet machine (load average about 5). | run | writes/s | list p50 / p99 | get p50 / p99 | timeline p50 / p99 | events p50 / p99 | push p50 / p99 | write p50 / p99 | event-loop p99 (worst 5 s) | WAL frames p50 / max | WAL restarts | main-thread samples in `sqlite3WalCheckpoint` | worker samples in it | |---|---|---|---|---|---|---|---|---|---|---|---|---| | main1 | 393 | 6.5 / 87.1 | 2.2 / 69 | 7.6 / 149.5 | 7.5 / 101.6 | 4.5 / 101.5 | 2.7 / 44 | 86.6 | 529 / 1415 | 1740 | 887 / 15800 | 0 | | branch1 | 502 | 6 / 15.3 | 1.8 / 6.3 | 5.8 / 39.2 | 6.8 / 14 | 3.3 / 13.6 | 2.5 / 6.1 | 31.0 | 2369 / 6317 | 558 | 0 / 15490 | 450 | | main2 | 468 | 6.2 / 33.7 | 2 / 46.2 | 6.6 / 70.1 | 7 / 62.1 | 3.9 / 139.1 | 2.7 / 16.1 | 51.6 | 538 / 1296 | 2053 | 662 / 15510 | 0 | | branch2 | 450 | 6.2 / 100.3 | 1.9 / 67.2 | 6.6 / 108 | 7.1 / 81.2 | 4 / 66 | 2.7 / 22.5 | 65.4 | 1892 / 6025 | 593 | 0 / 15553 | 488 | | branch3 | 432 | 7.3 / 122.4 | 2.1 / 67.4 | 7.5 / 189.2 | 7.9 / 145.1 | 4.5 / 220.4 | 2.9 / 27.9 | 95.3 | 2006 / 5983 | 564 | 0 / 16134 | 618 | | main3 | 477 | 6 / 43.5 | 1.9 / 20.6 | 6.2 / 80.4 | 6.8 / 42.5 | 3.3 / 73.8 | 2.6 / 17 | 36.9 | 507 / 1248 | 2076 | 572 / 15460 | 0 | | main4 | 496 | 5.5 / 23.2 | 1.8 / 11 | 5.9 / 59.5 | 6.6 / 13.9 | 3.5 / 24 | 2.5 / 9.1 | 35.3 | 523 / 1263 | 2173 | 543 / 15594 | 0 | | branch4 | 508 | 5.4 / 16.3 | 1.8 / 8.8 | 5.7 / 50.9 | 6.4 / 15.1 | 3.1 / 13.8 | 2.4 / 5.6 | 36.4 | 2166 / 7115 | 615 | 0 / 15585 | 406 | | branch5 | 507 | 5.6 / 16.5 | 1.8 / 4.6 | 5.6 / 40.4 | 6.5 / 11.9 | 3.1 / 21.3 | 2.4 / 5.8 | 42.1 | 2217 / 7554 | 597 | 0 / 15556 | 383 | | main5 | 491 | 5.9 / 19.1 | 1.9 / 8.6 | 6.1 / 48.9 | 6.8 / 16.4 | 3.2 / 25.1 | 2.5 / 8.7 | 31.8 | 540 / 1279 | 2124 | 635 / 15444 | 0 | Median across runs (p99, ms): | | list | get | timeline | events | push | write | event-loop p99 | |---|---|---|---|---|---|---|---| | origin/main (5 runs) | 33.7 | 20.6 | 70.1 | 42.5 | 73.8 | 16.1 | 36.9 | | branch (5 runs) | 16.5 | 8.8 | 50.9 | 15.1 | 21.3 | 6.1 | 42.1 | Reading it: - **No checkpoint on the main thread.** - In each run's 20 s `sample` (1 ms interval) of the server process, origin/main's main thread spends 543–887 samples (3.5–5.7% of its time) inside `sqlite3WalCheckpoint`. - The branch has 0 main-thread samples there in all five runs; its 383–618 checkpoint samples are all on the worker thread. - The starvation backstop never fired: no "Sustained writes outpaced…" lines, and no worker warnings in any branch log. - **The WAL stays bounded under sustained writes** (400–500 renames/s for 180 s): - p50 1.9–2.4k frames, peak 6.0–7.6k frames (≤ 31 MB WAL file), restarting about 600 times per run. - origin/main peaks at about 1.4k frames, because each commit that crosses 1,000 frames checkpoints inline. The branch trades a somewhat larger WAL for no commit-time checkpoints. It is capped by the 4,096-frame catch-up and the 16,384-frame backstop. - **Request and push p99 don't get worse.** - The median p99 across the five runs improves for every request kind: list 33.7 → 16.5 ms, get 20.6 → 8.8, timeline 70.1 → 50.9, events 42.5 → 15.1, push 73.8 → 21.3, write 16.1 → 6.1. - p50s are unchanged or slightly lower. - On the quiet machine (pairs 4–5) the branch is lower on every p99 except events in pair 4 (13.9 → 15.1 ms). - Branch2 and branch3 are worse than their neighbours; they ran during the other benchmark's heaviest windows, and so did main1's high numbers. - **Event-loop p99 (worst 5 s window) doesn't improve at the median** (36.9 → 42.1 ms; 31–95 ms on the branch, 32–87 ms on main). Every run, on both builds, has the same ~270 ms worst stall: a periodic slow `events` query in the sweep, unrelated to checkpoints. - **Idle cost.** With nothing writing, the worker's ten no-op PASSIVE passes per second cost about 40 ms of CPU per 30 s (≈ 0.13% of one core), measured on a subset.db clone. Raw per-run data (load summaries, WAL samples, event-loop log, `sample` output, server logs) is in the thread's storage under `perf/runs/`. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Four pieces of storage were growing with nothing to remove them:
terminal_sessionsrows were never deleted. The usage plugin's scans leave about 3.7k a day. The storage report measured 186,399 exited rows, 41 MB with their 6 indexes. Nothing reads them: the daemon keeps an exited terminal's output for 30 minutes (HOST_DAEMON_TERMINAL_EXIT_RETENTION_MS), and the UI shows only live sessions.completed_event_output_truncationscan cursors were also left over from a superseded migration.data.dbfiles were created withauto_vacuum=NONE(plugin-api.tsopened them with only WAL and busy_timeout), so free pages never left the file. The installedusageplugin's file is 195 MB, of which 178 MB is free pages.plugins/snapshots/usage, another 195 MB). Only a failed stabilization ever reads it, and the replaced artifact it would roll back to is deleted as soon as the update settles.This is PLAN.md §6 items 3 and 3b of the bb.db storage plan (thr_y6xhxw8t8w).
What changed
pruneExitedTerminalSessions(packages/db/src/data/terminal-sessions.ts) and anexited-terminal-session-prunesweep job. It deletes rows exited more than 7 days ago, 1,000 per 10 s tick, through a new partial indexterminal_sessions_exited_prune_idx(updated_at, id WHERE status = 'exited'). With the index, the steady-state empty check costs about 0.03 ms instead of a scan of every exited row.deleteThreadScopedPruningCursors, called fromthread-archive.ts); the background sweep finishes archived threads. Migration0152_small_storage_cleanupsdeletes the existing archived-thread cursors and the dead truncation cursors, and creates the index.plugin-database-maintenancejob takes open handles fromPluginService.listOpenPluginDatabases()and returns the free pages of those in incremental auto-vacuum mode, using the same chunked incremental vacuum bb.db uses. The freelist/mode/vacuum primitives inmaintenance.tsnow take the raw SQLite client so both sweeps share them.storage.database()create newdata.dbfiles withauto_vacuum = INCREMENTAL, so new plugin files get this sweep. This branch is rebased on it.activateManagedUpdatedeletes its snapshot once the update settles. Startup GC (listDiscardablePluginStateSnapshots) also discards snapshots created by an earlier server process, except rollbacks stillrollback-pendingorrestoring. That is what removes an existing install's leftover copy on its next restart.docs/configuration.md(plugin data.db and the snapshots directory) anddocs/events-table-pruning.md. No plugin SDK surface change.HOST_DAEMON_PROTOCOL_VERSIONchange: the daemon never opens bb.db or plugin databases.restoredrow after restart); they now assert the snapshot is gone.How you verified
Measurements on the scrubbed copies (APFS clones of
thr_n6cyn6sk25/perf/data-heavy/heavy.dbandperf/data/subset.db; nothing ran against~/.bb). The scrub emptiedterminal_sessionsandthread_pruning_cursors. As-is, both copies save nothing: heavy.db's only affected rows are the 4 dead truncation cursors, and the new empty index adds 4 KB. To get numbers at production scale, I seeded a heavy.db clone with the report's counts:I then ran the real migration and the sweep function. The seeded rows are about 20% larger than production's (51 MB against 41 MB), so expect the production saving to be about 20% smaller.
terminal_sessions+ indexes (incl. the new one)thread_pruning_cursorsrunDatabaseMaintenanceSweepUsage plugin database. No copy exists under the scrubbed directories, and I didn't copy the live one. I measured on a synthetic DB with the same shape (195 MB file, 175 MB free after the plugin's delete pattern), created in incremental mode the way #7101 makes
storage.database()create files, and ranrunPluginDatabaseMaintenanceSweepon it hourly:The 195 MB Oct 29 snapshot copy goes at the next restart; that is covered by the GC test below, not observed live. Together that is the plan's −373 MB for the usage plugin, except the 178 MB inside the existing NONE file, which needs the offline compact.
Tests (each fails without its change):
pruneExitedTerminalSessionsdeletes only rows exited before the cutoff, oldest first, within the limit.event-pruning.test.ts).ready/restoredsnapshots from an earlier process and keepsrollback-pending,restoringand this process's snapshots.Commands:
turbo run lint typecheck --filter=@bb/db --filter=@bb/serverThe full suites run in CI.
🤖 Generated with Claude Code