Repository navigation
Keep streaming message prefixes across the in-turn window cut - #913
Merged
Merged
Conversation
The in-turn event-budget window's buffered-text guard keyed off row.itemKind on in-window rows, but the only in-window rows for a still-streaming message that began below the cut are delta rows, and delta rows are always persisted with item_kind = NULL. The guard never fired in production, so the tops of long streaming assistant messages were clipped and the cut point advanced with the budget floor. Read the item kind from the backfilled item/started lifecycle row instead, and let the completed-item check cover backfilled rows so an item that finished below the cut is not treated as still streaming. The regression test only passed because it seeded delta rows with an itemKind through raw insertEvents — a shape the production write path (deriveStoredEventItemFieldsFromSource) can never produce. Seed deltas with itemKind: null; the test now fails against the previous code. Co-Authored-By: Claude Fable 5 <[email protected]>
amadad
pushed a commit
to amadad/bb
that referenced
this pull request
Aug 14, 2026
…#913) ## The problem Since get-bb#891 bounded timeline cost within long-running turns, the tops of long streaming assistant messages were clipped — the message rendered starting mid-sentence, and the cut point kept advancing as the stream grew (observed live in a real thread whose final message streamed ~28KB across ~5,700 events in one turn). get-bb#894 added a guard meant to carry a still-streaming message's below-the-cut deltas into the owning window, but the guard keyed off `row.itemKind` on the in-window rows. The only in-window rows for a message that began below the budget floor are delta rows, and delta rows are always persisted with `item_kind = NULL` (`deriveStoredEventItemFieldsFromSource`). The guard therefore never fired in production: verified against a live database where all 9,242 `item/agentMessage/delta` rows have a NULL kind. ## The fix `ensureInTurnWindowWholeItemRows` now reads the item kind from the backfilled `item/started` lifecycle row instead of from in-window rows. The lifecycle backfill is fetched first, and the completed-item check covers backfilled rows too, so an item that completed below the cut is never treated as still streaming. ## Why CI was green The get-bb#894 regression test seeded delta rows with `itemKind: "agentMessage"` through raw `insertEvents` — a row shape the production write path can never produce. The test now seeds deltas with `itemKind: null`, and fails against the previous server code. The parented-toolCall `itemKind === "toolCall"` checks elsewhere in `timeline.ts` were audited and left alone: they run after whole-item backfill has merged in lifecycle rows, so the kind is available there. ## Testing - `pnpm exec turbo run test --filter=@bb/server -- --run` on all 7 timeline suites (33 tests pass) - rewritten regression test confirmed to fail against pre-fix `timeline.ts` - `pnpm exec turbo run typecheck --filter=@bb/server` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <[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.
The problem
Since #891 bounded timeline cost within long-running turns, the tops of long streaming assistant messages were clipped — the message rendered starting mid-sentence, and the cut point kept advancing as the stream grew (observed live in a real thread whose final message streamed ~28KB across ~5,700 events in one turn).
#894 added a guard meant to carry a still-streaming message's below-the-cut deltas into the owning window, but the guard keyed off
row.itemKindon the in-window rows. The only in-window rows for a message that began below the budget floor are delta rows, and delta rows are always persisted withitem_kind = NULL(deriveStoredEventItemFieldsFromSource). The guard therefore never fired in production: verified against a live database where all 9,242item/agentMessage/deltarows have a NULL kind.The fix
ensureInTurnWindowWholeItemRowsnow reads the item kind from the backfilleditem/startedlifecycle row instead of from in-window rows. The lifecycle backfill is fetched first, and the completed-item check covers backfilled rows too, so an item that completed below the cut is never treated as still streaming.Why CI was green
The #894 regression test seeded delta rows with
itemKind: "agentMessage"through rawinsertEvents— a row shape the production write path can never produce. The test now seeds deltas withitemKind: null, and fails against the previous server code.The parented-toolCall
itemKind === "toolCall"checks elsewhere intimeline.tswere audited and left alone: they run after whole-item backfill has merged in lifecycle rows, so the kind is available there.Testing
pnpm exec turbo run test --filter=@bb/server -- --runon all 7 timeline suites (33 tests pass)timeline.tspnpm exec turbo run typecheck --filter=@bb/server🤖 Generated with Claude Code