Skip to content

Keep streaming message prefixes across the in-turn window cut - #913

Merged
SawyerHood merged 1 commit into
mainfrom
fix-clipped-streaming-messages
Jul 30, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
fix-clipped-streaming-messages

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

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.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 #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

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]>
@SawyerHood
SawyerHood merged commit f6894ae into main Jul 30, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the fix-clipped-streaming-messages branch July 30, 2026 23:03
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]>
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