From 2ecf0a05fb2d648b702e2e2d01d58f83f385923b Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 24 Jul 2025 18:01:34 +0000 Subject: [PATCH] Fix chat message ordering bug in handleExistingChat - Prepend new message instead of appending to maintain descending order - Fixes BUS-1486: Message order reversal when adding follow-up messages - getMessagesForChat returns newest-first, so new messages should be prepended Co-Authored-By: Dallin Bentley --- apps/server/src/api/v2/chats/services/chat-helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/server/src/api/v2/chats/services/chat-helpers.ts b/apps/server/src/api/v2/chats/services/chat-helpers.ts index b9fd30585..4a8313e9d 100644 --- a/apps/server/src/api/v2/chats/services/chat-helpers.ts +++ b/apps/server/src/api/v2/chats/services/chat-helpers.ts @@ -257,8 +257,8 @@ export async function handleExistingChat( getMessagesForChat(chatId), ]); - // Combine messages - const allMessages = newMessage ? [...existingMessages, newMessage] : existingMessages; + // Combine messages - prepend new message to maintain descending order (newest first) + const allMessages = newMessage ? [newMessage, ...existingMessages] : existingMessages; // Build chat with messages const chatWithMessages: ChatWithMessages = buildChatWithMessages(