Repository navigation
Conversation
isTimelineCursorSequencePresent, listTimelineInterruptionRows and listTimelineWindowHintsDescending rebuilt their Drizzle query and called SQLite prepare() on every call. They now use prepareCachedQuery with placeholders, like their sibling readers, and accept DbQueryConnection so transactions reuse the same cache path. Fixes #8497 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/8497-db-5-fixed-shape-timeline-readers-in-events-thr_zbjr6j6wpq
branch
December 2, 2026 19:30
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
#8497 listed five timeline readers in
packages/db/src/data/events.tsthat rebuilt their Drizzle query and called SQLiteprepare()on every call. Two of them,listTodoSnapshotEventRowsForThreadandgetLatestModelFallbackRowSinceTurnRequest, were already cached on main by #8490. The other three were not:isTimelineCursorSequencePresent,listTimelineInterruptionRowsandlistTimelineWindowHintsDescending. Each call paid for compiling the SQL again, and SQLite prepared the statement again.What changed
prepareCachedQuery, with placeholders for their fixed scalar arguments. This is the same pattern their sibling readers use.listTimelineWindowHintsDescendingchanges from a rawdb.all(sql…)to the query builder. It keeps the sameINDEXED BY events_thread_type_sequence_idx, the same predicates and the sameDESCorder and limit.DbQueryConnection, so calls inside a transaction use the same cache.EXPLAIN QUERY PLANis unchanged. All three still search their original index, and none of them builds a temp B-tree.How you verified
Added the three readers to the case table in
packages/db/test/data/events-preparation.test.ts. The table checks correct results for fresh bindings and inside transactions, with zeroprepare()calls after warm-up. All three new cases fail on main and pass with this change.pnpm exec turbo run typecheck test --filter=@bb/db: 822 tests pass.pnpm exec turbo run typecheck --filter=@bb/serverpasses. The server timeline, request-path-statements and thread-derived-cache-equivalence tests pass: 32 files, 298 tests.The issue's repro script reports 0 prepares per call for all five readers. Before this change, three of them reported 1 per call.
Real data: the events of a 52,700-event thread copied from a production
bb.db, with 2,000 warm calls per reader. Old and new code return identical results.isTimelineCursorSequencePresentlistTimelineInterruptionRowslistTimelineWindowHintsDescendingFixes #8497
🤖 Generated with Claude Code