Skip to content

Server stalls 15-18 s while synchronous SQLite event queries block the event loop (large bb.db) #6835

Open

Description

@Pryapus

On a single-user Mac Studio running bb 0.48.1 (server protocol 258), the server stopped logging for 15-18 s three times in one night (23:05:48-23:06:06, 02:01:48-02:02:03 and 04:30:16-04:30:32 UTC). Connected host daemons' event posts failed with fetch failed during exactly those gaps.

What the logs show:

  • select "type" from "events" where thread_id = ? and turn_id = ? took 7-17.5 s with only 0.4-0.8 s CPU (waiting on I/O). TRANSACTION IMMEDIATE took 5-11 s. There were 56 such slow selects in 8.5 h of uptime.
  • 29 of the 40 selects of 5 s or more ran within 30 s of "Slow thread event pruning". Pruning itself takes up to 3.4 s to remove 32 events (381 pruning warnings in 8.5 h).
  • bb.db is 6.45 GB and grows about 0.35 GB a day (WAL 79 MB). Under memory pressure the page cache cannot hold it, so these queries read from disk.

Two requests:

  1. Keep SQLite work off the server's event loop (a worker thread, or async batching for event reads and pruning), so slow disk I/O cannot freeze the whole server.
  2. Add an index that covers events(thread_id, turn_id) (or the query's access path), and make event pruning incremental and bounded so it does not hold long write transactions.

Environment: macOS 27 on Apple silicon, bb-app 0.48.1, about 40 concurrent agent threads. Logs are available on request.

Activity

  1. added theissue type on Nov 2, 2026
  2. added
    host
    threads
    partial-repro
    on Nov 2, 2026
  3. bb-slop-cop commented on Nov 2, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Classification: Bug · Priority: High · Effort: High · Labels: host, threads, perf, partial-repro.

    Reproduction and root-cause report — PARTIALLY REPRODUCED. Confidence: high for synchronous event-loop blocking; the reported cold-read I/O cause remains unverified.

    On trusted main (93411e8e6a), a controlled SQLite writer lock made the real daemon-event persistence transaction delay a 20 ms timer to approximately 739 ms in both clean-checkout runs. The root cause is synchronous SQLite transaction execution on the server thread. The covering thread/turn index and incremental, bounded pruning already exist; the original 15–18 second read stalls were not reproduced.

    The report includes the complete regression test: its heartbeat assertion fails as expected in both runs, while the index/pruning checks and 187 existing database tests pass.

    No pull request: guaranteeing off-thread database execution requires an architecture decision, outside the simple-fix criteria.

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

    hostpartial-reproperfthreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions