Repository navigation
Conversation
ymichael
force-pushed
the
bb/flat-turn-windowed-timeline-reads-split-out-of-7-thr_gr9htkx467
branch
from
November 17, 2026 04:03
495f17e to
7462c36
Compare
…ing turns into budget-sized pages A timeline page read every turn it touched from the start of history. thr_u738kqjs29's 17-row latest page read 7,654 events because a background task in the window had a delegation parent in a 7,400-event turn, and a long running turn with no user message inside it was a single page however long it ran (#4674). A turn whose rows render flat (a running turn, or any turn under the flat display) with many events outside the window is now read only inside the window, plus the complete events of items that cross the window edges, delegation parents and children, and the turn's lifecycle, accepted-input, compaction and provider rows. Finished turns under the collapsed display are still read whole. When no request row fits the event budget inside a running turn, the window starts on a half-budget grid, moved back to the start of the item it lands in. The cut is always a request, turn or item lifecycle row, which pruning never deletes. Batched queries render once and run directly when they fit under the SQLite variable limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged with #7541, windowed reads of flat turns disagreed with a full build in three ways: - An item whose events in the window do not include its item/started, such as Claude reasoning that streams deltas without one, was rebuilt from its in-window events only, so its row started late. The page now reads every event of such an item instead of looking for an item/started before the window. - A turn-scoped question asked before the window and answered inside it kept only its in-window lifecycle events and moved. The interaction lifecycle lookup no longer filters to thread scope, the page reads it for interactions in windowed turns, and the latest-window memo checks the same condition before appending. - Older pages loaded delegation children only when the delegation started inside the window. #7541 owns rows by display position, so this dropped or misplaced rows; the rule is removed. A turn is now read whole when at most a sixth of the event budget lies outside the window (250 events at the default 1500). With the equivalence tests' 24-event budget, that windows turns in every seed; before, five builds in one seed did. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/flat-turn-windowed-timeline-reads-split-out-of-7-thr_gr9htkx467
branch
from
November 18, 2026 00:58
a5bcf69 to
af1dd64
Compare
Collaborator
Author
|
Closing at Michael's direction. The problem is real and stays open in #4674: a page reads whole turns, so a small latest page can read thousands of events. This fix adds about 940 source lines of special cases to the window selection, and it was rebuilt on the row-ownership code that #7795 has since deleted. The examples and measurements here are being reused as the benchmark for a simpler read path.
|
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
A timeline page read every turn it touched from the start of history. thr_u738kqjs29's 17-row latest page read 7,654 events, because a background task in the window had a delegation parent in a 7,400-event turn. And because a window only ever started at a user message, a long running turn with no message inside it was a single page however long it ran: with u738 cut off mid-turn so a 5,842-event turn is still running, main's latest page is 393 rows, reading 5,866 events. This is the structural cause in #4674.
What changed
Rebased onto main after #7541 (display-position row ownership). No schema or wire change; cursors stay
timeline-v3.Windowed reads (
timeline.ts,timeline-selection-memo.ts,packages/db/src/data/events.ts). A turn whose rows render flat (a running turn, or any turn under the flat display) with more than a sixth of the event budget outside the window (250 events at the default 1500) is read only inside it. The page adds:item/startedis not among its in-window events, including items that stream without one (Claude reasoning);listStoredInteractionLifecycleRows, which no longer filters to thread scope;All other turns are read whole, as on main, including finished turns under the collapsed display. The latest-selection memo appends to windowed turns and applies the same interaction check before it appends.
Grid cuts inside long running turns (
selectTimelineWindowStart). When no request row fits the budget inside a running turn, the window starts on a half-budget grid, moved back to the start of the item it lands in. The cut is always a turn-scoped request, turn or item lifecycle row, so held older cursors survive Stop pruning from making apps refetch, and keep older cursors valid after pruning #7284's pruning. There is no grid cut once the cut's turn has finished.Batching: every new query goes through
queryRawRowsInSqliteVariableBatches.docs/timeline-pagination.mddescribes what a page reads, the grid, and the older-row bound.Changes since the previous revision, which conflicted with #7541:
item/started. They were rebuilt from in-window events only. Real case: thr_7vjjsfxsns.Source +937 / −61; tests +1,053; docs +33.
How you verified
Real data, in-process on a
VACUUM INTOcopy of a production bb.db (Nov 17), main (f1c5304) vs this branch. Medians of 5 cold reads (caches dropped between reads) in one process, so the timings show direction, not a controlled A/B.BB_TIMELINE_HISTORY_DB=~/.bb/bb.db pnpm exec turbo run test:timeline-history --filter=@bb/server, on a fresh copy of the live database, matches one full build for every thread at budgets 1500 and 120. The previous revision, merged with main, failed it on thr_gcuc46ug4j (both budgets) and thr_7vjjsfxsns (budget 120).Tests.
item/startedand a steer starting the page inside it; and a question asked before the page and answered inside it. Both fail without this revision's fixes.pnpm exec turbo run typecheck lint:type-aware --filter=@bb/server --filter=@bb/dbpnpm exec turbo run test check:query-costs --filter=@bb/db: 67 files passtest/services/threads,test/system,test/public: 1,576 passoxlintandoxfmt --checkon the touched filesRefs #4674
🤖 Generated with Claude Code