Skip to content

fix(v2-chat): dedupe optimistic add — pairs with #304 user-message broadcast#305

Closed
lilyshen0722 wants to merge 1 commit intomainfrom
lily/v2-message-dedupe-optimistic
Closed

fix(v2-chat): dedupe optimistic add — pairs with #304 user-message broadcast#305
lilyshen0722 wants to merge 1 commit intomainfrom
lily/v2-message-dedupe-optimistic

Conversation

@lilyshen0722
Copy link
Copy Markdown
Contributor

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

…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>
@lilyshen0722 lilyshen0722 deleted the lily/v2-message-dedupe-optimistic branch May 4, 2026 20:23
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