旧 CLI 的延迟 close 事件会覆盖新 CLI 的 SDK WS 旧 CLI 的 close 事件被识别为 stale,被忽略

旧 CLI 的延迟 close 事件会覆盖新 CLI 的 SDK WS	旧 CLI 的 close 事件被识别为 stale,被忽略
This commit is contained in:
zhb 2026-06-20 01:32:44 +08:00 committed by GitHub
parent ad33980c40
commit a78d669c10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -694,11 +694,21 @@ export class ConversationService {
return true
}
detachSdkConnection(sessionId: string): void {
detachSdkConnection(
sessionId: string,
socket?: { send(data: string): void },
): void {
const session = this.sessions.get(sessionId)
if (session) {
session.sdkSocket = null
if (!session) return
// Only clear sdkSocket when the closing socket is the one currently
// attached. During a restart transition the old CLI's WS close event
// can arrive AFTER the new CLI has already connected its own SDK WS —
// blindly nulling here would clobber the fresh connection and leave
// outbound messages stranded in pendingOutbound forever.
if (socket && session.sdkSocket && session.sdkSocket !== socket) {
return
}
session.sdkSocket = null
}
handleSdkPayload(sessionId: string, rawPayload: string): void {