diff --git a/assistant/src/daemon/handlers/computer-use.ts b/assistant/src/daemon/handlers/computer-use.ts index 885cd78439e..de877fdd480 100644 --- a/assistant/src/daemon/handlers/computer-use.ts +++ b/assistant/src/daemon/handlers/computer-use.ts @@ -57,6 +57,13 @@ export function handleCuSessionCreate( // Clean up stale metadata from the replaced session; the new session // will set its own metadata below if needed. ctx.cuSessionMetadata.delete(msg.sessionId); + // Remove the session ID from the old socket's set so the old socket's + // close handler won't abort the replacement session. + for (const [sock, ids] of ctx.socketToCuSession) { + if (ids.delete(msg.sessionId) && ids.size === 0) { + ctx.socketToCuSession.delete(sock); + } + } } const config = getConfig();