fix(playground): key chat messages by sender and timestamp - #2275
Open
leepokai wants to merge 1 commit into
Open
fix(playground): key chat messages by sender and timestamp#2275leepokai wants to merge 1 commit into
leepokai wants to merge 1 commit into
Conversation
`MessageList` keyed each row by `item.time` alone, a millisecond timestamp stamped when the transcript is sent. `addChatItem` scopes its dedupe to a single `userId`, so a user transcript and an agent transcript that share a millisecond are both pushed and React sees two children with one key. Speech-to-speech graphs make that routine rather than rare: the final input transcription lands as the first output transcript delta arrives, and the two are sent with different stream_ids, so neither the dedupe nor the discard branch collapses them. Keying by sender and timestamp together is enough. Two items from the same sender can never collide, because the reducer already discards or replaces them before they reach the list.
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.
Problem
The chat list throws a React key collision during normal conversation:
The key is a millisecond timestamp, so this is not purely cosmetic — React warns that colliding keys can drop or duplicate rendered children, meaning chat lines can visibly disappear or repeat.
Root cause
MessageListkeys each row byitem.timealone:item.timeistext_ts, stamped withint(time.time() * 1000)when the transcript is sent, anditem.userIdis the sender'sstream_id. TheaddChatItemreducer scopes both its discard and its replace branches to a singleuserId:So two transcripts from different senders that share a millisecond are both pushed, and the list renders two children with the same key.
Two transcripts from the same sender can never collide — the reducer either discards the later one (
time <= LastFinalItem.time) or replaces the pending non-final item.Speech-to-speech graphs make the cross-sender collision routine rather than rare: the final input transcription is emitted as the first output transcript delta arrives, and the two are sent with different
stream_ids.Fix
Key by sender and timestamp together, which is unique by the argument above.
Verification
Reproduced by replaying the reducer with a user transcript (
stream_idfrom session metadata) and an agent transcript (stream_id100) sharing one millisecond — two items, one key. With the composite key both rows are unique, and the same-sender case still collapses to a single item, so no row is lost.Confirmed against a running
voice_assistant_realtimegraph: the warning fired twice during ordinary conversation before the change and does not appear after it.