Skip to content

Slow / command lookup on remote servers: server stalls (hourly vacuum, timeline builds) dominate, not round trips #5192

Open

Description

@brsbl

Summary

On a remote bb server, the / command menu often took 0.4–2.9s to open. Profiling shows two separate costs:

  • Steady cost: the /commands request made several serial server→host-daemon round trips, and desktop did nothing ahead of time. That was about 0.3–0.6s on every lookup.
  • Variance: the server's main thread was regularly blocked by its own work, and every round trip queued behind it. This produced the 1–3s cases, and up to a minute during the hourly vacuum.

The single biggest bottleneck is the hourly incremental vacuum, which blocks the whole server for 9–69s every hour. Next are timeline rebuilds on long-running threads (0.2–9s each). Round trips and filesystem scanning are a much smaller share.

Every bb server runs this vacuum hourly once more than 1,024 pages are free. How long it blocks depends on database size and hardware. Each server is single-user, and a stall affects every device and daemon connected to that server.

Where the time goes

# Bottleneck Measured cost Scope Tracking
1 Hourly incremental_vacuum(20000) runs in one synchronous call 9–69s every hour; 1,087s over 30h All requests on the server #5193 (fix)
2 Timeline build reads the whole active turn 0.2–9.5s per build; about 2,300 builds over 30h Thread open and refresh, plus everything queued behind them #4674
3 listActiveBackgroundTaskCountsByThreadIds, CPU-bound p50 108ms, p99 186ms; 6,423 slow runs (721s) over 30h Thread and sidebar responses (about 0.1s each) not filed
4 Thread pruning advances about 140ms each; 3,787 slow (530s) over 30h Background, blocks the loop partly fixed on main (#5124, #5115)
5 /commands: 2 serial daemon round trips for project skills, plus 1 for provider commands about 1 RTT (100–200ms) per serial trip; 13 RPCs per call with 10 skills / lookup and thread start #5172
6 Desktop composer doesn't prefetch the / catalog first / waits for the full request (0.4–1.8s) Desktop / #5171
7 Daemon filesystem scan for commands and skills 20–160ms / lookup not worth changing
8 Server reads and hashes its own skills on each request 15–25ms (48 skills) / lookup not worth changing

Rows 1–4 come from the server logs; rows 5–8 come from direct measurement.

Versions and environment

  • Server: 0.45.1-nightly.37657450135.1 (commit 04c6371b8a), run by the bb-server.service systemd unit.
    • Linux, 4 vCPU, 7.9 GB RAM, 1.2 GB swap in use.
    • Data dir /root/bb-server/data.
  • Client and host daemon: macOS 26.5.2, bb-app 0.45.1-nightly.37657450135.1, connected to the server over the network. Server↔daemon RTT is about 100–200ms.
  • Database:
    • bb.db is 8.05 GB, with a 323 MB WAL.
    • auto_vacuum=INCREMENTAL, page_size=4096.
    • page_count=1,965,101 and freelist_count=1,026,702, so 4.2 GB (52%) of the file is free pages.
  • The code cited below is unchanged between 04c6371b8a and main at 53c1e870d1, except where noted.

Steps to reproduce

A. / latency against a remote server

  1. Connect a Mac host to a remote bb server, and open a project that has .bb/skills.

  2. Time the endpoint the / menu calls:

    for i in $(seq 8); do curl -s -o /dev/null -w "%{time_total} " "$BB_SERVER_URL/api/v1/projects/$PROJECT/commands?provider=claude-code&environmentId=$ENV"; done
  3. Repeat with provider=nonexistent. That returns before any daemon RPC, which gives you the baseline.

B. Vacuum stall, standalone (Node 22, node:sqlite):

import { DatabaseSync } from "node:sqlite";
const db = new DatabaseSync(process.argv[2]);
db.exec("PRAGMA page_size=4096; PRAGMA auto_vacuum=INCREMENTAL; PRAGMA journal_mode=WAL;");
db.exec("CREATE TABLE events(id INTEGER PRIMARY KEY, thread TEXT, data BLOB); CREATE INDEX ev_thread ON events(thread);");
const ins = db.prepare("INSERT INTO events(thread,data) VALUES (?, randomblob(?))");
db.exec("BEGIN");
for (let i = 0; i < 600000; i++) ins.run("t" + (i % 500), 1500 + (i % 7) * 200);
db.exec("COMMIT");
db.exec("DELETE FROM events WHERE id % 2 = 0");
db.exec("PRAGMA wal_checkpoint(TRUNCATE)");
let t = performance.now();
db.exec("PRAGMA wal_checkpoint(PASSIVE)");
db.exec("PRAGMA incremental_vacuum(20000)");   // what the hourly sweep runs
db.exec("PRAGMA wal_checkpoint(PASSIVE)");
console.log("one call:", Math.round(performance.now() - t), "ms");
t = performance.now();
for (let i = 0; i < 80; i++) db.exec("PRAGMA incremental_vacuum(250)");
console.log("80 x 250 pages:", Math.round(performance.now() - t), "ms total");

Run it with node repro.mjs /tmp/repro.db. That builds a 1.6 GB database with 172k free pages.

Expected vs actual

Expected: / opens with an already-loaded list in about 0.2s. Database maintenance and other background work never block requests for more than about 100ms.

Actual, / (step A):

provider=claude-code   1.05 2.94 1.75 1.83 0.56 0.40 0.49 0.99 s   (cold first call 1.42 s)
provider=codex         1.79 0.79 0.57 s
provider=nonexistent   0.10 0.51 0.20 0.34 0.13 0.15 0.19 0.11 0.21 0.12 s   (no daemon RPC)

Actual, vacuum (step B, M-series Mac with SSD):

incremental_vacuum(20000) blocked for 1115 ms
80 x incremental_vacuum(250): 553 ms total  (about 7 ms per chunk)

Actual, vacuum in production: all 32 hourly runs, Oct 7 01:02 to Oct 8 08:03 UTC.

10-07 02:02:51  durationMs 69355  cpuDurationMs 55016  PRAGMA incremental_vacuum(20000)
10-07 05:03:01  durationMs 65237  cpuDurationMs 50922
   ... (server restart 18:01)
10-07 19:02:34  durationMs 20206  cpuDurationMs  9014
10-08 08:03:29  durationMs  8980  cpuDurationMs  7456
total: 32 runs, 1,087 s wall, 891 s CPU; each frees about 80 MB of 4.2 GB free (about 51 more hours at this rate)

Each run lines up with a 9–11s Event loop stalled entry, for example 10-08 05:03:15 maxDelayMs 11601. That entry blames whatever request was in flight, such as bb-account.v1.waitForStatusChange, not the sweep.

Evidence

1. Hourly vacuum.

  • The hourly database-maintenance sweep (periodic-sweeps.ts#L205-L228) calls runIncrementalVacuum with MAX_PAGES = 20_000. That runs checkpoint, vacuum, checkpoint in one synchronous call.
  • Unlike the full-compaction branch (#L232-L238), it never checks isDatabaseMaintenanceIdle.
  • Terminal disconnects: 159 of 703 Terminal session disconnected logs fall inside vacuum windows, which cover under 1% of the time.

2. Timeline builds (#4674, timeline.ts#L1010-L1030):

  • thr_46gxq5dyzh had 254 logged builds totaling 123s. The worst was 7.1s and read 1,165 event rows (572 KB) for a latest page that returns 3–75 rows.
  • TRANSACTION DEFERRED has 2,907 slow entries totaling 1,024s. Its max of 9,466ms equals the worst timeline build.
  • Timeline builds overlap 98 of the 162 event-loop stalls longer than 1s.

3. Background-task counts (events.ts#L2281):

  • The query groups every background-task event per thread and calls json_extract on each.
  • 6,423 runs took ≥100ms (p50 108, p99 186, max 564ms). That is 721s of wall time and 703s of CPU, so it is pure CPU.
  • It runs a median of 144 times an hour, with a peak of 1,200.
  • About 80% of calls bind a batch of thread IDs, meaning thread lists. Single-thread responses also call it.

4. Pruning: 3,787 slow resolved-items/usage advances totaling 530s. #5124 and #5115 on main reduce this, but the server has not been deployed with them yet.

5. /commands fan-out (projects.ts#L728). Three branches run in parallel:

  • Provider commands (native-roots.ts#L252): a plugin host RPC (resolveNativeRoots, cached after the first call), then host.list_commands.
  • Project skills (workspace-skills.ts#L82): host.list_files over .bb/skills, then one host.read_file per SKILL.md.
  • Shared skills: host.list_skills.

The slowest branch is two serial trips warm and two cold. On a dev app with a 10-skill fixture, a single /commands call made 13 host RPCs on main and 2 with #5172. Server and daemon were local there, so it measures RPC count, not RTT.

6. Client (project-queries.ts#L302):

7. Daemon scan, timed locally against the claude-code roots:

  • resolveNativeRoots 17–171ms.
  • Root resolution 1ms.
  • discoverProviderCommands 22–157ms (26 commands from 9 roots). The first call is cold.

8. Server skill catalog (injected-skills.ts#L608): reading and SHA-256-hashing 48 server-side skills (78 files, 0.5 MB) took 14–24ms, timed on the production host.

How the server data was measured:

  • Read-only aggregation of /root/bb-server/data/logs/server.{50,51,52}.log, about 30h.
  • Page counts from opening bb.db read-only with node:sqlite.
  • Nothing was restarted or written.
  • Investigation thread: Investigate slow command lookup

What you ruled out

Suggested priority and effort

AGENT GENERATED

Activity

  1. added
    host
    on Oct 8, 2026
  2. added theissue type on Oct 8, 2026
  3. added
    confirmed-repro
    on Oct 8, 2026
  4. bb-slop-cop commented on Oct 8, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority High · Effort Low. Existing perf and host labels preserved.
    • Report: https://get-bb.github.io/reports/issues/5192.html — REPRODUCED, high root-cause confidence; reproduction label: confirmed-repro.
    • Root cause: the hourly sweep runs one synchronous 20,000-page vacuum without yielding. A regression test against trusted main failed in two clean checkouts: queued event-loop work waited 243ms / 240ms until maintenance finished. All 12 existing maintenance tests passed. Production 9–69s durations were not independently measured.
    • No new PR: PR #5193 already links this issue; a duplicate fix was skipped. Its code was not executed.

    AGENT GENERATED

  5. changed the title [-]Hourly incremental vacuum blocks the server event loop for 9–69s on large databases[/-] [+]Slow / command lookup on remote servers: server stalls (hourly vacuum, timeline builds) dominate, not round trips[/+] on Oct 8, 2026
  6. brsbl commented on Oct 19, 2026

    @brsbl
    CollaboratorAuthor

    Row 6 (desktop prefetch): #5171 is closed. After #5777, /commands also runs a live provider.list_commands probe. That probe can start a Claude Code CLI process per worktree cwd, cached for 2 minutes, so prefetching on desktop focus would add a CLI start to most thread opens. Prefetching on desktop needs a cheaper catalog path first: a server-side cache of live provider commands per host and provider, or a scan-only prefetch. The PR's focus flag would also need to reset on blur. Details are in the closing comment on #5171.

    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

    confirmed-reprohostperf

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions