From d46515d49a565aca8d33bed9fb55f8be0b6896fe Mon Sep 17 00:00:00 2001 From: southseact-3d Date: Tue, 17 Feb 2026 19:43:42 +0000 Subject: [PATCH] fix: ignore body opencodeSessionId when session was reset When session.opencodeSessionId is null (indicating the session was reset due to corruption or undo failure), ignore any opencodeSessionId sent in the request body. This prevents the client from reusing a corrupted session that was previously reset on the server. --- chat/server.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/chat/server.js b/chat/server.js index 5f42b87..aaf3ff5 100644 --- a/chat/server.js +++ b/chat/server.js @@ -16906,7 +16906,15 @@ async function handleNewMessage(req, res, sessionId, userId) { if (body.originalMessageId) message.originalMessageId = body.originalMessageId; // Preserve opencodeSessionId for session continuity in retries/continuations // Also prioritize body.opencodeSessionId over session.opencodeSessionId for explicit continuation - if (body.opencodeSessionId) { + // CRITICAL: If session.opencodeSessionId is null (session was reset), ignore body.opencodeSessionId + // to prevent reusing a corrupted session that was previously reset + if (session.opencodeSessionId === null && body.opencodeSessionId) { + log('Ignoring body opencodeSessionId because session was reset', { + bodySessionId: body.opencodeSessionId, + reason: 'Session was reset due to corruption/undo failure - forcing new session creation' + }); + // Don't set message.opencodeSessionId - let ensureOpencodeSession create a new one + } else if (body.opencodeSessionId) { message.opencodeSessionId = body.opencodeSessionId; log('Using explicit opencodeSessionId from request body', { opencodeSessionId: body.opencodeSessionId }); } else if (session.opencodeSessionId) {