Skip to content

Run the hourly database vacuum in chunks that yield to requests - #5193

Merged
brsbl merged 2 commits into
mainfrom
bb/chunked-incremental-vacuum
Oct 19, 2026
Merged

brsbl merged 2 commits into
mainfrom
bb/chunked-incremental-vacuum

Conversation

@brsbl

@brsbl brsbl commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The hourly maintenance sweep ran one synchronous PRAGMA incremental_vacuum(20000) on the server’s main thread. The investigation in #5192 recorded request stalls of 9–69 seconds on an 8 GB database with 4.2 GB of free pages.

What changed

How you verified

  • The regression test verifies event-loop progress during vacuum and reclamation of more than one chunk.
  • One Slop Cop review passed all five panels on 45398863d60f7af26bc9aba0301dba9bc99ca151; no open P0/P1 findings.
  • Remote CI passed on 45398863d60f7af26bc9aba0301dba9bc99ca151, including six maintenance tests on Linux and Windows.
  • Built-server QA passed: 5,367 successful API/daemon requests, zero errors, and 20,000 pages reclaimed per sweep.
Real end-to-end comparison: measurements, commands, and limits

Compared main f9eae1c44cd67e3dcbf807809bda8999926f7967 with candidate 45398863d60f7af26bc9aba0301dba9bc99ca151 on Node v24.21.0. Each ran its separately built server with fresh data and loopback ports, plus an enrolled built host daemon. Main source came from git archive; unchanged workspace dependency packages were shared.

The synthetic 1.71 GB database contained 196,608 rows of 8 KiB blobs with alternating rows deleted. Both scheduled sweeps began with 195,937 free pages and reclaimed 20,000. The real scheduler triggered the hourly job on its first 10-second tick; no timer patch, test route, or direct maintenance invocation was used.

Three real GET requests ran every 20 ms for 18 seconds: /api/v1/system/config, /api/v1/hosts, and /api/v1/hosts/:id/files/:absoluteProofPath. File reads traversed the connected daemon and returned verified contents. Both daemons remained connected afterward.

During-sweep request latency Main p95 / max PR p95 / max
System config API 1,694 / 1,759 ms 257 / 1,253 ms
Host list API 1,676 / 1,739 ms 268 / 1,218 ms
Daemon file RPC 1,698 / 1,763 ms 825 / 1,330 ms

The PR completed 526 responses inside the maintenance window; main completed one just before its synchronous vacuum. Main logged a 1,717 ms incremental_vacuum(20000) call. The PR logged no vacuum/checkpoint statement above the existing 100 ms slow-query threshold.

The measurement window starts at server listening + 10 seconds and ends at the maintenance completion log. It includes preceding sweep jobs; distributions include requests overlapping that window. The window lasted 1,754 ms on main and 3,599 ms on the PR. Yielding improves responsiveness but adds total sweep time; the worst PR request remained 1,330 ms under approximately 150 requests/second. This does not claim tail latency is eliminated.

Commands used from the candidate checkout (QA scripts and raw logs retained in this thread’s .qa-5193/ directory):

pnpm exec turbo run build --filter=@bb/server --filter=@bb/host-daemon --concurrency=2
pnpm exec turbo run build --filter=@bb/cli --concurrency=2
(cd .qa-5193/main && pnpm exec turbo run build --filter=@bb/server --concurrency=2)
bb host-care start --title 'PR5193 isolated vacuum comparison' --command 'node .qa-5193/run.mjs' --retention temporary
node .qa-5193/summarize.mjs
bb host-care release job_405f0208a3a74185b34475f97c690379

The driver creates its data root using mktemp -d .qa-5193/data.XXXXXX, seeds SQLite, starts node apps/server/dist/index.js, enrolls via POST /internal/hosts/enroll-key, and starts node apps/host-daemon/dist/index.js. Both processes receive explicit isolated BB_DATA_DIR and port settings. All owned processes were cleaned up; no production data was used.

Coverage is the core API, scheduled maintenance, and real daemon RPC. Targeted builds lacked bundled plugin artifacts and emitted equivalent startup warnings; plugin/provider/UI behavior is outside this pass. Remote CI ran the tests; local builds only supported real-product QA.

Recommendation: SHIP this candidate, subject to the user’s merge decision. Nothing has been merged.

Part of #5192 (row 1: hourly vacuum)

BB-Thread: Investigate slow command lookup

BB-Thread-ID: thr_vg2ig7xcqm

AGENT GENERATED

One synchronous incremental_vacuum(20000) blocked the server event loop for
9-69s every hour on an 8 GB database. Vacuum the same 20,000 pages in
256-page chunks and yield to the event loop between them.

Fixes #5192

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T08:17:44.903600Z 9206326 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…l-vacuum

# Conflicts:
#	apps/server/test/services/database-maintenance-sweep.test.ts
@brsbl
brsbl merged commit 9937c46 into main Oct 19, 2026
28 checks passed
@brsbl
brsbl deleted the bb/chunked-incremental-vacuum branch October 19, 2026 00:25
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