From 103951eb3ca5c7e99b8cb5796142d69b41fec818 Mon Sep 17 00:00:00 2001 From: southseact-3d Date: Tue, 17 Feb 2026 10:13:12 +0000 Subject: [PATCH] fix: skip undo in redo flow when no previous output exists When clicking redo on a message, the system would fail with 'Command exited with code 1' if there were previous opencode messages but none of them produced any output. Now we check if previous messages actually had output (reply or partialOutput) before attempting to undo, preventing the error when there's nothing to undo. Fixes issue where redo button fails when previous messages had no output. --- chat/public/builder.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/chat/public/builder.js b/chat/public/builder.js index 510ae6c..a5dc83e 100644 --- a/chat/public/builder.js +++ b/chat/public/builder.js @@ -329,8 +329,13 @@ async function redoMessage(msg, session) { .slice(0, messageIndex) .some(m => m.cli === 'opencode'); - // Only undo if there are previous opencode messages - if (hasPreviousOpencodeMessages) { + // Check if any previous messages had output (files were changed) + const hasPreviousOutput = session.messages + .slice(0, messageIndex) + .some(m => m.cli === 'opencode' && (m.reply || m.partialOutput)); + + // Only undo if there are previous opencode messages AND they produced output + if (hasPreviousOpencodeMessages && hasPreviousOutput) { try { await api(`/api/sessions/${session.id}/messages/${msg.id}/undo`, { method: 'POST', @@ -340,7 +345,7 @@ async function redoMessage(msg, session) { console.warn('Undo failed, continuing with redo:', err.message); } } else { - console.log('First build message - skipping undo, proceeding directly to rebuild'); + console.log('No previous output to undo - skipping undo, proceeding directly to rebuild'); setStatus('Starting build...'); }