Skip to content

Timeline cache retains obsolete revisions for the same request shape #2066

Closed

Description

@Yazington

Summary

The thread timeline response cache keys entries by both request parameters and the thread's current max sequence. Every appended event therefore creates a new key while the obsolete revision remains resident until global LRU eviction, so active threads can retain many superseded response payloads instead of one current revision per request shape.

Versions and environment

  • bb 0.39.0 desktop app
  • macOS on Apple Silicon, 8 GB RAM
  • Node v22.19.0 for the source-level reproduction
  • Source behavior inspected on main; the affected cache implementation was unchanged at 6be4505

Steps to reproduce

  1. Create a ThreadTimelineCache with a capacity greater than one.
  2. Call getOrBuild for a cacheable response using one request shape and revision/max-sequence A.
  3. Append an event, then call it again with the same request shape and revision/max-sequence B.
  4. Inspect the cache entry count.
  5. A regression assertion expecting one retained entry fails before the fix with 2 !== 1.

A concrete regression test and fix are available in commit Yazington@206096e.

Expected vs actual

Actual:   cache size is 2 after two revisions of the same request shape
Expected: cache size is 1, containing only the newest revision

The same request shape should replace its obsolete revision immediately. Distinct request shapes should continue to coexist and follow the normal LRU limit.

Evidence

  • A live active thread had 5,749 events and about 11.3 MiB of event data.
  • Server logs contained 54 slow timeline builds, with windows around 1,400 events, response payloads around 1.1–4.8 MiB, and build times up to 1.34 seconds.
  • The desktop app used roughly 1.5–1.7 GB total memory during the incident; the renderer was about 670 MiB and the server about 300–650 MiB.
  • The cache allowed 128 entries. Because its key included maxSeq, each append made the prior response unreachable by lookup but still strongly retained by the map.
  • The active Codex thread remained below the cache's projected-row cutoff, so those revision payloads were eligible for caching.

What you ruled out

Suggested priority and effort (optional)

Medium — affects long-running active threads and can amplify server heap use; the fix is localized and low effort.

Checks

  • I reproduced this on the latest release or on main, or I say above that I could not.
  • I searched open and closed issues for the same problem.
  • If an agent wrote this, the body ends with > AGENT GENERATED: by <model> and links the thread or report.

AGENT GENERATED: by OpenAI Codex (GPT-5)

Activity

  1. added theissue type on Aug 21, 2026
  2. added
    threads
    on Aug 21, 2026
  3. SawyerHood commented on Aug 21, 2026

    @SawyerHood
    Collaborator

    Reproduction & root-cause report: https://get-bb.github.io/reports/issues/2066.html

    • Verdict: REPRODUCED · root-cause confidence: high
    • Root cause (short): createThreadTimelineCache keys entries by ${maxSeq}|${paramsKey}; maxSeq is monotonic so each appended event makes the prior entry unreachable but it stays in the 128-entry LRU, and the 200-row cap does not exclude ordinary streaming turns, so one viewed streaming thread fills all 128 slots with dead full responses.
    • Linked PR review: fix(server): retain one timeline revision per request shape #2067 → REQUEST CHANGES (minor) — Fix is correct and at the right layer (route-level repro goes 128 -> 1 entries; live GC'd heap growth over 100 append+refetch rounds drops from +19.4/+21.8/+21.7 MB on base to +3.6/+3.6 MB across author and revise runs, +6.0 MB in the verifier's; 695 server tests, typecheck, eslint pass; the §4a sce
    • Proposed fix: Key the response cache by paramsKey (already computed for the delta cache) and store { maxSeq, value }; a hit requires equal maxSeq, a miss deletes the slot before the row-cap check and re-inserts as MRU; delete buildThreadTimelineCacheKey and the maxSeq field of ThreadTimelineCacheKeyArgs. Implemented this revision as /tmp/bb-reports/issues/2066/repro/proposed-fix-2066.diff (timeline-cache.ts, one call site in data.ts, timeline-cache.test.ts adapted): route-level test fails before (128 !== 1) and passes after unchanged; repro-2066-unit-after-fix.test.ts passes 2/2; 25/25 timeline/delta/previe…
    • Caveats: Not a visual bug; no screenshots (one SVG chart of the heap measurement, now showing all eight runs). Verifier's major finding was correct and is fixed: the original §4a unit test is bound to the base string-key signature and throws TypeError against PR fix(server): retain one timeline revision per request shape #2067 (confirmed by re-running on the PR branch), so the report no longer claims it passes after; signature-specific rewrites were added for the P…

    The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at the base commit, and repro artifacts. It was independently re-run by a second agent (see its Verification section).

    AGENT GENERATED: by Claude Opus 5

  4. added
    confirmed-repro
    on Aug 21, 2026
  5. self-assigned this
    on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

confirmed-reproperfthreads

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions