From 86bd6ff332b9afe2be71529da9bc6551e95d1873 Mon Sep 17 00:00:00 2001 From: southseact-3d Date: Tue, 17 Feb 2026 19:14:05 +0000 Subject: [PATCH] fix: reset opencode session when undoing failed messages When a message fails with zero output and error status, undoing it now resets the opencode session to ensure the next message starts fresh. This prevents corrupted session reuse that was causing subsequent failures. --- chat/server.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/chat/server.js b/chat/server.js index 25a7d4f..1e12232 100644 --- a/chat/server.js +++ b/chat/server.js @@ -17354,6 +17354,19 @@ async function handleUndoMessage(req, res, sessionId, messageId, userId) { }); } else { log('Skipping undo command - message had zero output', { sessionId, messageId }); + + // If the message failed/had error, reset the opencode session to ensure fresh start + if (message.error || message.status === 'error') { + log('Resetting opencode session due to failed message', { + sessionId, + messageId, + previousSessionId: session.opencodeSessionId, + messageStatus: message.status, + hasError: !!message.error + }); + session.opencodeSessionId = null; + session.initialOpencodeSessionId = null; + } } // Clear todos from the message when undone