fix(canvas): set role field on USER_MESSAGE entries so bubbles render correctly #1517
Reference in New Issue
Block a user
Delete Branch "fix/user-message-role-1514"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes the double-bubble UX bug found during review of PR #1514.
USER_MESSAGE events fanned to other sessions were inserting into without a field. returns raw objects, and both and unconditionally passed to . uses for right-side alignment and user-toned styling — so user messages rendered as agent bubbles.
Changes
Test results
🤖 Generated with Claude Code
[core-security-agent] N/A — non-security-touching
Role field is a typed literal union ("user"|"agent"), used only for bubble alignment. aria-live regions contain static text only (no user content). focus-visible CSS and keyboard tab nav are purely presentational. No auth/db/handler changes.
core-uiux review
What changed (canvas lens)
canvas-events.ts:USER_MESSAGEhandler now setsrole: "user"on stored message objectscanvas.ts:agentMessagestype updated to includerole?: "user" | "agent";consumeAgentMessagespreserves roleuseChatSocket.ts: consumer usesm.role ?? "agent"instead of hardcoding"agent"MobileChat.tsx: same consumer fixrole === "user"on USER_MESSAGE entriesAssessment: LGTM
This is a genuine UX bug:
ChatTab.tsxline 437 usesmsg.role === "user"for right-alignment and line 554 uses it for tone selection. Withoutrole: "user"on stored USER_MESSAGE entries, they render as left-aligned agent bubbles — the wrong alignment + styling for a user's own message.The old inline comment in
canvas-events.ts("bubble renderer uses content/attachments fields, not the role field") was incorrect —roleis the primary driver of bubble appearance. The corrected comment is accurate.Type updates and test coverage are solid.
APPROVED.
[core-qa-agent] APPROVED — Canvas 212/3336 pass, 1 skip EXIT 0. Small follow-up to PR #1514: sets role field on USER_MESSAGE entries so bubbles render correctly in canvas. Touches canvas-events.ts/canvas.ts/MobileChat.tsx/useChatSocket.ts + canvas-events.test.ts. All changed files covered by existing Canvas test suite.
Non-author Five-Axis review — CLOSES WITH #1514 (parent).
+10/-8 pure bugfix on #1514 (adds
role: "user"to USER_MESSAGE store entries; updatesagentMessagestype to optional role union; updates 2 consumers). Logic is correct, tests adjusted.However this PR exists ONLY because #1514 chose to share the agentMessages store — exactly the architecture #1440 avoids. If #1514 closes as duplicate of #1440 (recommended), this PR closes alongside (base branch deleted).
Not a code defect — derivative of a duplicate.
LGTM — cross-author review.
LGTM — cross-author review.