diff --git a/frontend/src/components/workspace/chats/use-thread-chat.ts b/frontend/src/components/workspace/chats/use-thread-chat.ts index 85e7db1a8..6913e3b76 100644 --- a/frontend/src/components/workspace/chats/use-thread-chat.ts +++ b/frontend/src/components/workspace/chats/use-thread-chat.ts @@ -24,6 +24,14 @@ export function useThreadChat() { setThreadId(uuid()); return; } + // Guard: after history.replaceState updates the URL from /chats/new to + // /chats/{UUID}, Next.js useParams may still return the stale "new" value + // because replaceState does not trigger router updates. Avoid propagating + // this invalid thread ID to downstream hooks (e.g. useStream), which would + // cause a 422 from LangGraph Server. + if (threadIdFromPath === "new") { + return; + } setIsNewThread(false); setThreadId(threadIdFromPath); }, [pathname, threadIdFromPath]);