From 9eb497c4f5a854079573eb670d232d1e7226b4f9 Mon Sep 17 00:00:00 2001 From: scotthuang Date: Wed, 15 Apr 2026 12:55:55 +0800 Subject: [PATCH] fix(ui): skip chat history reload during active sends to prevent message card delay When a user sends a message, the Control UI performs an optimistic update to display the message immediately. However, if a session.message gateway event arrives during the send, it triggers an unconditional loadChatHistory() call. This race condition resets chatStream to null, causing the optimistic message card to disappear until the first LLM delta arrives. The fix adds a guard to skip history reload while a chat run is active (host.chatRunId is set). The chat event handler already manages streaming state and appends the final assistant message, making the concurrent reload unnecessary during active sends. External message refresh is preserved for idle sessions. Fixes the regression introduced in commit 20266c14cb (added session.message event handling for qa-lab testing). Co-Authored-By: Claude Opus 4.6 (1M context) --- ui/src/ui/app-gateway.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/src/ui/app-gateway.ts b/ui/src/ui/app-gateway.ts index ea1a30a0c8d..24774177dd8 100644 --- a/ui/src/ui/app-gateway.ts +++ b/ui/src/ui/app-gateway.ts @@ -422,6 +422,14 @@ function handleSessionMessageGatewayEvent( if (!sessionKey || sessionKey !== host.sessionKey) { return; } + // Skip history reload while a chat run is active. The chat event handler + // manages streaming state and appends the final assistant message. Reloading + // history mid-run races with the optimistic user-message update and resets + // chatStream, which delays the user message card from appearing until the + // first LLM delta arrives. + if (host.chatRunId) { + return; + } void loadChatHistory(host as unknown as ChatState); }