diff --git a/apps/client/src/features/ai-chat/components/chat-thread.tsx b/apps/client/src/features/ai-chat/components/chat-thread.tsx index 801d2183..7d982b60 100644 --- a/apps/client/src/features/ai-chat/components/chat-thread.tsx +++ b/apps/client/src/features/ai-chat/components/chat-thread.tsx @@ -134,6 +134,13 @@ export default function ChatThread({ messages: initialMessages, transport, onFinish: () => onTurnFinished(), + // In AI SDK v6 `onFinish` does NOT fire when the stream errors, so a brand + // new chat that fails on its first turn would never invalidate the chat list + // nor adopt the server-created chat id (the server still creates the row and + // saves the error message). Run the same post-turn path on error so the + // failed chat appears in history immediately instead of after a manual + // refresh. The error itself is still surfaced via `error` below. + onError: () => onTurnFinished(), }); const isStreaming = status === "submitted" || status === "streaming";