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.
This commit is contained in:
@@ -329,8 +329,13 @@ async function redoMessage(msg, session) {
|
|||||||
.slice(0, messageIndex)
|
.slice(0, messageIndex)
|
||||||
.some(m => m.cli === 'opencode');
|
.some(m => m.cli === 'opencode');
|
||||||
|
|
||||||
// Only undo if there are previous opencode messages
|
// Check if any previous messages had output (files were changed)
|
||||||
if (hasPreviousOpencodeMessages) {
|
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 {
|
try {
|
||||||
await api(`/api/sessions/${session.id}/messages/${msg.id}/undo`, {
|
await api(`/api/sessions/${session.id}/messages/${msg.id}/undo`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -340,7 +345,7 @@ async function redoMessage(msg, session) {
|
|||||||
console.warn('Undo failed, continuing with redo:', err.message);
|
console.warn('Undo failed, continuing with redo:', err.message);
|
||||||
}
|
}
|
||||||
} else {
|
} 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...');
|
setStatus('Starting build...');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user