Skip to content

Stop re-projecting whole turns on turn-details pages and whole epochs on outline loads - #7243

Merged
ymichael merged 2 commits into
mainfrom
bb/timeline-s7-other-turn-thread-sized-paths-thr_mb7ipbhx2t
Nov 9, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/timeline-s7-other-turn-thread-sized-paths-thr_mb7ipbhx2t

Conversation

@ymichael

@ymichael ymichael commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Two read paths re-projected whole turns or whole histories on every request (REPORT #7 of the Nov 7 timeline audit):

  • Turn summary details. buildTimelineTurnSummaryDetails read, decoded and projected the entire turn, then paginated it. Every "load earlier" page and every re-expand paid the full projection again. 6e9knccemi turn t2 (7,563 events) took 13 pages × ~150 ms.
  • Conversation outline. conversation-outline-cache.ts refused to keep a checkpoint once any backgroundTask or delegation item appeared in the projected history (hasBackgroundState). Every outline load of a thread that had ever run a background command therefore reprojected its whole epoch. 11 of the 12 audit threads have such items; d5ej4e2gtv paid ~140–290 ms per load.

What changed

  • timeline-turn-details-cache.ts (new) keeps the scoped turn-details projection in a per-connection LRU (32 entries, 32 MiB, 8 MiB per entry).
    • Slot: thread plus the snapshot surface, which already encodes every request input except the cursor.
    • Revision: snapshot key plus the thread's rewrite generation.
    • An entry also expires when a retained-output preview it contains would flip to retention-expired, since that preview depends on Date.now().
    • Pages paginate the cached rows. paginateTimelineContents accepts precomputed leaf sizes (measureTimelineContentLeafBytes) so they are measured once.
  • conversation-outline-cache.ts drops the blanket background guard. Background and delegation item ids join the checkpoint's referenced item set, exactly like tool-call ids, so a later selected event for a retained item rebuilds from scratch.
    • The outline SQL selection already drops a task's normal completed completion and never selects delegation rows, so the full build never depended on those events.
    • Failed or interrupted completions and progress events are selected, and they trigger the rebuild.
  • docs/timeline-pagination.md documents both behaviours.

No wire, CLI or SDK changes.

How you verified

Benchmarks used the shared audit harness, in-process against an APFS clone of the Nov 7 production snapshot. Runs were 3 alternating base/fix pairs on the same machine, each the median of 3 samples. Load average was 12–69 because other slices were benchmarking at the same time, so absolute numbers are noisy; the pairs alternate.

Turn summary details (app parameters: deferContent, whole turn, walk every beforeCursor page):

thread / turn events pages whole walk ms (before → after) re-expand ms (before → after)
6e9knccemi t2 7,563 13 1913 → 155 1914 → 4.2
6e9knccemi t3 4,212 8 643 → 83 627 → 1.5
u738kqjs29 t3 7,407 4 859 → 221 886 → 0.7
avim9t7kpe t1 5,886 6 824 → 140 840 → 1.2
kdrbtee92b t1 7,335 3 659 → 213 594 → 0.3
wg5iwwrezi t1 1,914 4 178 → 48 177 → 0.5

First pages and single-page turns cost the same as before. Parity: every page of 23 turns on 12 threads hashes identically between base and fix.

Conversation outline, thread forced active, second load after the first:

thread background events before → after ms
d5ej4e2gtv 5,262 286 → 116
6e9knccemi 276 34 → 1.4
kdrbtee92b 779 12.6 → 2.6
ymhw6pktq4 198 12.1 → 1.0
y6xhxw8t8w 168 18.9 → 7.9

Outline parity replay:

  • For each thread, the replay moves the tail of its last 25 root turns out of events and re-appends it step by step: at turn ends, mid-turn, and at random background-task events.
  • At every step it compares loadThreadConversationOutline (incremental) with buildThreadConversationOutline (independent full builder).
  • Coverage: 107 threads (the 12 audit threads, the 60 threads with the most background events, and recent threads with ≥1,000 events), 4,573 steps.
  • Result: 0 mismatches.
  • Median incremental cost per append, before → after: yvsvx8anai 18.4 → 2.1 ms, dwzy4aij2h 16.5 → 2.3 ms, 3wbmnrdpap 30.9 → 2.5 ms.

Tests added:

  • timeline-turn-details-cache.test.ts
    • One projection serves all pages and a repeat expand. Fails before: 2 extra projections.
    • A gap-fill below the latest sequence (rewrite generation bump, unchanged maxSeq) rebuilds. Fails if the generation is dropped from the revision.
    • A preview flips to retention-expired once its retention passes. Fails if the expiry is ignored.
  • conversation-outline-incremental.test.ts
    • Only the live tail is read after background tasks that finished after their turns. Fails before: 403 rows read vs < 25.
    • Matches the full rebuild when a retained background task later reports completed, failed or progress.

Commands:

pnpm exec turbo run typecheck lint --filter=@bb/server
pnpm exec turbo run test --filter=@bb/server -- test/services/threads/ test/public/public-thread-data.test.ts test/public/public-thread-timeline-completed-turn-display.test.ts   # 358 passed
pnpm exec turbo run test --filter=@bb/server -- test/public/public-thread-timeline* test/public/public-thread-cleared-context-history.test.ts test/public/public-thread-shell-command-summaries.test.ts   # 73 passed

Not changed:

  • Measured but left alone: GET /threads/:id/messages/:seq, empty-latest-window retries, bb thread wait polling, github-pr-status turnRanGh, fork history copy.
  • Remaining outline fallbacks: a nested child of a kept tool call still writing (gcuc46ug4j, kbjzy5zdu7), and threads whose turns never all settle (d5ej4e2gtv).

Refs #4674

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits November 9, 2026 12:02
Every "load earlier" page of turn summary details re-read, decoded and
re-projected the whole turn, then paginated it, and re-expanding a turn
paid the same again. Cache the scoped projection per thread and request
shape, keyed on the cursor snapshot and the thread's rewrite generation,
and serve every page and repeat expand by paginating the cached rows with
their cached leaf sizes. Entries expire when a retained-output preview
they contain would flip to retention-expired.

Snapshot A/B (3 alternating pairs, load avg 12-69), whole walk / re-expand:
- 6e9knccemi t2 (7.6k events, 13 pages): 1913 -> 155 ms / 1914 -> 4.2 ms
- u738kqjs29 t3 (7.4k events, 4 pages): 859 -> 221 ms / 886 -> 0.7 ms
- avim9t7kpe t1 (5.9k events, 6 pages): 824 -> 140 ms / 840 -> 1.2 ms
First pages and single-page turns cost the same as before. Pages are
byte-identical across 23 turns on 12 threads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Any backgroundTask or delegation item in the projected history stopped
the outline from ever keeping a checkpoint, so every outline load of a
thread that had run one background command reprojected its whole epoch.
Treat background items like tool calls instead: their ids join the
checkpoint's referenced items, and a later event for one of them rebuilds
from scratch. The outline selection already drops a task's normal
completion, so the full build never depended on it.

Outline replay over 107 snapshot threads (4,573 append steps, incremental
vs the full builder at every step): 0 mismatches. Active outline reload,
3 alternating A/B pairs: d5ej4e2gtv 286 -> 116 ms, 6e9knccemi 34 -> 1.4 ms,
kdrbtee92b 12.6 -> 2.6 ms, ymhw6pktq4 12.1 -> 1.0 ms; replay median per
append: yvsvx8anai 18.4 -> 2.1 ms, dwzy4aij2h 16.5 -> 2.3 ms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/timeline-s7-other-turn-thread-sized-paths-thr_mb7ipbhx2t branch from 3d2811c to bdd08bf Compare November 9, 2026 20:03
@ymichael
ymichael merged commit 713ee78 into main Nov 9, 2026
51 checks passed
@ymichael
ymichael deleted the bb/timeline-s7-other-turn-thread-sized-paths-thr_mb7ipbhx2t branch November 9, 2026 20:10
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