Repository navigation
Description
Summary
The server's thread-timeline response cache skips any response with more than 200 top-level rows. Once a requested page of a long thread passes that size, two requests with an identical cache key (same revision and same request parameters — for example a second desktop window, or a plugin calling threads.timeline with the app's parameters) each run their own full projection instead of sharing one. I expected identical requests to share one build regardless of response size.
Versions and environment
- bb 0.43.3 desktop app, macOS 26.5.2, Apple M5. Source read and repro run at c1a64f4.
- Node v22.22.3 for the standalone repro.
- Providers in the affected threads: Claude Code 2.1.278, codex-cli 0.155.1.
- Setup: 2 desktop windows on one server, 561 threads, 2–10 running threads, 17 path-installed plugins.
Steps to reproduce
- Check out get-bb/bb at c1a64f4.
- Save this as
repro-cache.tsin the checkout root:import { createThreadTimelineCache } from "./apps/server/src/services/threads/timeline-cache.ts"; for (const n of [200, 201]) { const cache = createThreadTimelineCache(); let builds = 0; const build = () => { builds += 1; return { rows: Array.from({ length: n }, (_, i) => ({ id: String(i) })) } as never; }; cache.getOrBuild("thr_a", "same-key", build); cache.getOrBuild("thr_a", "same-key", build); // second client, identical key console.log(`rows=${n} builds=${builds} cacheSize=${cache.size}`); }
- Run
node --experimental-strip-types repro-cache.tsfrom the checkout root.
Expected vs actual
Actual: rows=200 builds=1 cacheSize=1
rows=201 builds=2 cacheSize=0
Expected: rows=201 builds=1 cacheSize=1
Evidence
- Admission rule: with the constant at
if (value.rows.length <= maxCacheableRows) { #L6(DEFAULT_MAX_CACHEABLE_ROWS = 200). - The key is
maxSeqplus thread, status, environment, provider display name, page (kind, segment limit, cursor), nested rows, summary-only, diagnostic operations and completed-turn display:bb/apps/server/src/services/threads/timeline-cache.ts
Lines 90 to 110 in c1a64f4
export function buildThreadTimelineParamsKey( args: Omit<ThreadTimelineCacheKeyArgs, "maxSeq">, ): string { return [ args.threadId, args.status, args.environmentId ?? "-", args.providerDisplayName ?? "-", pageKeyPart(args.page), args.includeNestedRows ? "1" : "0", args.summaryOnly ? "1" : "0", args.includeDiagnosticOperations ? "1" : "0", args.completedTurnDisplay, ].join("|"); } export function buildThreadTimelineCacheKey( args: ThreadTimelineCacheKeyArgs, ): string { return `${args.maxSeq}|${buildThreadTimelineParamsKey(args)}`; } - Context, not proof of the hit rate: on the live server, responses above the cutoff do occur for
pageKind: "latest". From~/.bb/logs/server.8.log, trimmed:With 2 running threads the bb server used 24% of a core, with 10 running threads 84% (CPU-time deltas from{"threadId":"thr_5tpdgiiyp4","totalDurationMs":189.2,"thresholdMs":150,"selectionStrategy":"full","pageKind":"latest","eventRowCount":1320,"eventDataBytes":688143,"projectedRowCount":261,"responseRowCount":261,"msg":"Thread timeline build blocked the event loop"} {"threadId":"thr_tddwe6esxx","totalDurationMs":224.4,"thresholdMs":150,"selectionStrategy":"standard-window","pageKind":"latest","eventRowCount":1130,"eventDataBytes":703094,"projectedRowCount":298,"responseRowCount":298,"msg":"Thread timeline build blocked the event loop"}ps -o cputimeover fixed 40 s windows). I did not measure how many of those builds were identical-key misses, so I am not claiming this cutoff explains that load — only that above 200 rows the cache cannot help at all. - Investigation: bb thread
thr_tddwe6esxxon my machine (local, not shareable by link); I can paste the measurement notes and scripts here on request.
What you ruled out
- Not Timeline cache retains obsolete revisions for the same request shape #2066: that is this cache retaining obsolete revisions below the cutoff; this is admission above it.
- Not the only cost: every new
maxSeqis a new key, so one build per revision is inherent. One slow build in the same log hadresponseRowCount137, under the cutoff. - Not Archiving a thread leaves its native browser views alive #2298: both renderer processes here are ordinary app windows ("BB window 1" and "BB window 3" in
bb browser instances), no leaked browser views. - Searched open and closed issues for "timeline cache", "event loop timeline build" and "maxCacheableRows"; found Timeline cache retains obsolete revisions for the same request shape #2066 and timelineWindowEventBudget assumes 0.06ms/event; measured 0.479ms/event on a 4-core host #1749 (event budget), neither covers admission.
Suggested priority and effort
Affects long threads viewed by more than one client with identical request parameters. No workaround, no data loss. Replacing the row cutoff needs a memory-policy decision (rows can carry large nested content), so I am not suggesting an effort level.
AGENT GENERATED
Activity
bb-slop-cop commentedon Sep 21, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotClassification: Bug · Priority: Medium · Effort: Medium. Applied
threads,perf, andconfirmed-repro; no existing classifications were replaced.Reproduction report: REPRODUCED · high confidence. On trusted main, the 200-row admission gate leaves larger responses uncached, so identical keys invoke the projection builder again. In two clean checkouts, three requests built once at 199–200 rows and three times at 201–300 rows. The report includes the test and output; production CPU impact was not measured. The normal build was blocked by a broken local pnpm launcher.
No PR: replacing the explicit admission policy requires a memory-budget decision, so it fails the automatic simple-fix criteria.
bborn commentedon Sep 27, 2026
One data point for the memory-budget question. Measured on
mainat a19b3ed with a 378-row thread on loopback: the build ran on every request (25 ms each on an M-series Mac; 150 to 360 ms per the slow-build log on a 4-core Linux host, blocking the event loop each time). Raising the admission cap alone would let 128 entries of several hundred KB each stay resident, so the prototype at bborn#1 (apps/server/src/services/threads/timeline-cache.ts) keeps the entry limit and adds a total-row budget: responses up to 2,000 rows are admitted, the cache evicts oldest-first once the sum of cached rows passes 12,000, and a single entry larger than the budget is still kept. At roughly 1.6 KB of JSON per row that bounds the cache near 20 MB of response data. After the change the same thread answers from cache in 8 to 10 ms, most of it JSON and brotli. Tests for admission, budget eviction, oversized single entries and invalidation are intimeline-cache.test.tson that branch. Happy to adjust the numbers to whatever policy you prefer before opening a PR.luketraas commentedon Sep 29, 2026
I have a fix on a branch that replaces the 200-row cap with a byte budget: each admitted response is weighed once by its serialized size, the cache keeps its 128-entry cap, adds a 16 MiB budget with least-recently-used eviction, and skips any response above a quarter of the budget. Through the real route, 10 identical requests for a 450-row page went from 10 builds (18.3 ms p50 per repeat) to 1 build (about 1 ms per repeat); under pressure, 40 threads of 515 KiB responses kept 31 in cache at 15.6 MiB accounted and 18.1 MiB measured heap.
Before opening a PR: is a byte budget the policy you want here, and is 16 MiB acceptable, or would you prefer another number or a shared budget with the delta rows cache? @bborn, I compared against your prototype; happy to credit it or defer if you are opening one.
hellno commentedon Nov 5, 2026
Looks like this was fixed by #7063, which replaced the 200-row limit with a byte budget (2 MiB per entry, 64 MiB total). Can this be closed?
ymichael commentedon Nov 17, 2026
Fixed on main: #7063 replaced the 200-row cap with a byte budget, and #7245 set the limits. Large responses are now cached. Closing.