Repository navigation
Guard timeline builds against superlinear growth - #7861
Merged
Merged
Conversation
Add a deterministic growth check for buildThreadTimelineFromEvents. It counts array, Map, Set and Object.keys/values/entries work during one build and requires 4x the events to cost under 6x the work, across 16 thread shapes (large file changes, many commands, deltas, turns, steered messages, thread-scoped prompts). It counts work instead of timing it, so it cannot flake. It fails on the matchFileRows regression fixed in #7835 (ratios 11.4 and 13.7). It found two more quadratic paths in group-event-projection-turns: - applyExternalUserBoundaries filtered every root user message for each turn. It now sorts the boundaries once and binary-searches each turn's window. - Each thread-scoped warning or prompt scanned every turn to find the running one. One sweep over turns sorted by start now resolves all of them. Real threads produce byte-identical timelines (7 threads, four option combinations). Full builds of the 1,370-turn and 798-turn threads drop from ~395 ms to ~350 ms and from ~357 ms to ~315 ms. 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.
Human comments
What was wrong
The timeline build in
@bb/thread-viewhad no check against cost growing faster than the data. #7754 replaced an indexed lookup with a per-file scan of every row. Behavior tests passed, and the regression stayed in until #7835. Adding a growth check found two more quadratic paths ingroup-event-projection-turns.ts:applyExternalUserBoundariesfiltered every root user message in the thread once per turn (turns × messages).findRootTurnRunningAtSequencescanned every turn once per thread-scoped warning or interaction prompt (turns × prompts).What changed
packages/thread-view/test/timeline-build-growth.test.ts. It builds timelines for 16 thread shapes at 100 and at 400 units: files in one edit (same and reversed completion order), file changes, commands, command output deltas, assistant messages and deltas, reasoning deltas, tool calls, reads and searches, web searches, plan updates, delegations, user messages sent during a running turn, turns, and turns that each raise a thread-scoped permission prompt.Object.keys/values/entries.finally.applyExternalUserBoundaries: sorts the boundary sequences once, then binary-searches each turn's window. The output is already ascending, so the per-turn sort is gone.findRootTurnsRunningAtThreadMessages). It walks turns sorted by start and keeps a stack that discards turns completed before the current message.How you verified
item-records.tsfrom before Index historical file paths during timeline row matching #7835: 11.4× and 13.7×.group-event-projection-turns.tsfrom before this PR: 6.97× for turns, 9.41× for per-turn thread-scoped prompts.JSON.stringify(buildThreadTimelineFromEvents(...))hashes are identical before and after, forcompletedTurnDisplaycollapse/expand ×includeNestedRowstrue/false.Full-build medians:
thr_cdfq9maj8qthr_d5ej4e2gtvSmaller threads show no measurable change.
pnpm exec turbo run test typecheck lint:type-aware lint --filter=@bb/thread-viewpasses.pnpm exec turbo run test --filter=@bb/server -- test/services/threads/timeline test/public/public-thread-timeline test/timeline-historypasses: 263 passed, 2 skipped. The skipped tests are history replays that needBB_TIMELINE_HISTORY_DB.🤖 Generated with Claude Code