fix(v2-chat): dedupe optimistic add — pairs with #304 user-message broadcast#305
Closed
lilyshen0722 wants to merge 1 commit intomainfrom
Closed
fix(v2-chat): dedupe optimistic add — pairs with #304 user-message broadcast#305lilyshen0722 wants to merge 1 commit intomainfrom
lilyshen0722 wants to merge 1 commit intomainfrom
Conversation
…oadcast Backend #304 added a Socket.io `newMessage` emit on user-message POST to fix the "human messages don't appear live for other users" bug. That fix introduced a sender-tab race: the WS broadcast and the POST response both deliver the same message row to the sender's tab, and only the WS handler had a dedupe-by-id check (V2 hook line 194). Symptom: sending a message renders it twice in the sender's own tab — once from the WS event (which arrives async), once from the POST response (which appends without dedupe). Fix: mirror the same dedupe pattern in the optimistic-add path of sendMessage(). Whichever path arrives first wins; the second is a no-op. Order doesn't matter, both are idempotent. Other connected users still see one message (their tab only gets the WS event, no optimistic local copy), which is the correct behavior. Surfaced during YC demo recording — Sam's @nova trigger message rendered twice in his tab the first time we hit the new broadcast path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Fixes the duplicate-message-in-sender-tab regression introduced by PR #304's Socket.io broadcast on user-message POST. Mirrors the WS handler's dedupe-by-id pattern in the optimistic-add path of sendMessage().
🤖 Generated with Claude Code