Repository navigation
Description
Summary
A synchronous request-history lookup used by timeline and thread runtime display took 26.531 s on a large self-hosted database. It finished 27 ms before the server reported a 28.563 s event-loop stall. The lookup should be bounded by the request IDs being fetched and should leave the server responsive even on threads with long request histories.
Versions and environment
- Incident: BB 0.49.0-based source build, Linux x86_64, ext4, SQLite in WAL mode. The lookup is present on upstream main at
fab82665a3299fae8910f55d7519a3b034a03b9a. The incident runtime's exact Node and embedded SQLite versions were not captured. - The database was 6.80 GB when sampled, with about 5.2 GB in the
eventstable itself and about 6.24 GB including its indexes. The server had a 12-CPU quota on a 16-vCPU host. - Standalone reproduction: Linux, Python 3 and SQLite 3.46.1. It uses synthetic data and the current-main lookup shape. No provider or Connect is needed.
Steps to reproduce
- Save the script below as
repro.pyand runpython3 repro.py. It creates a disposable WAL database and inserts 8,000 request events across two threads. It executes the same WHERE and ORDER BY shape as the current lookup, with a minimal projection schema. - Inspect the query plan and the wall and thread CPU times. The small fixture reproduces the plan and the history reads, not the incident's 26.5 s. The full-server timing is unverified on current main.
- To measure server impact on an isolated BB instance, seed long request histories with large payloads, fetch a timeline or runtime display that looks up request IDs across threads, and capture the actual bound plan, the slow DB log and an independent HTTP heartbeat. Compare warm and cold cache runs.
Standalone reproduction
import sqlite3, tempfile, time
from pathlib import Path
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "events.sqlite"
db = sqlite3.connect(path)
db.executescript("""
PRAGMA journal_mode=WAL;
CREATE TABLE events (
id TEXT PRIMARY KEY, thread_id TEXT NOT NULL, sequence INTEGER NOT NULL,
type TEXT NOT NULL, data TEXT NOT NULL);
CREATE INDEX events_thread_type_sequence_idx ON events(thread_id, type, sequence);
""")
kind = "client/turn/requested"
payload = "x" * 16384
db.executemany("INSERT INTO events VALUES (?, ?, ?, ?, ?)", (
(f"{thread}-{i}", thread, i, kind, f'{{"requestId":"r{i}","payload":"{payload}"}}')
for thread in ("a", "b") for i in range(4000)
))
db.commit()
db.close()
db = sqlite3.connect(path)
query = """
SELECT * FROM events
WHERE type = ? AND (
(thread_id = ? AND json_extract(data, '$.requestId') IN (?, ?)) OR
(thread_id = ? AND json_extract(data, '$.requestId') IN (?, ?))
)
ORDER BY thread_id, sequence
"""
params = (kind, "a", "r3999", "missing", "b", "r3999", "missing")
print("SQLite", sqlite3.sqlite_version)
for _, _, _, detail in db.execute("EXPLAIN QUERY PLAN " + query, params):
print(detail)
start_wall, start_cpu = time.perf_counter(), time.thread_time()
rows = db.execute(query, params).fetchall()
assert [row[0] for row in rows] == ["a-3999", "b-3999"]
print(f"{len(rows)} rows, {(time.perf_counter()-start_wall)*1000:.1f} ms wall, "
f"{(time.thread_time()-start_cpu)*1000:.1f} ms thread CPU")
db.close()Expected vs actual
Expected: the number of history rows read is bounded primarily by the selected request IDs. A routine timeline or runtime-display read should not block unrelated server requests for tens of seconds.
Actual, synthetic fixture:
SQLite 3.46.1
MULTI-INDEX OR
INDEX 1
SEARCH events USING INDEX events_thread_type_sequence_idx (thread_id=? AND type=?)
INDEX 2
SEARCH events USING INDEX events_thread_type_sequence_idx (thread_id=? AND type=?)
USE TEMP B-TREE FOR ORDER BY
2 rows, 113.7 ms wall, 113.4 ms thread CPU
Evidence
- Sanitized incident report, 2026-11-19 UTC. The server's
Slow DB querylog at 06:19:54.330 recordedoperation="all",bindingArgumentCount=16,durationMs=26530.7andcpuDurationMs=1784. The 06:19:54.357Event loop stalledentry recordedmaxDelayMs=28563.4. The query had five thread/ID branches and ordered matches by thread and sequence. - A read-only EXPLAIN on the incident database, with dummy parameters of the same shape and SQLite 3.46.1, matched the plan above. The existing index locates thread/type rows and leaves the JSON predicate to be evaluated afterward. The actual bound plan from the embedded SQLite was not captured. The wall/CPU gap suggests off-CPU wait, but does not identify which storage, locking or scheduler delay was involved.
What you ruled out
- The resolved-item prune advance was a separate synchronous transaction from a different sample. Its per-advance budget was addressed by #7254, included in 0.50.1. This report concerns the SELECT.
- #7473 concerns a correlated queued-retry acceptance query during turn submission. This is a direct lookup of stored requests used by read paths. #7753 documents broader stalls and planner statistics on another large database.
Suggested priority and effort (optional)
The observed impact was a server-wide pause during a read. Before choosing a migration, compare the bound plans, end-to-end latency, database growth and upgrade impact on a representative snapshot:
- An expression index on thread ID and extracted request ID (with type in the key, or a partial index if the actual bound predicate can use it) can avoid visiting unrelated JSON rows. Index build scans and writes on a large database, adds disk and write overhead, and may leave a sort when ordered results span several IDs.
- An indexed generated column gives multiple query paths a common key. It still needs an index build. A stored generated column also requires a table rebuild when added to an existing SQLite table.
- A separately maintained lookup table allows a staged, resumable backfill, with extra write and consistency costs. Moving the read off the main loop may improve responsiveness while leaving the scan cost in place.
Checks
- I reproduced the plan and query shape on synthetic data and stated which incident behavior has yet to be reproduced on current main.
- I searched open and closed issues for the same problem.
- This issue contains the sanitized investigation report and a standalone reproduction. The original investigation is private.
AGENT GENERATED
Activity
bb-slop-cop commentedon Nov 20, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotthreads,perf.partial-repro.Bound the client turn request lookup to the acceptance that consumed …
Fail the query cost check on undeclared growth with data size
Fail the query cost check on undeclared growth with data size
Fail the query cost check on undeclared growth, and bound nine histor…
Time server and plugin SQL in the query cost check, and fail every ca…