From 36e7197994e1ef53087ecdb759262f5c6f780979 Mon Sep 17 00:00:00 2001 From: gongzhiyong Date: Wed, 15 Apr 2026 02:51:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(P0):=20=E4=BF=AE=E5=A4=8D=E6=96=B0=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E5=8F=91=E6=B6=88=E6=81=AF=E5=90=8E=E8=B7=B3=E5=9B=9E?= =?UTF-8?q?=E6=AC=A2=E8=BF=8E=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:ensureThread() 通过 setCurrentThreadId 设置新线程ID,但 React 状态 未同步刷新,useStream 仍绑定 threadId=undefined,导致 submit() 提交到 错误的线程。 修复:在 submit 前手动调 thread.switchThread(activeThreadId),确保 useStream 立即指向新创建的线程。 Co-Authored-By: Claude Opus 4.6 (1M context) --- langgraph/src/main.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/langgraph/src/main.tsx b/langgraph/src/main.tsx index 9e59f56..2d7ace6 100644 --- a/langgraph/src/main.tsx +++ b/langgraph/src/main.tsx @@ -217,11 +217,12 @@ function App() { setConcurrentStatus("idle"); return; } - // For a newly created thread, currentThreadId just changed so the useEffect - // would call thread.switchThread() which clears thread.messages mid-stream. - // Skip it — useStream already uses the updated threadId prop from currentThreadId. + // For a newly created thread, currentThreadId just changed via setCurrentThreadId + // but React state hasn't flushed yet — useStream still has threadId=undefined. + // Manually switch useStream to the new thread so submit() targets the right thread. if (!currentThreadId) { skipNextSwitchRef.current = true; + thread.switchThread(activeThreadId); } try { localStorage.removeItem(`draft_${activeThreadId}`); } catch { /* ignore */ }