Use the existing type index for event context queries - #3874
Merged
Merged
Conversation
This was referenced Sep 17, 2026
ymichael
added a commit
that referenced
this pull request
Sep 17, 2026
## Human comments ## What was wrong Latest plan/goal snapshots were inserted into conversation context before its bounds were calculated. An old plan could pull thousands of unrelated turn markers into a small current page. Projecting that snapshot as a partial historical turn also made current row ordering depend on unrelated head state. ## What changed Load latest head state separately and use it only for plan/goal extraction. Conversation events determine context bounds, grouping, and pagination. Include head-state rows in selection-cache byte accounting. Stacked on #3874; this PR contains only the head-state separation. ## How you verified - Added regressions for an old plan across 100 turns, auxiliary state preserving current row order, and late changes to omitted commands retaining the pagination merge guard. - 406 thread-view tests, relevant timeline server tests, client-core tests, and server/thread-view/client-core typechecks passed. Final head-state and selection-memo run: 18 tests passed. - Compared actual default cold, repeat-open, and unchanged-update routes across all 2,385 threads in a consistent read-only main-DB snapshot. Rendered rows and head state match throughout. 41 threads change only `olderRowsSourceSeqEnd`, because auxiliary historical snapshots no longer participate in conversation projection. One already-deleted thread returns the same 404. - Cold Post-merge cop: 117.55 → 35.45 ms after the index fix, with 7,364 → 901 selected events. S10 remains at 7,161 events. Broad latency flags were rechecked over nine measured samples across 19 threads; none retained a >10% and >5 ms regression. Focused Post-merge cop: 109.22 → 36.06 ms. Measurements are server-route timings on a shared host, not browser rendering timings. > AGENT GENERATED
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
Bounded event-type queries in
listStoredEventRowscould use the thread/sequence index and filter by type, despite an existing thread/type/sequence index. A measured default timeline request executed six such context queries over 110,630 event rows. Even a query returning no rejected inputs took about 54 ms.What changed
Select the existing
events_thread_type_sequence_idxfor typed queries, retaining the planner-selected path for unfiltered queries. Use the existing SQL field projection helper for Drizzle's indexed table expression. Ordering, bounds, type deduplication, limits and returned fields are preserved. No new index, migration, public API or daemon protocol change.This is the first independent performance follow-up to #3817. It does not change conversation-context bounds or detail reconstruction.
How you verified
pnpm exec turbo run test typecheck --filter=@bb/db: 577 tests and typecheck pass, including event query ordering/bounds behavior.