Skip to content

fix(messages): emit Socket.io newMessage on user-message POST#304

Closed
lilyshen0722 wants to merge 1 commit intomainfrom
lily/messages-socket-broadcast
Closed

fix(messages): emit Socket.io newMessage on user-message POST#304
lilyshen0722 wants to merge 1 commit intomainfrom
lily/messages-socket-broadcast

Conversation

@lilyshen0722
Copy link
Copy Markdown
Contributor

Mirrors the agent-runtime broadcast in the user path. Before this fix, human-posted messages didn't appear live for other connected users — only on refresh.

Surfaced during YC demo recording.

🤖 Generated with Claude Code

Previously, only the agent-runtime path (`agentMessageService.postMessage`)
emitted a `newMessage` Socket.io event when a message landed. The human-
user path (`messageController.createMessage`) saved to PG/Mongo and
returned the row, but never broadcast — so when a human posted in a
pod, every other connected user only saw the message on manual refresh.

Symptom: chat looks broken for everyone except the message author. Easy
to miss in dev because the author's own client renders the message
optimistically from the response, so only second-user testing surfaces
the gap.

Fix: mirror the broadcast shape from `agentMessageService` (same `pod_id`
+ `podId` both populated for V2's cross-pod-leak filter, same fallback
ordering for `_id`/`id`, same field names). Wrapped in try/catch so a
broken socket layer can't fail the message post.

Surfaced during YC demo recording — Mike's user-token messages weren't
showing up live in Sam's tab while Cody's agent-runtime messages were.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lilyshen0722 lilyshen0722 deleted the lily/messages-socket-broadcast branch May 4, 2026 20:06
lilyshen0722 added a commit that referenced this pull request May 4, 2026
Build (tsconfig.build.json) is stricter than the loose check; it
flagged username/messageType/profile_picture/createdAt as missing
from the NormalizedMessage cast in the socket-emit block from #304.
Widening the inline type assertion to include the optional fields
the formattedMessage shape reads. No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lilyshen0722 added a commit that referenced this pull request May 4, 2026
…oadcast (305)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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