Repository navigation
Timeline perf integration (do not merge: verification branch for #7238 #7239 #7245 #7244 #7246 #7243 #7247 #7254 #7249 #7241 #7108 #7240 #7248 #7242 #6215) - #7250
Closed
ymichael wants to merge 68 commits into
Conversation
On macOS the clutch scheduler gives a busy plain process only its fair share against agent workloads, so under 15+ concurrent agents the server main thread got ~6% of a core while having work ~88% of the time. Spawning the server and daemon through taskpolicy -a gives them the application scheduling policy, which keeps their latency at baseline under heavy CPU contention. The policy is not inherited by their children, so agents and terminals keep their normal priority. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The host daemon now sets nice 10 (below-normal on Windows) on provider processes, terminal shells and environment lifecycle scripts right after spawning them, so the builds and tests agents run inherit it. When many agents saturate the CPU on Linux, the server keeps its share instead of being preempted for most of each event-loop turn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-workloads-thr_vw834vqyax # Conflicts: # packages/process-utils/src/index.ts
…r-many-concurrent-agents-thr_vw834vqyax # Conflicts: # packages/bb-app/src/logged-process.ts
…thr_vw834vqyax' into bb/server-stalls-under-many-concurrent-agents-thr_vw834vqyax
…r-many-concurrent-agents-thr_vw834vqyax
The server sends the experiment to daemons in the session handshake and in provider-session-policy.replace (protocol 257). While it is on, the daemon lowers provider processes and environment lifecycle scripts to nice 10. The server and daemon mirror the value to <data dir>/agent-cpu-priority.json; the launcher reads it at each spawn to decide on taskpolicy -a, and the daemon seeds its own setting from it before the handshake. A missing or unreadable file means off. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…window
`bb thread show`, `bb thread commands`, `bb thread options`, and
`sdk.status` read their fields through `threads.timeline({ summaryOnly })`.
That builds and projects the whole latest page, which on a thread with a
long open turn decodes thousands of events on the event loop, and then
returns no rows. Agents polling child threads with `bb thread show`
repeated that build on every check (Discord report; #4674, #6499).
Add `GET /threads/:id/head-state` (`sdk.threads.experimental_headState`),
which decodes only the latest to-do snapshot and provider state events,
and switch those callers to it. On a production snapshot the summaryOnly
read took 4-174 ms per thread and the head-state read 0.2-0.9 ms, with
identical values on all 16 runs.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The group-context loop called ensureTimelineWindowParentedRows once per iteration, and each call re-queried the children of every delegating item in the window, including children already loaded with their turn. On thr_u738kqjs29 the latest window read 19,463 rows for 7,665 distinct rows. - Keep the set of tool calls whose children (and missing parents) were already fetched across loop iterations. - Exclude turns the turn query already loaded from the child-row query (new excludedTurnIds argument; the trimmed memo source applies the same filter). - Return the turn and child rows straight from the SQLite statement with aliased columns instead of Drizzle's per-row mapping. - Check octet_length before the character-counting length() in the inline-output truncation column, so rows that are small in bytes skip a full UTF-8 scan. Cold latest window, median of 3 alternating A/B harness pairs on the Nov 7 snapshot (load avg 11-40, shared machine): - u738kqjs29: 222.8 -> 149.2 ms, rows read 19,463 -> 7,857 - kdrbtee92b: 36.1 -> 27.7 ms, rows read 2,264 -> 1,332 - avim9t7kpe: 129.2 -> 104.2 ms - wg5iwwrezi: 60.3 -> 53.3 ms, rows read 3,358 -> 2,653 - u738kqjs29 older-page walk: 1,012 -> 678 ms Responses are byte-identical across 1,648 replayed reads on 159 snapshot threads, and memo-path windows after appends match fresh builds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r-many-concurrent-agents-thr_vw834vqyax Bump HOST_DAEMON_PROTOCOL_VERSION to 265, keep the host toolchain's loopback NO_PROXY for the taskpolicy-wrapped server and daemon, and parse daemon messages through the contract schema in the experiment test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
listStoredEventRowsByParentToolCallIds bound every parent tool call id plus the excluded turn ids in one unbatched statement, and listStoredTimelineTurnEventRows assumed 32 fixed variables although the inline-output truncation column binds more than that. Both now split their ids with queryInSqliteVariableBatches, counting the fixed variables from the statement built with an empty batch. Tests cover 40,000 parent ids with 500 excluded turns and 33,002 turn ids (both raised "too many SQL variables" before), and assert that the parented read with excluded turns still searches events_parent_tool_call_thread_parent_sequence_idx without a scan. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y on failure Every daemon terminal.output chunk read its terminal_sessions row before checking whether any browser was attached. Headless terminals, such as the usage plugin's scans, never have one, so each chunk cost a query for nothing. The handler also advanced the forwarded sequence for output nobody received, so a browser reattaching during a daemon disconnect caught up from that sequence and missed the output in between. The handler now returns before the lookup when the terminal has no browser clients. normalizeRpcJsonResult built a path string for every node of an RPC result while copying it. It now keeps a segment stack and renders the path only when it reports a problem. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Stall records named "ws:daemon heartbeat" as the longest synchronous work in most windows because DB transactions, plugin handlers and plugin background work were not measured. Record every bb.db transaction (labelled by its first write), single statements of 1 ms or more, and the synchronous part of each request, plugin invocation, plugin load and plugin service before its first await. Name the dominant child chain and the calling work, and add main-thread CPU and context switches to the longest unit and to the slow timeline build log. Profile stall attribution now totals sampled time per plugin id. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A push for one new event still re-ran several whole-window passes after the selection memo and projection fold hit. This removes the biggest of them without changing any output byte: - Settled delegations: with deferContent the server dropped their child rows after building and mapping them. thread-view now skips building them (omitSettledDelegationChildRows) and only checks whether any child row exists, so the result stays null vs [] exact. - bb thread tell detection: parseThreadTellCommand scanned every command (2 MB on u738kqjs29) several times per build. Results are now cached by command string, bounded like the shell intent cache. - Interrupted turns: once any turn in the window was interrupted, every fold finish structuredClone'd the whole projection state. It now deep-copies only when interrupted-turn finalization would change something (a running call or a pending message in that turn). - Decode: a selection that extends the previous one reuses its decoded prefix and byte count instead of re-decoding every row. - Pagination byte budget: per-leaf and per-page JSON.stringify is replaced by byte counts cached per row object; unchanged latest-window rows and window fields are reused from the previous build when they serialize identically, so the tag, delta and byte counts only touch rows that changed. Warm push after one appended event, in-process harness push scenario, 4 alternating base/fix pairs x 12 appends, load avg 14-19: thread base ms fix ms kdrbtee92b 4.0 2.8 u738kqjs29 (active) 15.4 9.8 8nnix6m53a (active) 5.9 3.0 gyi25h9awq (active) 10.6 4.7 wg5iwwrezi (active) 10.9 4.3 txqr3djnmd (active) 8.0 2.5 mwktgwihcc (active) 8.1 3.2 Parity: latest, phone, CLI, nested, nested+deferred, summaryOnly and three older pages for all 947 snapshot threads with >=1,000 events, plus a 13-step warm-vs-cold replay with deltas on 112 threads, hash identical to main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Phone (segmentLimit 8) and desktop (20) windows, summaryOnly, CLI log and nested reads each paid a full build after the app's window was already built, and with both phone and desktop watching a giant-turn thread the two 13 MB selections evicted each other from the 16M-char memo, so every push rebuilt both from SQL. Older pages were revisioned on the thread head, so every append invalidated them, and no revision carried the rewrite generation, so a gap-filled event below the head was never seen. - Selection memo: a narrower window adopts a wider sibling's selection when both start at the same sequence, or trims it in memory; shared row arrays are counted once against the char budget. - Projection cache keyed by the selected rows array: the event projection is shared across deferContent, summaryOnly and includeNestedRows; rows are materialized per includeNestedRows (thread-view now exposes projectThreadTimelineEvents and buildThreadTimelineFromProjection). - Response cache: revisions include the rewrite generation; older pages are revisioned on generation and surface only (their cursor snapshot is already in the key); thread-deleted drops a thread's windows; the per-entry cap is 8 MB (was 2 MB, total cap unchanged at 64 MB). - Decode cache: one LRU of 16M chars instead of two 4M generations, so a rescan of a 13M-char turn hits. Snapshot A/B (3 alternating pairs, medians, load 17-64): - u738 phone+desktop push after an append: 864 -> 26.5 ms - older page re-read after an append: u738 230 -> 0.1, kdrb 108 -> 0.1 ms - phone8 after app: u738 294 -> 5.3, avim 138 -> 2.2, kdrb 32 -> 1.8 ms - summaryOnly after app: u738 42 -> 4.0, avim 23 -> 2.2 ms - CLI log after app: u738 40 -> 3.9, avim 23 -> 2.0 ms - nested after app: u738 46 -> 11, avim 59 -> 45 ms - wg5 CLI log / nested repeat (over 2 MB): 38 -> 0.3 ms - u738 walk pages 2-4: ~225 -> ~175 ms - cold latest builds: unchanged (15 samples each, within noise) Parity: 72 snapshot threads, 586 response hashes identical to main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every "load earlier" page of turn summary details re-read, decoded and re-projected the whole turn, then paginated it, and re-expanding a turn paid the same again. Cache the scoped projection per thread and request shape, keyed on the cursor snapshot and the thread's rewrite generation, and serve every page and repeat expand by paginating the cached rows with their cached leaf sizes. Entries expire when a retained-output preview they contain would flip to retention-expired. Snapshot A/B (3 alternating pairs, load avg 12-69), whole walk / re-expand: - 6e9knccemi t2 (7.6k events, 13 pages): 1913 -> 155 ms / 1914 -> 4.2 ms - u738kqjs29 t3 (7.4k events, 4 pages): 859 -> 221 ms / 886 -> 0.7 ms - avim9t7kpe t1 (5.9k events, 6 pages): 824 -> 140 ms / 840 -> 1.2 ms First pages and single-page turns cost the same as before. Pages are byte-identical across 23 turns on 12 threads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Any backgroundTask or delegation item in the projected history stopped the outline from ever keeping a checkpoint, so every outline load of a thread that had run one background command reprojected its whole epoch. Treat background items like tool calls instead: their ids join the checkpoint's referenced items, and a later event for one of them rebuilds from scratch. The outline selection already drops a task's normal completion, so the full build never depended on it. Outline replay over 107 snapshot threads (4,573 append steps, incremental vs the full builder at every step): 0 mismatches. Active outline reload, 3 alternating A/B pairs: d5ej4e2gtv 286 -> 116 ms, 6e9knccemi 34 -> 1.4 ms, kdrbtee92b 12.6 -> 2.6 ms, ymhw6pktq4 12.1 -> 1.0 ms; replay median per append: yvsvx8anai 18.4 -> 2.1 ms, dwzy4aij2h 16.5 -> 2.3 ms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…start test condition-based Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A reader that holds an old snapshot (for example a VACUUM INTO copy) stops PASSIVE checkpoints from backfilling while writes keep growing the WAL. The worker treated that as write starvation: it paused, asked the main thread to checkpoint the tail, resumed, and repeated on every write, logging one "Sustained writes" line each time (about 2,000 lines per 15 s pin on a bb.db snapshot). The main-thread checkpoint could not help either, since the same reader blocks it. The worker now only reports starvation, and only re-runs immediately, when the previous pass made checkpoint progress or the WAL restarted. A pinned WAL falls back to the normal interval until the reader finishes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eader test A fixed 1.5 s write window depends on runner speed, and stopping just past the threshold let the unpatched worker pass before its starvation messages landed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Usage and turn-diff snapshot prunes no longer advance the thread's rewrite generation or send history-compacted: timeline, outline and turn-detail reads never load those rows beyond the kept snapshots. The settled sweep now sends one history-compacted per thread pass instead of one per ten-second run, and the timeline response cache keys on the rewrite generation so reads between runs still match a fresh build. A history rewrite on one thread now forgets only that thread's grouping contexts instead of clearing them for every thread. Replay of the production pruning schedule on 5 busy snapshot threads (163 turn ends, deltas and usage rows reconstructed into pruned sequence holes, 3 alternating A/B pairs, medians): - history-compacted notices: 344 -> 121 (2.1 -> 0.74 per turn end) - rewrite-generation bumps: 275 -> 156 - served timeline build time: 133 s -> 63 s; refetch builds 44 s -> 12 s - u738kqjs29: 30 -> 9 notices, build time 78.8 s -> 32.5 s - every post-prune read equalled a fresh build in both variants Co-Authored-By: Claude Opus 5.5 <[email protected]>
A timeline page fetched every turn it touched from the start of history, plus every turn its delegation parents lived in, so a 17-row latest page on thr_u738kqjs29 read a 7,407-event turn (7,663 rows, 13.4 MB) because one background task in the window had a parent in that turn. A turn whose rows render flat (a running turn, or any turn under the flat display) is now read only inside the page window. The selection adds the complete events of items that cross the window edges, delegation parents, children of delegations the page owns, the turn's lifecycle, accepted input, compaction and provider rows, and on older pages the turn's events up to the furthest event those items reach, since the projection fold depends on them. Turns that start inside the window are still read whole with no extra queries. Finished turns under the collapsed display are still read whole. The latest-selection memo appends to windowed turns and checks the store before accepting an event for an item it has not seen. olderRowsSourceSeqEnd is at least a windowed turn's last event before the window, so the client merge never keeps a gap. thr_u738kqjs29 cold latest page (in-process, snapshot): 7,663 -> 779 rows read, ~210 -> ~32 ms. Rendered rows are unchanged: merged walks over 119 snapshot threads x 3 variants and the 12 harness threads x 4 variants are byte-identical to main. Refs #4674 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A window started at a user message, so a turn with no message inside it was one page however long it ran: thr_kdrbtee92b's oldest page owned a 7,335-event turn. When no message start fits the event budget, the window now starts on a grid of half the budget at or below the budget floor, on the first lifecycle event there (pruning never deletes those, so cursors stay valid), moved back to the start of the item it lands in so the latest page is never left holding only a streaming item's tail. The latest start then moves once per half budget of appends, so the selection memo keeps appending. The grid is skipped inside a finished collapsed turn, which is read whole anyway. Cursors stay timeline-v3: their fields keep their meaning, and the projection of a window is unchanged. Harness, snapshot, two alternating A/B pairs, median of 3 per run, load 6-10: - u738kqjs29 latest: 218 -> 24 ms, rows read 7,663 -> 772; push with one new event as active: 12.2 -> 1.6 ms; phone layout 188 -> 14 ms - wg5iwwrezi latest: 53 -> 42 ms - app walk: u738 918 -> 337 ms (34.7k -> 15.4k rows), 6e9knccemi 958 -> 544 ms (56.7k -> 26.6k) - thread log --all: d5ej4e2gtv 3.98 -> 3.04 s (157k -> 115k rows), u738 1.55 -> 0.57 s, kdrbtee92b 764 -> 466 ms, 6e9knccemi 1.07 -> 0.65 s - costs: small-turn cold latest +0.5-1.5 ms (2-9%); app walk kdrbtee92b 226 -> 292 ms and d5ej4e2gtv 2.04 -> 2.24 s, from the extra pages and the tail reads that keep older pages exact Rows are unchanged: merged walks of 119 snapshot threads x 3 variants and 12 harness threads x 4 variants, plus latest-page head fields, are byte-identical to main. Refs #4674 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…timeline-perf-integration
…nd-plugin-main-thre-thr_aemxuhadwf' into ru2/integration-wip
…-code-off-core-s-ev-thr_jbvai7bpud' into ru2/integration-wip # Conflicts: # apps/server/src/services/plugins/plugin-api.ts # apps/server/src/services/plugins/plugin-runtime.ts # apps/server/src/services/system/periodic-sweeps.ts # packages/db/src/data/maintenance.ts
…aves-its-branch-beh-thr_rfnkcrag5v' into ru2/integration-wip
…urrent-agents-thr_vw834vqyax' into ru2/integration-wip
The previous commits made some reads slower than main: - Older pages re-read a turn's later events up to the furthest event their items reached. That guarded against a projection dependency that turned out to be a missing background-task start, already fixed, so the tail read is gone. On kdrbtee92b's app walk the turn rows read fall from 15.4k back to main's 9.4k. - Grid cuts split finished turns into more pages, each paying fixed per-page costs. Grid cuts now apply only inside running turns, and only when the turn has more than one budget of events before the cut. Pages over finished history keep main's boundaries. - A turn that started before the window paid for context, item-closure and count queries. On the latest page each touched turn's first sequence now comes from one index-only query. A turn that starts within 256 sequences of the window is read whole in the same single query as the window, as main does. On older pages a turn with at most 256 events outside the window is read whole. - A child-row exclusion subquery cost about 11 ms on kdrbtee92b's CLI walk and has been removed. ymhw6pktq4 cold latest, the worst small case before this change, went from +0.35 ms to +0.07 ms in turn loading (180 fresh-connection builds per side). Merged walks are still byte-identical to main. Refs #4674 Co-Authored-By: Claude Opus 5.5 <[email protected]>
S4's decoded-selection cache kept up to 4 decoded selections per thread for 64 threads per connection, bounded by count only, and nothing dropped them on thread delete, history rewrite or idle. It retained row data the selection memo and the stored-event decode cache had already let go: reading the 12 harness threads in 4 page shapes kept 261 MB alive in it. The decoded rows now live on the selection memo entry whose rows they decode. A memo hit hands the entry's decoded rows to the build as the prefix to extend, and the build stores the extended result back on the new entry. The decoded cache therefore has exactly the memo's bounds (16 entries, 4 idle, 16M data chars) and is forgotten wherever the memo forgets an entry: thread delete, rewrite generation or data_version change, context-clear epoch change and eviction. The separate per-thread map and its prefix scan are gone. Retained heap after reading app, phone, CLI and nested windows (forced GC): scenario main #7244 c381f52 this 12 harness threads +63 MB +321 MB +67 MB 12 harness + 293 recent +109 MB +295 MB +108 MB Warm push after one appended event (harness push scenario, 9 alternating pairs x 12 appends, median of per-run medians): kdrbtee92b 2.5 -> 2.4 ms, u738kqjs29 (active) 8.8 -> 9.1 ms; the last 3 interleaved pairs were 8.8 vs 8.8 ms. Rows read, decoded and folded per push are identical. Warm cache-hit reads stay at 0.0-0.1 ms on all 12 threads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A page that touched a finished turn under the collapsed display (Codex's default) read the whole turn, because its summary rows depend on every message in it: thr_avim9t7kpe's latest page read 5,888 rows to render 6. The first time a page reads such a turn of at least 1,000 events whole, it stores the turn's row plan in thread_turn_timeline_plans: the summary rows, and the id and source range of each message the turn shows ungrouped. Later pages take the summary rows from the plan and read only the events of the ungrouped messages they show, plus the turn's context events. A plan is keyed by a projection version, the in-process rewrite generation, the thread status and the display settings that change the output, following the thread_conversation_outlines precedent. It is used only while the greatest sequence of the turn's events, its delegations' children and its open items is unchanged. Rewriting the history suffix deletes a thread's plans. The latest-selection memo rebuilds on any append that touches a planned turn. Nested-row reads (bb thread log --format verbose) still read the turn whole. Harness, snapshot, three alternating A/B pairs, fresh DB clone per run, median of 3 per run, load 6-10: - avim9t7kpe latest page 105 -> 14 ms (5,888 -> 40 rows), app walk 227 -> 15 ms, thread log --all 211 -> 15 ms - 9h3n4aiax8 app walk 146 -> 52 ms (13.9k -> 1.5k rows) - the first read of a turn materializes its plan at main's cost - nested-row reads right after an app read of the same thread no longer share the app's whole-turn selection: avim 45 -> 144 ms, which is main's own cold nested read (143-150 ms; branch 137-140 ms) Merged walks are byte-identical to main across 357 broad-sample walks, 208 walks of 104 Codex threads whose finished turns span pages, and 48 harness walks, each with plans being created and with all plans stored. Refs #4674 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ized-costs-thr_jn4p352bnn' into bb/timeline-perf-integration
Stored per-turn plans and conversation outlines were keyed on the in-process rewrite generation, which restarts at zero. A rewrite before a restart could leave a stored plan or outline that still looked valid. A gap-fill insert into a finished turn does not move the plan's watermark (the turn's greatest sequence), so after a restart the stale plan was used and the walk rendered the turn without the inserted message. thread_event_rewrite_generations (migration 0156) holds a per-thread generation. bumpThreadEventRewriteGeneration increments it in the same transaction at every rewrite: suffix deletes, inserts at or below the high-water mark, completed-output migrations, and pruning that removes rows (moved inside the pruning transaction). The in-memory generation stays the fast key for process-local caches. Turn plans and persisted outlines key on the stored value, one primary-key read per build. The new restart test seeds a plan and an outline, gap-fills an agent message into the turn, reloads the server modules, and checks that the walk and outline equal a rebuild with no stored artifacts. It fails when the keys use the in-memory generation. The rewrite-generation DB tests now also assert the stored value on every bump path. Refs #4674 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-turn-pagination-46-thr_pgx4x6ezq6' into bb/timeline-perf-integration # Conflicts: # apps/server/src/services/threads/timeline-pagination.ts # apps/server/src/services/threads/timeline-selection-memo.ts # apps/server/src/services/threads/timeline.ts # packages/db/src/data/events.ts # packages/db/src/data/thread-pruning.ts # packages/thread-view/src/build-thread-timeline.ts
…n one pass Evicting one entry per insert from the front of the Map walked every tombstone left by earlier deletes, so each insert over budget cost O(evicted entries) and 600k inserts took 16 s instead of 85 ms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…visit after it The turn-end live prune now removes rows, and each removal sent its own history-compacted notice before the sweep's pass over the same thread sent another. A live step on a settled thread now leaves its notice to the sweep's next visit to that thread, with a one-minute fallback, and the timeline response cache revision includes the rewrite generation so server reads never depend on the notice. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aring-thr_curdrpgt2c' into bb/timeline-perf-integration
…29ek' into bb/timeline-perf-integration # Conflicts: # apps/server/src/services/system/thread-pruning-sweep.ts # apps/server/src/services/threads/timeline-cache.ts # apps/server/test/services/threads/timeline-cache.test.ts # docs/events-table-pruning.md
timelinePage.olderRowsSourceSeqEnd depended on whether a turn's plan was stored and on read order. The page folded in the latest event of every windowed or planned turn before the window. A whole read of the same turn instead reports the greatest sourceSeqEnd of the rows it projected and did not return, leaving out rows sent as olderRowUpdates. thr_avim9t7kpe's latest page reported 1 on a fresh database and 1925 once its plan was stored. A nested read first left a plan-less memo entry that later app reads reused, so those reported 1 again. The page now adds only what a whole read would have projected: - a planned turn: the end of each stored ungrouped message that ends before the window. Plans keep only messages that render a row, and a stored message matches its projected message by id and source range. - a turn read only inside the window: its latest event before the window, skipping context events (already read) and events whose top-level row reaches the window. A metadata-only backward scan finds it and usually stops after one page. A windowed read also reads the turn-scoped start of an item whose thread-scoped completion is in the window. Without it, thr_u738kqjs29's older pages gave a delegation row a later sourceSeqEnd than main. #7247's new queries hardcoded SQL-variable counts and used Drizzle row mapping. They now batch with queryInSqliteVariableBatches on the query's exact fixed-variable count, and turn and item rows read raw rows through the same helpers #7239 adds. Snapshot parity against main 55135d1, 162 threads, every response including olderRowsSourceSeqEnd and tag: 4,652 hashes, 0 differences. Reverse read order: 2,462 hashes, 0 differences. Append replay: 1,024 steps, 5,120 deltas, 0 warm-vs-cold mismatches. Refs #4674 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-turn-pagination-46-thr_pgx4x6ezq6' into bb/timeline-perf-integration # Conflicts: # packages/thread-view/src/build-thread-timeline.ts
…dget The latest-window row reuse kept the pageable rows of the last 32 windows per connection in a separate map. The bound was a count, not a size, and the map never dropped a thread's windows on history rewrite, compaction or memo eviction. The kept rows now live on the selection memo entry for their selection, one set per (deferContent, includeNestedRows) variant. Their JSON bytes count toward the memo's 16M budget along with the selection's data chars. They go away wherever the memo drops an entry: forget on rewrite or compaction, context-clear epoch change and eviction. A rewritten generation doesn't carry them over. After pagination, only rows whose JSON size pagination already measured are kept. Those are the only rows reuse helps, and their size costs nothing extra. Charging every pageable row instead stringified the older context rows pagination never touches, which doubled u738kqjs29's first CLI read after an app read (27 -> 57 ms). Retained heapUsed after reading app, phone, CLI and nested windows of each thread (forced GC; kept rows = heap freed by dropping them once the windows instance is gone): read set 49f4151 this 12 harness threads +66.5 MB (5.9) +66.5 MB (1.0) 305 threads +108.3 MB (3.2) +108.4 MB (1.2) 305, harness threads read last +128.6 MB (5.9) +112.4 MB (1.0) 318, 17 largest threads last +149.1 MB (14.4) +140.3 MB (0.0) Responses are identical to 49f4151: 4,652 forward and 2,462 reverse-order hashes over 162 threads, and 0 warm-vs-cold mismatches over 1,024 append-replay steps. Harness timings, 4 alternating pairs, are within 1% in total, and every rows-read and bytes metric is identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A deferred notice was sent by whichever sweep visit came next, usually a pass that removed nothing, so the rewriting pass after it still sent its own and the count didn't drop. A live step's notice now rides on the sweep's next real notice for the thread, with the one-minute fallback, and active-turn live steps defer the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ized-costs-thr_jn4p352bnn' into bb/timeline-perf-integration # Conflicts: # apps/server/src/services/threads/timeline-selection-memo.ts
The batched queries rendered every query twice: once with an empty batch to count its fixed variables, then again for the batch. The inline-output truncation column makes that render expensive, so listStoredTimelineTurnContextRows cost 650 us against 410 us before batching. queryRawRowsInSqliteVariableBatches now renders the query once with the whole list, takes the exact fixed-variable count from that render, and runs it directly when it fits. Only lists above the SQLite limit pay for per-batch renders. The aggregate and start-lookup queries keep their raw SQL text, rendered through SQLiteSyncDialect. The older-row scan starts with 16 events and grows, and the thread-scope start lookup is skipped when the page reads no turn in part. Micro-benchmark on thr_u738kqjs29, per call against the PR head: turn context rows 409 vs 408 us, first sequences 28.6 vs 28.3 us, outside counts 26.7 vs 26.4 us. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…29ek' into bb/timeline-perf-integration # Conflicts: # apps/server/src/services/system/thread-pruning-sweep.ts # docs/events-table-pruning.md
…-turn-pagination-46-thr_pgx4x6ezq6' into bb/timeline-perf-integration
ymichael
added a commit
that referenced
this pull request
Nov 9, 2026
…tly (#7245) ## Human comments ## What was wrong Timeline window caches were keyed on the request's page shape and on the thread head, not on what actually determines the output. The selection memo was keyed by `segmentLimit`. So the phone (8) and desktop (20) windows each ran their own SQL selection, decode and projection, even when both started at the same sequence. On a giant-turn thread the two ~13M-char selections could not both fit the memo's 16M-char budget: with phone and desktop both watching, every push evicted the other entry and rebuilt both windows from SQL. summaryOnly, CLI log and nested reads shared the selection but re-ran the whole projection. In the response cache, older pages used the current `maxSeq`/status as their revision, even though their content is fixed by the cursor's snapshot, so every append on an active thread invalidated them. No revision carried the rewrite generation, so an event gap-filled below the head (same `maxSeq`) was served stale. `thread-deleted` never dropped cached windows. Windows over 2 MB were never cached. The decode cache's two 4M-char generations thrash on a rescan of any turn larger than one generation (the largest recent turns are 11–13M chars). ## What changed - `timeline-selection-memo.ts`: a narrower window adopts a wider sibling's selection (same thread, budget, epoch, head and generation) when its computed start equals the sibling's. If the start is later, it trims the sibling's rows in memory instead of running SQL. A wider window whose start equals a narrower sibling's adopts that selection too. Row arrays shared between entries count once against the char budget. A memo hit with no appended rows keeps the same row array. - `timeline-projection-cache.ts` (new), `timeline.ts`: the projection is cached per selected row array (a `WeakMap`, so it lives exactly as long as the memo's rows). The event projection is shared across `deferContent`, `summaryOnly` and `includeNestedRows`, and rows are materialized per `includeNestedRows`. Output after projection (previews, deferral, pagination, shortening, tag) is still computed per request. `@bb/thread-view` now exports `projectThreadTimelineEvents` and `buildThreadTimelineFromProjection`; `buildThreadTimelineFromEvents` composes them. Profiles have a new `thread-view-rows` stage for materialization. - `timeline-cache.ts`, `thread-timeline-windows.ts`: revisions include the rewrite generation. Older pages are revisioned on generation and surface only, because the anchor id in the key already encodes the cursor snapshot. `thread-deleted` invalidates the thread's windows. The per-entry cap is now 8 MB (was 2 MB). The 64 MB total is unchanged, and cached responses measured 1.3–1.6× their JSON size in heap. - `stored-event-decode-cache.ts`: one LRU of 16M chars replaces two 4M-char generations, so a rescan of a turn up to 16M chars hits. Once the cache goes over either cap, it evicts the oldest entries down to 90% of both caps in one pass. Evicting one entry per insert from the front of the `Map` would walk every slot deleted before it (V8 keeps deleted slots until the next rehash): 600k inserts take 14.6 s that way and 82 ms with batch eviction. No wire, CLI or SDK changes. Every response is byte-identical to main (parity below). ## How you verified Benchmarked on a prod snapshot clone with the shared in-process harness (cold/variants/walk/push) plus S2 scenarios (older pages after an append, phone+desktop push, parity, memory). Three alternating base/new pairs, medians of medians. Load average was 17–64 because other benchmarks shared the host; row and parity metrics are deterministic. | case | main | this PR | |---|---|---| | u738 phone+desktop latest after one append | 864 ms | 26.5 ms | | older page re-read after an append (u738 / kdrb) | 230 / 108 ms, rebuilt | 0.1 / 0.1 ms, hit | | phone8 after app (u738 / avim / kdrb / wg5) | 294 / 138 / 32 / 52 ms | 5.3 / 2.2 / 1.8 / 7.7 ms | | summaryOnly after app (u738 / avim / wg5) | 42 / 23 / 29 ms | 4.0 / 2.2 / 15 ms | | CLI log after app (u738 / avim / kdrb) | 40 / 23 / 22 ms | 3.9 / 2.0 / 13.5 ms | | nested after app (u738 / avim) | 46 / 59 ms | 11 / 45 ms | | repeat of a window over 2 MB (wg5 CLI log, avim nested) | 38 / 55 ms | 0.3 / 0.2 ms | | u738 older-page walk, pages 2–4 (decode cache) | ~225 ms each | ~175 ms each | | cold latest, 12 threads (5 repeats × 3 pairs, load ~17) | — | within −10%/+7%, minima overlap | | module-cache heap after app+summary+CLI+nested+phone on 12 threads | 29.7 MB | 42.2 MB | The extra heap is mostly the decode cache (16M vs 8M chars, about 3.1 heap bytes per cached char when it holds the only copy of the row data). **Parity.** On 72 snapshot threads (the 12 harness threads plus 60 threads with ≥1,000 events), each of 6 variants (app, summaryOnly, CLI log, nested, phone8, CLI log at segment limit 100) was built cold, plus the latest and up to three older pages. All 586 response hashes, including rows, tags and cursors, are identical to main. On this branch, 1,008 reads in two warm sharing orders (wide first and narrow first) each equal the cold build. After appends, the older-page and phone/desktop scenarios showed zero mismatches against fresh builds. **Decode-cache eviction** (23d0283, found by the integration branch #7250). Per-insert front eviction made the `capacity` scenario (one instance opens 712 threads, then re-reads them) 14–17% slower than main. Harness `capacity,cold`, 9 repeats, three alternating pairs on fresh snapshot clones, load 4–8: | case | dc75c40 (per-insert eviction) | 23d0283 (batch eviction) | |---|---|---| | capacity reopen, median cold open | 23.8 ms (23.8 / 24.3 / 22.9) | 19.8 ms (19.8 / 19.9 / 19.1), −17% | | capacity first miss from newest / retained windows | 403 / 402 | 403 / 402 | | cold latest, 12 threads (medians of medians) | — | −2% to +8% per thread, ranges overlap. A cold read uses a fresh connection, and no thread exceeds the cap, so it never evicts. | The PR's other bounded `Map`s are fine. The response cache (512 entries) and the selection memo (16 entries) also evict from the front, but at those sizes 600k inserts take 108 ms and 49 ms (vs 45 / 44 ms with batch eviction). Both predate this PR. The projection cache is a `WeakMap` with at most 4 entries per selection. Parity of the fix: the 162-thread parity replay (12 harness threads plus 150 sampled threads with ≥1,000 events, 8 latest variants, older pages, repeats, turn details, outline), with one connection per arm so the decode cache evicts. All 4,652 response hashes are identical between dc75c40 and 23d0283 (and against a second dc75c40 run). The 8 errors are the same on both arms: details requests for 2 turns that the route rejects on main too. **Tests** (they fail on main, pass here): - `test/services/threads/timeline-window-sharing.test.ts`: a gap-filled event below the head is served. Older pages stay cached while the thread grows and are rebuilt after a rewrite. Phone reuses desktop's selection and projection. summaryOnly, CLI and nested reuse the app's projection. `thread-deleted` drops cached windows. All 5 fail on main. - `stored-event-decode-cache.test.ts`: a rescan of a turn at 75% of the cap hits on every row. Going over the cap evicts down to 90% at once, so the next inserts evict nothing; this one fails on dc75c40 (`expected 15987023 to be less than or equal to 14400000`). - `timeline-cache.test.ts`: older-page revision ignores the head and includes the generation; a 3 MB window is cached by default. - `timeline-selection-memo.test.ts`: the randomized warm-equals-cold replay also builds a narrower window before and after the wider one. Commands: `pnpm exec turbo run typecheck lint --filter=@bb/server --filter=@bb/thread-view` passes. `pnpm exec turbo run test --filter=@bb/server --filter=@bb/thread-view`: thread-view 510/510; server 3,947 passed and 1 failed, in `test/app/install-machine-script.test.ts`. That file also fails on main on this host (a different test each run, timing under load) and is unrelated. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 9, 2026
## Human comments ## What was wrong With the selection memo and projection fold both hitting, a push for one new event still ran several passes over the whole latest window (timeline perf audit, REPORT #5). On the snapshot threads the biggest were: - **Settled delegations.** Their child rows were built and mapped bottom-up, then thrown away by `deferSettledTimelineRow` (572 of 634 rows on kdrbtee92b). - **Sent-message detection.** `parseThreadTellCommand` scanned every command's text several times per build (2 MB per pass on u738kqjs29, about 14% of a push). - **Interrupted turns.** Once any turn in the window had been interrupted, every fold finish ran `structuredClone` on the whole projection state, because `pendingFinalizationByTurnId` is never cleared (6 of 150 sampled active threads, 1–1.8 ms per push). - **Decoding and byte counts.** Every row was decoded and its bytes counted again. - **Byte-budget pagination.** It ran `JSON.stringify` on every leaf, then on every returned segment. - **Tag and delta.** Every row object was fresh each build, so the tag and delta hashed and stringified all of them again. ## What changed - **thread-view.** `buildThreadTimelineFromEvents` takes a new `omitSettledDelegationChildRows` option. The server sets it when `deferContent` is on, and settled delegations then skip building their child rows. Emptiness is still checked lazily, so the output keeps the exact `null` vs `[]` that deferral produced. - **thread-view.** `parseThreadTellCommand` results are cached by command string, bounded the same way as `shellIntentCache` (16k entries, 8M chars), and every call returns a fresh object. - **thread-view.** `copyProjectionStateForFinish` deep-copies only when interrupted-turn finalization would actually change something: a running call, or a pending message or cell scoped to that turn. `interruptedTurnFinalizationChangesState` implements the check. - **server.** - `timeline-selection-decode.ts` / `timeline-selection-memo.ts`: when a selection extends the previous one, it reuses the decoded prefix and its byte count. The decoded rows live on the selection memo entry whose rows they decode, so they have exactly the memo's bounds (16 entries, 4 idle, 16M data chars) and go away wherever the memo drops an entry: thread delete, rewrite generation or `data_version` change, context-clear epoch change, and eviction. - `timeline-content-pagination.ts` / `timeline-pagination.ts`: JSON byte counts are cached per row object, and array and parent sizes are derived from their parts (exact for any UTF-8). - `timeline-window-reuse.ts`: unchanged latest-window rows, and window fields like todos and provider commands, are reused from the previous build when they serialize identically, key order included. The tag, delta and cache accounting then only touch rows that changed. `getOrBuild` now passes the stale response to the builder for this. - `timeline-selection-memo.ts`: the previous build's pageable rows, which the next build reuses rows from, live on the selection memo entry, one set per `deferContent`/`includeNestedRows` variant. Their JSON bytes count toward the memo's 16M budget along with the selection's data chars, and they go away wherever the memo drops an entry. Only rows whose JSON size pagination already measured are kept, so the size costs nothing extra (e515883). - **server, after rebasing onto #7245.** #7245's projection cache shares built rows between windows and keyed them only by `includeNestedRows`. Deferred reads now leave out settled delegations' child rows, so a CLI read after an app read could reuse the app's rows and lose a subagent's children. `timeline-projection-cache.ts` now keys rows by `includeNestedRows` and `omitSettledDelegationChildRows`. The first non-deferred read after an app read builds its own rows; the projection is still shared. In the selection memo, a selection shared by several entries counts its data once, and kept pageable rows count per entry. An entry that adopts a sibling's selection starts with no kept rows instead of sharing the sibling's map. - **No contract change.** No wire, CLI, SDK or plugin surface changes. Output is byte-identical to main. Not changed: - **Push pacing** still waits the last build's duration (capped at 1 s). Cheaper builds shorten it directly. - **Remaining u738kqjs29 cost.** Most of its remaining push cost is the fold finish over completed turn t3 (7.4k events). The window loads t3 only as context and the page doesn't return it. Removing that needs page-bounded reads (#4674 / S6), not hit-path work. - **kdrbtee92b grouping-context SQL.** About 10% of its push is still `getTimelineGroupingContext` running again whenever child (parented) events are appended. ## How you verified **Before/after.** Harness push scenario: warm latest read with `afterTag` after appending one `item/started`. In-process on a clone of the Nov 7 snapshot. 4 alternating main/branch pairs × 12 appends, load average 14–19 (other slices were benchmarking at the same time). Median of per-run medians: | thread | main ms | branch ms | Δ | |---|---|---|---| | kdrbtee92b (active) | 4.0 (3.5–4.4) | 2.8 (2.8–3.0) | −30% | | u738kqjs29 (forced active) | 15.4 (14.3–16.2) | 9.8 (9.4–10.6) | −36% | | 8nnix6m53a (forced active) | 5.9 | 3.0 | −48% | | gyi25h9awq (forced active) | 10.6 | 4.7 | −56% | | wg5iwwrezi (forced active) | 10.9 | 4.3 | −61% | | txqr3djnmd (forced active, interrupted turn) | 8.0 | 2.5 | −69% | | mwktgwihcc (forced active, interrupted turn) | 8.1 | 3.2 | −60% | An earlier round of 3 pairs at load average 37–58 showed the same direction, with −16% to −61% and much wider spread. **Memory.** The first version of this PR kept decoded selections in a separate per-connection cache: 4 per thread for 64 threads, bounded by count only, never dropped on thread delete, rewrite or idle. It retained rows the memo and the stored-event decode cache had already released. They now live on the memo entries (49f4151). Retained `heapUsed` after one instance reads the app, phone, CLI and nested windows of each thread, after a forced GC, on a clone of the snapshot: | scenario | main | c381f52 | 49f4151 | |---|---|---|---| | 12 harness threads | +63 MB | +321 MB (261 MB in the decoded-selection cache) | +67 MB | | 12 harness + 293 most recent threads | +109 MB | +295 MB | +108 MB | | 12 harness threads, forced active | – | – | +74 MB | Push and warm timings for 49f4151 vs c381f52: harness `push` + `warm`, 9 alternating pairs × 12 appends (3 of them reversed-order, 3 interleaved), load average 7–9. Median of per-run medians: | case | c381f52 | 49f4151 | |---|---|---| | warm push, kdrbtee92b | 2.5 ms | 2.4 ms | | warm push, u738kqjs29 (forced active) | 8.8 ms | 9.1 ms (last 3 interleaved pairs: 8.8 vs 8.8) | | cold after append, kdrbtee92b / u738kqjs29 | 33.4 / 207.8 ms | 34.0 / 207.4 ms | | warm cache hit, all 12 threads | 0.0–0.1 ms | 0.0–0.1 ms | Rows read, decoded and folded per push are identical, and `event-json-decode` stays under 0.1 ms on both, so the prefix is still reused. **Memory, kept pageable rows (e515883).** Before this commit the reused rows sat in a separate per-connection map of the last 32 windows. The bound was a count, and nothing dropped a thread's windows on rewrite, compaction or memo eviction. Same measurement as above. In brackets: heap freed by dropping the kept rows once the windows instance is gone. | read set | 49f4151 | e515883 | |---|---|---| | 12 harness threads | +66.5 MB (5.9) | +66.5 MB (1.0) | | 305 threads (12 harness + 300 most recent) | +108.3 MB (3.2) | +108.4 MB (1.2) | | the same 305, harness threads read last | +128.6 MB (5.9) | +112.4 MB (1.0) | | 318 threads, the 17 largest read last | +149.1 MB (14.4) | +140.3 MB (0.0) | On this branch alone the old map stayed small in the default read order, because the last 32 windows read were small threads. With the larger merged integration branch (#7250) it measured 33 MB at 305 threads. The first version of this commit charged every pageable row. That stringified the older context rows pagination never measures, and it doubled u738kqjs29's first CLI, nested and summary reads after an app read (27 → 57 ms). Keeping only measured rows removed that cost. Timings for e515883 vs 49f4151: harness `cold`, `warm`, `variants`, `capacity` and `push`. Push threads were kdrbtee92b plus u738kqjs29, wg5iwwrezi and txqr3djnmd forced active, 12 appends, 5 repeats. 4 alternating pairs, each started at load below 8 (4.3–6.3). Median of per-run medians: | case | 49f4151 | e515883 | |---|---|---| | warm push, kdrbtee92b / txqr3djnmd / wg5iwwrezi / u738kqjs29 | 1.9 / 2.05 / 3.55 / 8.6 ms | 1.9 / 2.1 / 3.6 / 8.15 ms | | cold after append, u738kqjs29 | 205.8 ms (202.5–212.5) | 210.8 ms (206.6–220.3) | | cold app latest, sum of 12 threads | 567.7 ms | 570.7 ms | | first variant read after app, sum of 48 | 782.8 ms | 788.5 ms | | u738kqjs29 CLI log after app | 26.85 ms | 27.15 ms | | capacity reopen | 19.3 ms | 19.35 ms | | warm cache hit, all 12 threads | 0.0–0.1 ms | 0.0–0.1 ms | Every rows-read, decoded, bytes and response-bytes metric is identical between the two. **Parity.** Responses were hashed on main and on the branch over a read-only clone of the snapshot: - All 947 threads with ≥1,000 events, six window variants each: app latest, phone (segmentLimit 8), CLI, nested, nested+deferred, summaryOnly. - Up to three older pages per thread. - A 13-step incremental replay on 112 threads (the 12 harness threads plus 100 sampled), app and CLI params. Each step compares warm memo, fold and row-reuse builds against a cold build at the same maxSeq, and also hashes the delta from the previous step. Result: 9,723 / 9,723 hashes identical to main, and warm equals cold at every replay step. Retained-output availability, which depends on `Date.now()`, was normalized before hashing. Re-run on 49f4151 with the same script on a fresh clone: 9,723 / 9,723 identical to main and to c381f52, warm equals cold at every replay step. e515883 vs 49f4151, using the integration's parity and append-replay scripts on fresh clones: - 162 threads × 8 variants, older pages, turn details and outlines: 4,652 forward-order and 2,462 reverse-order hashes, all identical. - Append replay over 64 thread-runs: 1,024 steps and 5,120 deltas, 0 warm-vs-cold mismatches on both. **Tests added.** I ran the `structuredClone` test against the old condition, where it fails. The others test code paths that don't exist on main, so they weren't run there. - `thread-view/test/settled-delegation-child-rows.test.ts`: omitted child rows equal deferring the full rows, including nested, childless and pending delegations. - `thread-view/test/event-projection-fold.test.ts`: fold matches cold after every event for an interrupted turn with nothing pending, and finishing does not call `structuredClone`. - `thread-view/test/tool-call-parsing*.test.ts`: cached results are independent objects, repeated parses are reused, and the existing linearity benchmarks now use unique commands so the cache can't mask them. - `server/test/services/threads/timeline-selection-decode.test.ts`: prefix reuse and byte count. The memo entry carries the decoded rows and a reused selection extends them. Decoded rows are dropped on history rewrite and thread forget, and when the memo evicts the entry for its data-char budget or its entry cap. - `server/test/services/threads/timeline-selection-decode.test.ts`, kept pageable rows (e515883). A build reuses no row objects after the memo forgets the thread. Kept rows count toward the memo budget, so a second thread of the same size evicts the first. Both tests fail on 49f4151, where the rebuilt rows are still the old objects. - `server/test/services/threads/timeline-window-reuse.test.ts`: unchanged rows keep identity across an append and serialize like a fresh build; reuse only happens on exact JSON equality, including key order. - `server/test/services/threads/timeline-content-pagination.test.ts`: derived byte counts equal `Buffer.byteLength(JSON.stringify(rows))` for nested multibyte rows. - `server/test/services/threads/timeline-window-sharing.test.ts`: the CLI window built after the app window keeps a settled subagent's child rows. It fails without the cache-key change (`[null]` instead of `[1]`). The existing sharing test now expects a row rebuild for each new row shape (`includeNestedRows` × `deferContent`). **Commands run.** - e515883: `turbo run typecheck lint --filter=@bb/server`, plus vitest on `test/services/threads` and `test/provider-corpus` (34 files, 293 tests pass, 1 skipped). All with `env -u BB_ACCOUNT_POOL_PARENT_URL -u BB_SERVER_URL -u BB_CLI`. - `pnpm exec turbo run typecheck test --filter=@bb/server --filter=@bb/thread-view --filter=@bb/provider-parity` - 49f4151: `turbo run typecheck lint --filter=@bb/server`, plus vitest on `test/services/threads/timeline*`, `thread-events`, `conversation-outline*`, `test/provider-corpus`, `event-pruning` and `internal-event-append-ownership` (25 files, 241 tests pass, 1 skipped) **After rebasing onto main at 226d128** (#7245, #7238, #7254, #7284): `turbo run typecheck lint --filter=@bb/server`, `turbo run typecheck test --filter=@bb/thread-view --filter=@bb/provider-parity`, and vitest on `test/services/threads` and `test/provider-corpus` (38 files, 312 tests pass, 1 skipped). Push harness, 4 threads × 12 appends, rebased branch vs main at be3ca2c: warm push −37% to −64%, identical response bytes (load average 12–38, so the exact numbers are noisy). Refs #4674 (does not fix it) > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Do not merge. This branch only checks that these PRs work together. Each PR lands on its own.
Root cause
The Nov 7 timeline and server performance audit split its fixes into separate PRs. They overlap in:
Each PR was verified only against
origin/main.Change
Merged onto
origin/main55135d1, at the PR heads below:The parity, replay, memory and timing evidence covers the timeline set and #7254. The other PRs have typecheck, targeted tests and CI. Every conflict and its resolution is in
audit/INTEGRATION.md; the resolved hunks are in this branch's merge commits.Resolutions each PR's rebase must carry
rowsKey. The cached row materializations are keyed by every option that changes rows: nesting, settled-delegation omission, plan capture and planned turns. The event projection stays shared across every page shape.rewriteGenerationrevision. Thegenerationfield that Stop pruning from invalidating timelines it cannot change #7246 and Resume resolved-item pruning passes and bound each advance to its budget #7254 each added is dropped.ensureTimelineWindowParentedRows: Stop re-reading delegated children in timeline window selection #7239's lookups plus Read timeline pages without whole turns, and page long turns by sequence #7247's child-ownership filter.queryRawRowsInSqliteVariableBatches; Stop re-reading delegated children in timeline window selection #7239's helper delegates to it. Whichever of Stop re-reading delegated children in timeline window selection #7239 and Read timeline pages without whole turns, and page long turns by sequence #7247 lands second must keep the single-render version.turnPlanKeyvalidity in the own-entry and sibling checks. Read timeline pages without whole turns, and page long turns by sequence #7247's object-formselectTimelineWindowStartwithtimelineTurnSplitter.windowStartandwindowedTurnIdspassed to the trimmed sibling source.omitSettledDelegationChildRows: deferContent && !captureTurnPlans).previousand logscost.discardCandidateis awaited everywhere.Verification
All runs are in-process on APFS clones of the Nov 7 snapshot. #7247's migrations were applied once to a base clone used by every arm.
Parity coverage: 162 threads (the 12 harness threads plus 150 with ≥1,000 events). Latest app, phone, CLI, CLI at 100, nested, nested+deferred and summaryOnly ×2; older pages; repeats; turn details; outline load, stored and full.
History-compacted notices (prune replay, 8 threads, including deferred notices flushed after the overdue window):
Memory (retained heap after app, phone, CLI and nested reads, forced GC):
The rest of the excess is mainly Share timeline window builds across page shapes and key caches correctly #7245's deliberately larger 16M-char decode cache.
Before/after (harness, all 10 scenarios on the 12 threads, plus push on 4):
thread log --all(u738kqjs29)thread log --all(avim9t7kpe)thread log --all(kdrbtee92b)thread log --all(6e9knccemi)thread log --all(d5ej4e2gtv)thread log --all(ymhw6pktq4)Accepted trade-offs (coordinator):
The capacity regression from #7245's decode-cache eviction is fixed (−4%).
Full table, every scenario × thread (per-run medians in parentheses)
cold
variants
walk
walk-cli
details
outline
sqlcount
capacity
push
Typecheck and tests on 1f65878 (
env -u BB_ACCOUNT_POOL_PARENT_URL -u BB_SERVER_URL -u BB_CLI, turbo):--filter='...[origin/main]', 104 of 104 packages.@bb/db690;@bb/thread-view515.@bb/servertest/services/threads,test/system,test/provider-corpusandtest/public: 1,270 passed.Recommended landing order
Checked with
git merge-tree.generationrevision field)cost)rowsKey, the plan-capture guard and the single-render helper. Migrations 0155 and 0156 still follow 0154 unless main adds one first; in that case, regenerate with drizzle-kit and never hand-edit snapshots.🤖 Generated with Claude Code