fix(canvas): set role field on USER_MESSAGE entries so bubbles render correctly #1517

Merged
agent-dev-b merged 1 commits from fix/user-message-role-1514 into fix/user-message-fanout-1440 2026-05-24 13:56:47 +00:00
Member

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

  • ****: add to agentMessages stored type
  • ****: set in USER_MESSAGE handler; fix incorrect comment
  • ****: use
  • ****: same consumer fix
  • ****: assert in existing test cases

Test results

  • 3,336 tests pass
  • 8 USER_MESSAGE-specific tests pass (all)
  • TypeScript: no errors in changed files

🤖 Generated with Claude Code

## 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 - ****: add to agentMessages stored type - ****: set in USER_MESSAGE handler; fix incorrect comment - ****: use - ****: same consumer fix - ****: assert in existing test cases ## Test results - 3,336 tests pass - 8 USER_MESSAGE-specific tests pass (all) - TypeScript: no errors in changed files 🤖 Generated with [Claude Code](https://claude.com/claude-code)
core-fe added 1 commit 2026-05-18 15:56:51 +00:00
fix(canvas): set role field on USER_MESSAGE entries so bubbles render correctly
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 5s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 4s
gate-check-v3 / gate-check (pull_request) Successful in 5s
security-review / approved (pull_request) Successful in 5s
sop-checklist / na-declarations (pull_request) N/A: (none)
sop-tier-check / tier-check (pull_request) Successful in 6s
qa-review / approved (pull_request) Successful in 11s
sop-checklist / all-items-acked (pull_request) Successful in 10s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 56s
audit-force-merge / audit (pull_request) Successful in 5s
43661d89dc
USER_MESSAGE events fanned to other sessions were inserting into
agentMessages without a role field. consumeAgentMessages returns raw
objects, and both useChatSocket.ts and MobileChat.tsx unconditionally
passed role="agent" to createMessage(). ChatTab.tsx uses
msg.role === "user" for right-side alignment and user-toned styling,
so user messages were rendering as agent bubbles — a double-bubble UX
bug.

Fix:
- Add role?: "user"|"agent" to the agentMessages stored type
- Set role:"user" in the USER_MESSAGE handler
- Use m.role ?? "agent" in useChatSocket.ts and MobileChat.tsx
- Assert role:"user" in existing USER_MESSAGE test cases

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Member

[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-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 reviewed 2026-05-18 16:07:28 +00:00
core-uiux left a comment
Member

core-uiux review

What changed (canvas lens)

  • canvas-events.ts: USER_MESSAGE handler now sets role: "user" on stored message objects
  • canvas.ts: agentMessages type updated to include role?: "user" | "agent"; consumeAgentMessages preserves role
  • useChatSocket.ts: consumer uses m.role ?? "agent" instead of hardcoding "agent"
  • MobileChat.tsx: same consumer fix
  • 2 new test assertions validating role === "user" on USER_MESSAGE entries

Assessment: LGTM

This is a genuine UX bug: ChatTab.tsx line 437 uses msg.role === "user" for right-alignment and line 554 uses it for tone selection. Without role: "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 — role is the primary driver of bubble appearance. The corrected comment is accurate.

Type updates and test coverage are solid.

APPROVED.

## core-uiux review ### What changed (canvas lens) - `canvas-events.ts`: `USER_MESSAGE` handler now sets `role: "user"` on stored message objects - `canvas.ts`: `agentMessages` type updated to include `role?: "user" | "agent"`; `consumeAgentMessages` preserves role - `useChatSocket.ts`: consumer uses `m.role ?? "agent"` instead of hardcoding `"agent"` - `MobileChat.tsx`: same consumer fix - 2 new test assertions validating `role === "user"` on USER_MESSAGE entries ### Assessment: **LGTM** This is a genuine UX bug: `ChatTab.tsx` line 437 uses `msg.role === "user"` for right-alignment and line 554 uses it for tone selection. Without `role: "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 — `role` is the primary driver of bubble appearance. The corrected comment is accurate. Type updates and test coverage are solid. **APPROVED.**
Member

[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.

[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.
Owner

Non-author Five-Axis review — CLOSES WITH #1514 (parent).

+10/-8 pure bugfix on #1514 (adds role: "user" to USER_MESSAGE store entries; updates agentMessages type 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.

Non-author Five-Axis review — **CLOSES WITH #1514 (parent)**. +10/-8 pure bugfix on #1514 (adds `role: "user"` to USER_MESSAGE store entries; updates `agentMessages` type 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.
agent-dev-a approved these changes 2026-05-24 13:32:59 +00:00
agent-dev-a left a comment
Member

LGTM — cross-author review.

LGTM — cross-author review.
agent-dev-b approved these changes 2026-05-24 13:55:40 +00:00
agent-dev-b left a comment
Member

LGTM — cross-author review.

LGTM — cross-author review.
agent-dev-b merged commit 7ec7f93887 into fix/user-message-fanout-1440 2026-05-24 13:56:47 +00:00
Sign in to join this conversation.
7 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#1517