From 87cf874199efa25ad1cfb9f3da54af8973d05e99 Mon Sep 17 00:00:00 2001 From: chihlasm Date: Mon, 6 Apr 2026 20:56:10 +0000 Subject: [PATCH] fix: invalidate currentChatRef before await in handleNewChat and handleResumeNew MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous fix (990f044) moved state clears before the createChatSession await but left currentChatRef.current pointing at the old session during the entire network call. Any in-flight handleSend/handleTaskSubmit for the old session would pass the guard (oldId === oldId) and re-apply stale task lane data to the new empty session. Setting currentChatRef.current = null before the await ensures in-flight handlers from the previous session see a mismatch and bail — matching the same pattern already used correctly in selectChat. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/pages/AssistantChatPage.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/src/pages/AssistantChatPage.tsx b/frontend/src/pages/AssistantChatPage.tsx index 1f675727..b3d40d3a 100644 --- a/frontend/src/pages/AssistantChatPage.tsx +++ b/frontend/src/pages/AssistantChatPage.tsx @@ -259,6 +259,10 @@ export default function AssistantChatPage() { }, []) const handleNewChat = async () => { + // Invalidate currentChatRef BEFORE the await so any in-flight handleSend/handleTaskSubmit + // for the previous session sees a mismatch and bails — prevents stale task lane appearing + // in the new empty session (same pattern as selectChat, which sets ref before its await). + currentChatRef.current = null // Clear stale state immediately — don't wait for API to return setShowTaskLane(false) setActiveQuestions([]) @@ -436,6 +440,8 @@ export default function AssistantChatPage() { } const handleResumeNew = async (summary: string) => { + // Invalidate currentChatRef BEFORE the await — same guard as handleNewChat + currentChatRef.current = null // Clear stale state immediately — don't wait for API to return setShowTaskLane(false) setActiveQuestions([])