问题描述
在 Doc Chat 中点击 Clear Chat 后,前端会卡在 "Connecting..." 状态,Network 面板显示多个 /stream 请求同时 pending,只有一条收到 session_initializing,其余永远连接中。
根因
processSSEStream 的 pump 函数在 done 分支和 catch 块中无条件执行了 abortRef.current = null 和 scheduleReconnect()。当用户点击 Clear Chat 时:
startNewSession(true) 创建新的 AbortController 并发起 /stream?fresh=1
- 旧的 pump 在异步 cleanup 时把
abortRef 置 null,导致新连接的 watchdog 失去保护
- 旧 pump 同时调用
scheduleReconnect(),spawn 第二条 /stream 连接
- 两条连接互相竞争,用户看到永远 "Connecting..."
修复
在 pump() 的 done 分支和 catch 块中,只在 abortRef.current === controller 时才执行 cleanup(清空 abortRef 和 scheduleReconnect)。这样过时的旧 pump 不会影响新连接。
涉及文件
frontend/src/components/DocumentChatPanel.tsx - processSSEStream 函数的 pump 回调
修复内容
pump() done 分支:
// Before:
abortRef.current = null
scheduleReconnect()
// After:
if (abortRef.current === controller) {
abortRef.current = null
scheduleReconnect()
}
startNewSession catch 块:
// Before:
scheduleReconnect()
// After:
if (abortRef.current === controller) {
scheduleReconnect()
}
问题描述
在 Doc Chat 中点击 Clear Chat 后,前端会卡在 "Connecting..." 状态,Network 面板显示多个 /stream 请求同时 pending,只有一条收到
session_initializing,其余永远连接中。根因
processSSEStream的 pump 函数在done分支和 catch 块中无条件执行了abortRef.current = null和scheduleReconnect()。当用户点击 Clear Chat 时:startNewSession(true)创建新的 AbortController 并发起 /stream?fresh=1abortRef置 null,导致新连接的 watchdog 失去保护scheduleReconnect(),spawn 第二条 /stream 连接修复
在
pump()的done分支和 catch 块中,只在abortRef.current === controller时才执行 cleanup(清空 abortRef 和 scheduleReconnect)。这样过时的旧 pump 不会影响新连接。涉及文件
frontend/src/components/DocumentChatPanel.tsx-processSSEStream函数的 pump 回调修复内容
pump()done 分支:startNewSessioncatch 块: