From 80c2dac8163bd2616a75015e3f2bcd79a36714df Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 27 Feb 2026 04:36:44 +0000 Subject: [PATCH] Fix: always remove optimistic message on dispatch error to prevent ghost messages When attemptedTurnStart is true but the thread.turn.start dispatch fails (e.g. network error), the optimistic user message was never removed from optimisticUserMessages. The catch block only cleaned up when !attemptedTurnStart, leaving a permanently visible ghost message. Move setOptimisticUserMessages filter outside the !attemptedTurnStart guard so it always runs on error. The prompt/image restoration remains gated behind !attemptedTurnStart since that only applies to pre-send failures. --- apps/web/src/components/ChatView.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index c1bfa62f2b..c2a3341bb7 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -1509,14 +1509,14 @@ export default function ChatView({ threadId }: ChatViewProps) { createdAt: messageCreatedAt, }); } catch (err) { + setOptimisticUserMessages((existing) => + existing.filter((message) => message.id !== messageIdForSend), + ); if ( !attemptedTurnStart && promptRef.current.length === 0 && composerImagesRef.current.length === 0 ) { - setOptimisticUserMessages((existing) => - existing.filter((message) => message.id !== messageIdForSend), - ); promptRef.current = trimmed; setPrompt(trimmed); setComposerImages(composerImagesSnapshot);