aws-samples / aws-samples/agents4energy
Chat page not rendering restored user messages from AgentCore memory
- Dominant language
- TypeScript
- Stars
- 48
- Forks
- 68
- PR merge metrics
- No merged PRs in 30d
Description
## Summary
On the main chat page (`web/app/(with-auth)/chat/page.tsx`), user messages loaded from AgentCore memory are not rendering correctly when a session is resumed (reload / revisit an existing session). Assistant messages come back, but user turns are missing or misrendered.
## Where the bug likely lives
The restore path for the live chat page is:
`HarnessAgent.connect()` → `loadHistory(sessionId)` → `eventsToAguiMessages()` → `MESSAGES_SNAPSHOT` → CopilotChat
- `web/lib/harness-agent.ts` — `connect()` emits a single `MESSAGES_SNAPSHOT`.
- `web/lib/converse-to-agui.ts` — `eventToMessages()` / `normalizeRole()` maps stored Converse events into role-discriminated AG-UI messages.
`normalizeRole()` (converse-to-agui.ts:39) collapses anything that isn't `"user"` to `assistant`, and `eventToMessages` only emits a user/assistant message when `content || toolCalls.length` is truthy. A user event whose text arrives only via the flattened `text` field (no `contentJson`) is handled by the fallback branch — worth verifying that branch produces a `user`-role message and that CopilotChat renders it (`.copilotKitUserMessage`).
## Reproduction
1. Open the chat page, send a message, wait for the assistant reply to finish streaming.
2. Reload the session URL (same `?sessionId=`).
3. Observe: assistant reply is restored, user prompt is missing / rendered as assistant.
## Existing coverage
`web/e2e/chat.spec.ts` → "conversation history is restored on reload" asserts `.copilotKitUserMessage` reappears after reload. If this bug is live, that test should be failing (or is flaky against real infra) — confirm and tighten.
## Suggested fix direction
- Add a unit test for `eventsToAguiMessages` / `eventToMessages` covering a user event with only `text` (no `contentJson`) and confirm it yields a `user`-role message.
- Trace the `MESSAGES_SNAPSHOT` through CopilotChat to confirm user-role messages render.
Contributor guide
Research direction
Start with web/lib/converse-to-agui.ts, especially normalizeRole() and the fallback in eventToMessages(), then trace the MESSAGES_SNAPSHOT from web/lib/harness-agent.ts into CopilotChat. Run the relevant unit coverage if present and web/e2e/chat.spec.ts. Done means a restored text-only user event produces a user-role message and .copilotKitUserMessage reappears after reload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100