fix(chat): pin historical user-message timestamps to activity created_at

User flagged that all historical user bubbles render with the same
"now" clock after a chat reload — both messages in the screenshot
showed 9:01:58 PM despite being sent hours apart.

ChatTab.tsx:142 minted user messages with createMessage(...) which
calls new Date().toISOString() — fine for a freshly-typed message,
wrong for hydrated history. Every reload re-stamped all user bubbles
to the render moment, collapsing the visible chronology. The agent
path on line 157 already overrides with a.created_at; mirror that.

One-line fix (spread + override timestamp) plus a comment explaining
why the override is load-bearing so the next refactor doesn't drop it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hongming Wang 2026-04-26 21:06:19 -07:00
parent f547c4e259
commit 8415870520

View File

@ -136,10 +136,14 @@ async function loadMessagesFromDB(workspaceId: string): Promise<{ messages: Chat
const messages: ChatMessage[] = [];
// Activities are newest-first, reverse for chronological order
for (const a of [...activities].reverse()) {
// Extract user message from request_body
// Extract user message from request_body. Pin the timestamp to
// the activity row's created_at — without this override every
// historical user bubble re-stamps to "now" on each chat reload,
// and ALL user messages collapse to the same render-time clock
// (same as the agent path on line 157).
const userText = extractRequestText(a.request_body);
if (userText && !isInternalSelfMessage(userText)) {
messages.push(createMessage("user", userText));
messages.push({ ...createMessage("user", userText), timestamp: a.created_at });
}
// Extract agent response — text AND any file attachments so a