From b03f84aecfa2fbbedd05eea6f366dc5fd8fc897c Mon Sep 17 00:00:00 2001 From: chihlasm Date: Fri, 3 Apr 2026 05:23:55 +0000 Subject: [PATCH] fix: prevent task lane from showing previous session's data on switch Root cause: race condition between setActiveChatId and the persist effect. When switching from session A to B, setActiveChatId(B) triggers the persist effect which writes {chatId: B, questions: [A's data]} to sessionStorage BEFORE the async selectChat clears the task lane. The sessionStorage fallback then finds chatId === B and restores A's stale task lane data. Fix: clear task lane state synchronously in selectChat before the await. Server-side pending_task_lane restores it if the new session has data. Co-Authored-By: Claude Opus 4.6 (1M context) --- frontend/src/hooks/useAssistantSession.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/hooks/useAssistantSession.ts b/frontend/src/hooks/useAssistantSession.ts index d4ef81a9..25bf03ec 100644 --- a/frontend/src/hooks/useAssistantSession.ts +++ b/frontend/src/hooks/useAssistantSession.ts @@ -169,7 +169,12 @@ export function useAssistantSession() { const selectChat = useCallback(async (chatId: string) => { currentChatRef.current = chatId setActiveChatId(chatId) - // Don't clear task lane yet — wait for server response to decide + // Clear task lane immediately to prevent the persist effect from + // tagging the old session's data with the new chatId (race condition). + // Server-side pending_task_lane will restore it below if it exists. + setActiveQuestions([]) + setActiveActions([]) + setShowTaskLane(false) try { const detail = await aiSessionsApi.getSession(chatId) if (currentChatRef.current !== chatId) return