From d4232d487d17a64db541e268a8e3555ada38b8a3 Mon Sep 17 00:00:00 2001 From: southseact-3d Date: Tue, 17 Feb 2026 19:03:27 +0000 Subject: [PATCH] fix: skip opencode undo when message has zero output Prevents error when undoing messages that produced no output. Checks for reply, partialOutput, or done status before sending /undo command to opencode. --- chat/server.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/chat/server.js b/chat/server.js index 07b063a..25a7d4f 100644 --- a/chat/server.js +++ b/chat/server.js @@ -17334,21 +17334,28 @@ async function handleUndoMessage(req, res, sessionId, messageId, userId) { } try { - log('Sending undo command to opencode', { sessionId, messageId, opencodeSessionId: session.opencodeSessionId }); + // Check if message had any output - if not, skip the opencode undo + const hasOutput = !!(message.reply || message.partialOutput) || message.status === 'done'; - const cliCommand = resolveCliCommand('opencode'); - const args = ['--message', '/undo']; + if (hasOutput) { + log('Sending undo command to opencode', { sessionId, messageId, opencodeSessionId: session.opencodeSessionId }); - // Add session if we have one - if (session.opencodeSessionId) { - args.push('--session', session.opencodeSessionId); + const cliCommand = resolveCliCommand('opencode'); + const args = ['--message', '/undo']; + + // Add session if we have one + if (session.opencodeSessionId) { + args.push('--session', session.opencodeSessionId); + } + + await runCommand(cliCommand, args, { + cwd: session.workspaceDir || REPO_ROOT, + timeout: 30000 + }); + } else { + log('Skipping undo command - message had zero output', { sessionId, messageId }); } - await runCommand(cliCommand, args, { - cwd: session.workspaceDir || REPO_ROOT, - timeout: 30000 - }); - // Clear todos from the message when undone if (message.todos) { const todoCount = message.todos.length;