Skip to content

Commit 29dcf58

Browse files
committed
fix: show first chat message immediately in new sessions
The first message in a new agent chat session was not displayed optimistically. Two issues caused this: 1. ChatMessages early-returned with the empty-state placeholder when messages was empty, ignoring pendingUserMessage entirely. 2. applySessionSnapshot and applySessionEvent cleared pendingUserMessage when the server reported working=true, even before the actual user message appeared in the stream. For a brand-new session this created a window where both pending and real messages were absent. Now the empty-state check accounts for pendingUserMessage, and the pending bubble is only cleared once the real user message arrives.
1 parent 325fb6b commit 29dcf58

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

ui/src/features/agent/components/ChatMessages.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function ChatMessages({
4949
return ids;
5050
}, [messages]);
5151

52-
if (messages.length === 0) {
52+
if (messages.length === 0 && !pendingUserMessage) {
5353
return (
5454
<div className="flex-1 flex items-center justify-center text-muted-foreground p-4 bg-popover">
5555
<div className="text-center">

ui/src/features/agent/hooks/useAgentChat.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,10 @@ export function useAgentChat() {
252252
const nextMessages = snapshot.messages || [];
253253
if (
254254
pendingUserMessage &&
255-
(nextMessages.some(
255+
nextMessages.some(
256256
(message) =>
257257
message.type === 'user' && message.content === pendingUserMessage
258-
) ||
259-
snapshot.session_state?.working)
258+
)
260259
) {
261260
setPendingUserMessage(null);
262261
}
@@ -292,11 +291,9 @@ export function useAgentChat() {
292291
setMessages((current) => mergeMessages(current, event.messages || []));
293292
}
294293

295-
// Clear the pending message when the server acknowledges it is working,
296-
// even if the user message hasn't appeared in the stream yet.
297-
if (pendingUserMessage && event.session_state?.working) {
298-
setPendingUserMessage(null);
299-
}
294+
// Only clear the pending message once the actual user message appears in
295+
// the stream. Previously this also cleared on working=true, but that
296+
// caused the pending bubble to vanish before the real message arrived.
300297

301298
if (event.session_state) {
302299
setSessionState(event.session_state);

0 commit comments

Comments
 (0)