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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user