fix(api): supersede streamed fragment rows with their assistant snapshot - #388
Merged
Conversation
Streamed replies persist message.completed before the aggregated message.added snapshot arrives, so the timeline folded the stream and then rendered the snapshot again as a separate assistant message. When the driver additionally loses the message_start frame, per-envelope uuids fracture one reply into per-fragment messages and the log shows 'P' / 'ong. ...' / full-text rows (YEF-884). Track fragment rows closed without a snapshot per stream key and let a snapshot whose text prefix-matches the concatenated fragments replace them in place, keeping the first fragment's timeline position. Repairs existing rows at read time, including data written by older drivers.
Yevanchen
force-pushed
the
fix/api-fold-snapshot-supersede
branch
from
July 21, 2026 16:07
ba99c97 to
fa26bf3
Compare
Collaborator
Author
|
Clean-context review (delegated): APPROVE-WITH-NOTES, merge recommended.
Fast-follow suggested (non-blocking), |
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.
Fill what changed. Use N/A for irrelevant or maintainer-only items. See
CONTRIBUTING.mdfor branch, CLA, generated file, and CI rules.Summary
foldStreamedSessionEventRows, and let amessage.addedsnapshot whose text prefix-matches the concatenated fragments replace those rows in place (at the first fragment's timeline position) instead of rendering as an extra "Assistant message" row.message.completedlands before the aggregatedmessage.added, which used to render the reply twice) and the fractured order (a lostmessage_startsplits one reply into per-fragment messages, rendering"P"/"ong. What would you like to work on?"/ full text as three rows).Why
Verification
bun test tests/session-event-stream-fold.test.ts(16 pass, incl. new cases for the exact YEF-884 row sequence),bun test testsinapps/api(1044 pass),bun run lint,bun run tc.--output-format stream-json --include-partial-messages): the reply streams as'P'+'ong. What would you like to work on?'deltas with per-frame envelope uuids, matching the fractured rows in the screenshot.Impact
Review
apps/api/src/modules/sessions/domain/session-event-stream-fold.ts(closeGroupWithSnapshot), interaction withflushOpenStreamscarry-over.