Repository navigation
Conversation
This was referenced Aug 21, 2026
Collaborator
|
ymichael
added a commit
that referenced
this pull request
Nov 4, 2026
## Human comments ## What was wrong The timeline response cache keyed entries by `maxSeq`, so every new event left a dead entry behind. One streaming thread fills the 128 slots with revisions nobody can hit again and evicts every idle thread. Switching back to an idle thread then rebuilds its window from scratch. The key also carried the thread's status and surface (title, workspace and display settings), so a turn starting or ending, a generated title or a settings change left the previous entry behind as well. Tracked in #2066. ## What changed `apps/server/src/services/threads/timeline-cache.ts`, `thread-timeline-windows.ts`: - The cache key is the request shape only: thread, page, `summaryOnly`, `deferContent`, `includeNestedRows`. - Each entry stores a revision stamp of the thread state it was built from: `maxSeq`, status and surface. A request with the same stamp hits the cache; anything else rebuilds and replaces the entry, so each request shape keeps exactly one entry. - Limits and invalidation are unchanged. This is the #2067 / #2218 approach, redone on current main. ## How you verified - New cases in `timeline-cache.test.ts`: a maxSeq advance replaces the entry, a status or title change replaces the entry, an idle thread stays cached while another thread streams revisions, and the stale revision is dropped when the rebuilt window is not cacheable. The key and revision builders each differ for every one of their inputs. - Route-level repro (`/api/v1/threads/:id/timeline`, seeded DB): 6 idle threads were opened, then another thread appended N events with a timeline read after each, then the idle threads were reopened. Median idle reopen: | events between visits | main | this PR | |---|---|---| | 30 | 0.3 ms | 0.4 ms | | 100 | 0.2 ms | 0.3 ms | | 130 | 10.8 ms | 0.3 ms | | 300 | 10.8 ms | 0.3 ms | - A live bb database showed about 170 events a minute across 8 threads, so main's cache churns in under a minute while a thread is open and streaming. - Benchmark on the real timeline route: switching between 6 idle threads while another thread streamed 25 events between switches, for 18 switches: median 108 ms on main, 3.6 ms on this PR (p90 157 ms vs 6.1 ms). - `pnpm exec turbo run typecheck lint --filter=@bb/server`, and the server `test/services/threads` and `test/public/public-thread-timeline*` suites (38 files, 341 tests) pass after merging current main. Fixes #2066 > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: hellno <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Michael Yong <[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.
What was wrong
The timeline response cache included the thread max sequence in its map key. Each appended event therefore made the prior entry unreachable by future lookups while still retaining its full payload until global LRU eviction. Active threads could accumulate many obsolete revisions for the same request shape, contributing avoidable server heap pressure. See #2066.
What changed
How you verified
timeline-cache.test.tsVitest suite: 7/7 passed; the revision-retention assertion failed before the implementation change.@bb/serverTurbo typecheck passed.git diff --check origin/main...HEADpassed after rebasing onto currentmain.Fixes #2066