Repository navigation
Description
Summary
timelineWindowEventBudget is calibrated at ~0.06 ms/event. Measured on a 4-core VPS the real cost is 0.479 ms/event at p50, roughly 8x higher. The budget's stated goal of "a cold build near 100ms" therefore costs about 720 ms on this class of hardware, and each build blocks the event loop.
The constant
packages/domain/src/feature-flags.ts:31-37:
/**
* Measured on real threads a build costs ~0.06ms/event across the SQLite
* read, JSON decode, and projection. 1500 keeps a cold build near 100ms; the
* 10k-event thread that motivated the bound was ~670ms unbounded.
*/
timelineWindowEventBudget: 1_500,Measured on this host
bb 0.38.0, Ubuntu 22.04.5, 4 cores / 4.9 GiB, Node v24.19.0.
Across 541 samples taken from the server's own Thread timeline build blocked the event loop logging:
| metric | value |
|---|---|
| p50 | 0.479 ms/event |
| p90 | 0.964 ms/event |
| max | 5.55 ms/event |
A representative logged build: eventRowCount: 1257, decodedEventCount: 1257, eventDataBytes: 1481754, returning responseRowCount: 96 from segmentLimit: 20. Stage timings were event-query 82 ms, event-json-decode 181 ms, thread-view-projection 69 ms. So 1257 events were read and decoded to produce 96 rows.
Aggregate impact in one session: 532 logged slow builds totalling 155 seconds of blocked event loop, plus 1124 suppressed, for 1656 slow builds. In a single hour: 342. Event-loop stall samples (n=375) showed maxDelay p50 of 1098 ms, p95 of 5058 ms, and a maximum of 50.6 seconds.
The budget rarely binds
Of 76 threads on this install, only 2 exceed 1500 events. Six exceed 1000 and nineteen exceed 500. So for 74 of 76 threads the budget never applies and the full event set is read on every build.
Because the cache key includes maxSeq (timeline-cache.ts:126-130), every appended event invalidates the entry, so an actively updating thread rebuilds continuously and the previous entry becomes garbage. Each build churns roughly 0.5-1.5 MB of transient parsed JSON, which is a significant contributor to server heap pressure (see the related heap-sizing issue).
Suggested fix
The flag is already overridable via BB_FF_TIMELINE_WINDOW_EVENT_BUDGET (packages/config/src/env-vars.ts:233), and lowering it to 400 on this host puts cold builds near 190 ms and makes the budget bind for 19 threads instead of 2. That works as an operator workaround.
The underlying issue is that a fixed event count is a poor proxy for cost when per-event cost varies 8x across hardware. Options:
- Calibrate the budget at startup from a measured sample rather than a hardcoded constant.
- Budget on decoded bytes rather than event count, since
event-json-decodeis the dominant stage. - At minimum, document that the constant assumes fast hardware and should be lowered on small hosts, and mention the env var somewhere discoverable.
Worth noting the logging here is genuinely good. The Thread timeline build blocked the event loop records with per-stage timings are what made this measurable at all.
Activity
SawyerHood commentedon Aug 18, 2026
Reproduction & root-cause report: https://get-bb.github.io/reports/issues/1749.html
The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at
16ceb3a54, and repro artifacts. It was independently re-run by a second agent (see its Verification section).uje-m commentedon Aug 31, 2026
+1 with a fast-host repro — build cost is bimodal (p50 0.2 ms/event, max 270 ms/event), worst builds block the loop for 26–40s, and the stalls take down host heartbeats
Environment: bb 0.40.0 (stable), Ubuntu 24.04, Ryzen 7 5800X (8C/16T), 60 GiB RAM, NVMe, Node v24.15.0. Two actively-polled heavy threads out of 60+; long-lived agent threads with heavy tool outputs are my normal working pattern, not an outlier.
From one day of the same
Thread timeline build blocked the event looplogging — 2,038 logged slow builds on a single server instance:Per-event cost for the worst thread (n=524 builds): p50 0.2 ms/event, max 270 ms/event.
Two observations the count-based budget can't capture:
Causal isolation: while the two heavy threads were actively polled, the server logged 87 event-loop stall reports per 15 minutes (maxDelay commonly 3–7s, worst 13.7s). When those threads went idle — same install, same 60+ threads — stalls dropped to 0–5 per 10 minutes for the rest of the day.
Blast radius beyond UI latency: the host daemon's heartbeat lease is 30s. During the stall windows the daemon's event posts failed (
fetch failed) and the server dropped the host — surfacing to the user as "Host disconnected" and "Failed to send message" while the box sat at load ~3. So one thread's slow timeline build can take down message delivery for the whole install.Also noting: the
timelineWindowingexperiment was enabled mid-incident; it mounts nearby rows client-side, and as expected the server-side build cost above is unchanged.Happy to attach raw log lines — they carry
threadId/totalDurationMs/eventRowCount/decodedEventCount/eventDataBytes/responseRowCount/segmentLimit/selectionStrategy/pageKind, same shape as the OP's logging.