Repository navigation
Description
Summary
Building a thread's latest timeline page reads and decodes every event of every turn that touches the page, whatever timelineWindowEventBudget says. Agent turns can stay open for hours. When they do, each latest-page build decodes tens of thousands of events and tens of MB of JSON synchronously on the server's event loop. Every other request waits behind it, including the thread list and plugin RPCs.
This is related to #1749 (the per-event cost) and #3951 (rebuilds that are not shared), but it is a separate cause. The budget is bypassed entirely once a single turn is larger than the budget.
Where
apps/server/src/services/threads/timeline.ts, in selectStandardTimelineEventRows (upstream 049d6a932, around line 999). The group-context-query loop calls listStoredTimelineTurnEventRows with sequenceStart: epochSequenceStart and beforeSequence: maxSeq + 1 for every turn id on the page. It repeats until no new turn ids appear. A running turn with N events therefore costs N rows for every build, both at the tip and on older pages of the same turn.
The tests in apps/server/test/services/threads/timeline-in-turn-window.test.ts pin this behaviour. One example is "bounds a running turn that is larger than the whole budget", which asserts that the budgeted eventRowCount equals the unbudgeted count. The behaviour exists because leaf-index content cursors (contentCursor.beforeLeaf, contentPage.total) and stable turn summaries need the whole turn projected. So this looks like a design limit rather than a one-line bug.
Measured (one server, one day)
bb 0.44.0 (fork of upstream; the timeline code above is unchanged from upstream), Ubuntu 24.04, 32 cores, Node 22.22, about 20 concurrently running agent threads.
- 371
Event loop stalledrecords in one day. The median stall was 0.77 s and the worst 5.9 s. - 254 of the 371 had
slowestWork=timeline-build. - A representative profile:
pageKind: latest,segmentLimit: 20,eventRowCount: 13463,eventDataBytes: 26.9 MB. - The two threads behind most of the stalls each had one open turn: 9,995 events (21 MB) over 17 hours, and 18,361 events over 39 hours.
- A thread with 75,000 events in total but small turns caused no stalls. The cost follows turn size, not thread size.
- The latest-selection memo (
timeline-selection-memo.ts) absorbs only delta appends. Any non-delta event, such as a tool item starting or completing, misses the memo and triggers a full rebuild. An active agent produces those every few seconds.
Expected
A latest-page build's cost is bounded by the page, or at least is not repeated in full on every append to an open turn.
Options we see
- Cache decoded and projected output for the open turn, keyed by thread and max sequence. Extend it incrementally on append, and coalesce latest builds per thread. There is no wire change. We are prototyping this in our fork and will report numbers here.
- Move the decode and projection off the event loop (worker or chunked).
- Make open-turn content pagination sequence-based, so a page reads only its window. This changes the contract.
Workaround
We now hand off (replace) any thread whose recent turn exceeds 5,000 events once the thread goes idle. This caps the damage, but agents that block inside one turn still grow it until they stop.
Activity
mistakeknot commentedon Oct 2, 2026
Numbers from the fork prototype of option 1. Like the issue, it makes no wire-contract change, and the five pinned tests in
timeline-in-turn-window.test.tspass unchanged.There are two parts:
item/startedanditem/completedrows of the kinds agentMessage, commandExecution, fileChange, fileRead and reasoning, in turns it already knows. Tool calls, parented rows and turn lifecycle rows still rebuild.events-appendedrefresh. That refresh survives cache eviction and replacement, and is dropped on delete and history rewrite. Cache entries are keyed on every projection input, including the thread title, workspace root and plan command.Synthetic run: one running turn of 10,000 events, then 200 mixed appends (tool item started, output delta, item completed, message delta).
The response once the burst settles equals a cold build.
The first build after a cache miss still costs the full projection, so this mitigates the problem rather than fixing it. A truly page-bounded build would still need option 2 or option 3. Happy to send this as a PR if the approach is acceptable.
bb-slop-cop commentedon Oct 2, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotthreads,perf.confirmed-repro.brsbl commentedon Oct 8, 2026
More production evidence for this, from a remote server running
0.45.1-nightly.37657450135.1(04c6371b8a), Linux with 4 vCPU and an 8 GBbb.db. It covers about 30h ofserver.{50,51,52}.logand was read-only:thr_46gxq5dyzh(one hot thread):Thread timeline build blocked the event loopentries, plus about 1,700 suppressed.eventRowCount1,165 and 572 KB, for alatestpage that returns 3–75 rows.TRANSACTION DEFERRED: 2,907 entries totaling 1,024s. The max of 9,466ms is the same as the worst timeline build./command lookup.The largest stall on this server is a separate cause, filed as #5192.
From Investigate slow command lookup
AnobleSCM commentedon Oct 30, 2026
More production evidence, from a different trigger: a community plugin that reads only
contextWindowUsage.Setup: BB 0.48.0 on macOS, one server, Context Meter 0.1.6 (Hazihell/bb-plugin-context-meter), overnight Oct 29–30, 2026. Read-only, from the server log.
Trigger: on every
thread/contextWindowUsage/updatedorthread/tokenUsage/updatedchange, the plugin callsthreads.timeline({ summaryOnly: "true", segmentLimit: "1" })to readcontextWindowUsage. Those one-segment latest builds still selected the whole open turn.Numbers:
segmentLimit: 1builds took 8.4 to 15.3 s each (median 11.4 s).segmentLimit: 1builds.Ask: a way to read
contextWindowUsagewithout selecting turn events. For example,summaryOnlycould skip event selection when no segments are needed, a small usage endpoint could serve it, orthread:changedmetadata could carry the values. Meter-style plugins would then stay cheap whatever the turn size.AnobleSCM commentedon Oct 30, 2026
Correction to the ask in our earlier comment: BB already has the cheap read we asked for.
GET /threads/:id/context(#3540) returnscontextWindowUsagefrom the usage rows alone, with no timeline build. We've pointed the plugin author to it (Hazihell/bb-plugin-context-meter#1), which removes that plugin's trigger.It doesn't change the main issue here: a latest-page build still selects the whole open turn.
AnobleSCM commentedon Nov 7, 2026
Another trigger for this, still present on 0.49.0: BB's own CLI.
bb thread show <id>readspendingTodoswiththreads.timeline({ summaryOnly: "true" }). On the server,buildThreadTimelineWithProfileruns the fullbuildThreadTimelineInternallatest-page build insiderunEventLoopWorkSync, then returnsrows: []. So every status check pays for a whole latest-page build and throws the rows away.bb thread commandsandbb thread optionsread the same way.Measured on 0.49.0 (self-hosted server on macOS, Nov 7, 2026). One
bb thread show <id> --jsonon an idle thread with a cold cache:pageKind: latest,segmentLimit: 20,selectionStrategy: standard-windoweventRowCount6,390,decodedEventCount6,390,eventDataBytes25,960,077 (about 26 MB)Why it matters: agents that poll their child threads with
bb thread showrepeat that build on every check. On Nov 6, on 0.48.1, latest-page builds on our largest threads took up to 50.3 s (21,397 events decoded, 15 MB). Builds that long dropped the phone and both Macs from the server at the same moment, the symptom in #6499. Our agents now poll withbb thread list --json, and we moved the largest threads to fresh ones. There have been no tunnel drops since.Ask:
summaryOnlyskip row selection and decoding, or givependingTodosits own cheap read, asGET /threads/:id/contextdoes for usage.bb thread waiton an idle thread caused no build.Make windowed timeline reads no slower than main
Read finished collapsed turns from stored per-turn plans
Key persisted timeline projections on a durable rewrite generation
Report the same older-row bound however a page read its turns
Read thread todos, commands, and options without building a timeline …
Read thread head state without building a timeline window (#7238)
Make timeline pushes cost closer to the rows that changed (#7244)
Stop re-projecting whole turns on turn-details pages and whole epochs…
Read only the page's window of turns whose rows render flat
Cut long turns into budget-sized pages
Make windowed timeline reads no slower than main
Read finished collapsed turns from stored per-turn plans
Key persisted timeline projections on a durable rewrite generation
Report the same older-row bound however a page read its turns
Read only the page's window of turns whose rows render flat, and cut …
Read only the page's window of flat-rendered turns, and cut long runn…