Skip to content

Prune exited terminals, drop dead pruning cursors, and vacuum plugin databases - #7106

Merged
ymichael merged 1 commit into
mainfrom
bb/implement-storage-cleanup-pr-thr_6zhhx8g7xk
Nov 6, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/implement-storage-cleanup-pr-thr_6zhhx8g7xk

Conversation

@ymichael

@ymichael ymichael commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Four pieces of storage were growing with nothing to remove them:

  • Exited terminal_sessions rows 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.
  • Archived threads kept their per-thread pruning cursors (8,028 rows). Archiving and late idle transitions run one live pruning step, and that step created a scoped cursor nothing used again; the background sweep is what finishes archived threads. Four completed_event_output_truncation scan cursors were also left over from a superseded migration.
  • Plugin data.db files were created with auto_vacuum=NONE (plugin-api.ts opened them with only WAL and busy_timeout), so free pages never left the file. The installed usage plugin's file is 195 MB, of which 178 MB is free pages.
  • A plugin update's rollback snapshot stayed for 7 days after the update settled (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

  • Exited terminals: new pruneExitedTerminalSessions (packages/db/src/data/terminal-sessions.ts) and an exited-terminal-session-prune sweep job. It deletes rows exited more than 7 days ago, 1,000 per 10 s tick, through a new partial index terminal_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.
  • Pruning cursors: archiving a thread still runs its one live pruning step, then deletes that thread's scoped cursors (deleteThreadScopedPruningCursors, called from thread-archive.ts); the background sweep finishes archived threads. Migration 0152_small_storage_cleanups deletes the existing archived-thread cursors and the dead truncation cursors, and creates the index.
    • The cleanup sits in the archive flow, not in the pruning step itself: the usage policy carries its keeper state across live steps, so deleting cursors after every step would stop a live pass on an archived thread from ever getting past its first policy. A turn that finishes during the archive undo grace still runs one idle step and can leave one scoped row behind; archiving again clears it.
  • Plugin databases: a new hourly plugin-database-maintenance job takes open handles from PluginService.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 in maintenance.ts now take the raw SQLite client so both sweeps share them.
  • Snapshots: activateManagedUpdate deletes its snapshot once the update settles. Startup GC (listDiscardablePluginStateSnapshots) also discards snapshots created by an earlier server process, except rollbacks still rollback-pending or restoring. That is what removes an existing install's leftover copy on its next restart.
  • Docs: docs/configuration.md (plugin data.db and the snapshots directory) and docs/events-table-pruning.md. No plugin SDK surface change.
  • No HOST_DAEMON_PROTOCOL_VERSION change: the daemon never opens bb.db or plugin databases.
  • Behaviour notes:
    • The default title of a new terminal ("Terminal N") counts a thread's terminals, including exited ones. After 7 days, exited terminals stop counting.
    • Two tests asserted the old snapshot retention ("keeps rollback state through the grace period", and a restored row 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.db and perf/data/subset.db; nothing ran against ~/.bb). The scrub emptied terminal_sessions and thread_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:

  • 186,399 exited threadless terminals spread over 50 days;
  • 8,028 scoped cursors on 4,014 archived threads.

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.

heavy.db + seeded rows Before After
terminal_sessions + indexes (incl. the new one) 51.3 MB 8.0 MB (26,095 rows from the last 7 days)
thread_pruning_cursors 1.01 MB 12 KB
dead truncation cursors 4 rows 0
File, incremental copy, after one runDatabaseMaintenanceSweep 3,920,027,648 B 3,870,126,080 B (−49.9 MB)
File, NONE copy 3,998,072,832 B unchanged; 55.8 MB moved to the freelist for reuse
  • Migration 0152 on heavy.db: cursor deletes 6–7 ms; the index build over 186k rows 43–91 ms (one time).
  • Sweep batches of 1,000 rows: 161 batches, p50 2.2 ms, p99 2.6 ms, max 3.6 ms. The backlog drains in about 27 minutes at one batch per tick. 256-row batches were 0.6 ms each but needed 104 minutes, so 1,000 matches the closed-session prune.

Usage 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 ran runPluginDatabaseMaintenanceSweep on it hourly:

File Freelist Sweep work
Before 194.9 MB 174.5 MB —
Hour 1 112.9 MB 92.6 MB 98 ms in 256-page chunks
Hour 2 30.9 MB 10.7 MB 62 ms
Hour 3 20.2 MB 0 7 ms

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):

  • pruneExitedTerminalSessions deletes only rows exited before the cutoff, oldest first, within the limit.
  • Archiving through the API leaves no scoped cursor for the thread, and draining live pruning afterwards still applies every retention rule (event-pruning.test.ts).
  • Migration 0152 keeps global and live cursors and drops archived and dead ones.
  • The plugin sweep empties an incremental plugin DB's freelist and neither vacuums nor converts a NONE one.
  • Startup GC drops ready/restored snapshots from an earlier process and keeps rollback-pending, restoring and this process's snapshots.
  • A settled update leaves no snapshot row or directory.

Commands:

  • turbo run lint typecheck --filter=@bb/db --filter=@bb/server
  • vitest in packages/db: terminal-sessions, thread-pruning, maintenance, completed-event-output-migration, migrate, query-plans, schema, plugin-state-snapshots, sweeps
  • vitest in apps/server: plugin snapshot/update/cache-prune/settings-storage, database-maintenance-sweep, periodic-sweeps, test/system, public-terminals, public-thread-lifecycle-ownership, services/threads

The full suites run in CI.

🤖 Generated with Claude Code

AGENT GENERATED

@ymichael
ymichael force-pushed the bb/implement-storage-cleanup-pr-thr_6zhhx8g7xk branch from c3bc1ca to aec42eb Compare November 6, 2026 00:03
@ymichael
ymichael merged commit 430db57 into main Nov 6, 2026
52 checks passed
@ymichael
ymichael deleted the bb/implement-storage-cleanup-pr-thr_6zhhx8g7xk branch November 6, 2026 04:03
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant