Skip to content

Use the existing type index for event context queries - #3874

Merged
ymichael merged 1 commit into
mainfrom
bb/timeline-typed-context-index
Sep 17, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/timeline-typed-context-index

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Bounded event-type queries in listStoredEventRows could 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_idx for 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

  • Added the missing lower-bound case to the migrated SQLite query-plan regression. It fails before the change and passes after it.
  • pnpm exec turbo run test typecheck --filter=@bb/db: 577 tests and typecheck pass, including event query ordering/bounds behavior.
  • Compared default HTTP route cold opens, cached opens and unchanged deltas for all 2,385 threads in a consistent read-only main-database snapshot: all payload hashes match before/after. One deleted-thread 404 is unchanged. One warmup and three measured rounds per thread; nine initially flagged cold requests were rechecked with nine samples, followed by a reverse-order 15-sample confirmation for the remaining flag. No cold regression remained above both 10% and 5 ms.
  • The slow context-heavy request fell from 456 ms to 118 ms in the census and 448 ms to 100 ms in the final confirmation. This includes route execution, serialization and response parsing, but excludes network/browser time; cold clears application caches, not disk caches. The broad census ran versions sequentially and the host was shared, so small distribution changes are not claimed as stable speedups.

AGENT GENERATED

@ymichael
ymichael merged commit a5f12b2 into main Sep 17, 2026
16 checks passed
@ymichael
ymichael deleted the bb/timeline-typed-context-index branch September 17, 2026 22:40
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant