From 3f6e64996560b2fbc1e35a39fe5c7f60d0346a00 Mon Sep 17 00:00:00 2001 From: Developer Date: Mon, 16 Feb 2026 21:11:00 +0000 Subject: [PATCH] fix: skip undo for first build message to avoid exit code 1 error When clicking redo on the first build message, the system would fail with 'Command exited with code 1' because there was nothing to undo. Now we detect if this is the first opencode message and skip the undo step, proceeding directly to rebuilding. Fixes issue where redo button fails on first message in builder. --- chat/public/builder.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/chat/public/builder.js b/chat/public/builder.js index b0e6417..510ae6c 100644 --- a/chat/public/builder.js +++ b/chat/public/builder.js @@ -323,14 +323,25 @@ async function redoMessage(msg, session) { // Case 1: Proceed with Build - undo first, then rebuild with plan content if (isProceedWithBuild) { - // First, send undo to revert any file changes - try { - await api(`/api/sessions/${session.id}/messages/${msg.id}/undo`, { - method: 'POST', - }); - setStatus('Undo complete, rebuilding...'); - } catch (err) { - console.warn('Undo failed, continuing with redo:', err.message); + // Check if this is the first opencode message (nothing to undo yet) + const messageIndex = session.messages.findIndex(m => m.id === msg.id); + const hasPreviousOpencodeMessages = session.messages + .slice(0, messageIndex) + .some(m => m.cli === 'opencode'); + + // Only undo if there are previous opencode messages + if (hasPreviousOpencodeMessages) { + try { + await api(`/api/sessions/${session.id}/messages/${msg.id}/undo`, { + method: 'POST', + }); + setStatus('Undo complete, rebuilding...'); + } catch (err) { + console.warn('Undo failed, continuing with redo:', err.message); + } + } else { + console.log('First build message - skipping undo, proceeding directly to rebuild'); + setStatus('Starting build...'); } // Get the plan content - either stored on the message or try to extract from content