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.
This commit is contained in:
Developer
2026-02-16 21:11:00 +00:00
parent f1f32a430c
commit 3f6e649965

View File

@@ -323,7 +323,14 @@ 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
// 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',
@@ -332,6 +339,10 @@ async function redoMessage(msg, session) {
} 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
let planContent = msg.planContent;