fix: skip opencode undo when message has zero output
Prevents error when undoing messages that produced no output. Checks for reply, partialOutput, or done status before sending /undo command to opencode.
This commit is contained in:
@@ -17334,21 +17334,28 @@ async function handleUndoMessage(req, res, sessionId, messageId, userId) {
|
||||
}
|
||||
|
||||
try {
|
||||
log('Sending undo command to opencode', { sessionId, messageId, opencodeSessionId: session.opencodeSessionId });
|
||||
// Check if message had any output - if not, skip the opencode undo
|
||||
const hasOutput = !!(message.reply || message.partialOutput) || message.status === 'done';
|
||||
|
||||
const cliCommand = resolveCliCommand('opencode');
|
||||
const args = ['--message', '/undo'];
|
||||
if (hasOutput) {
|
||||
log('Sending undo command to opencode', { sessionId, messageId, opencodeSessionId: session.opencodeSessionId });
|
||||
|
||||
// Add session if we have one
|
||||
if (session.opencodeSessionId) {
|
||||
args.push('--session', session.opencodeSessionId);
|
||||
const cliCommand = resolveCliCommand('opencode');
|
||||
const args = ['--message', '/undo'];
|
||||
|
||||
// Add session if we have one
|
||||
if (session.opencodeSessionId) {
|
||||
args.push('--session', session.opencodeSessionId);
|
||||
}
|
||||
|
||||
await runCommand(cliCommand, args, {
|
||||
cwd: session.workspaceDir || REPO_ROOT,
|
||||
timeout: 30000
|
||||
});
|
||||
} else {
|
||||
log('Skipping undo command - message had zero output', { sessionId, messageId });
|
||||
}
|
||||
|
||||
await runCommand(cliCommand, args, {
|
||||
cwd: session.workspaceDir || REPO_ROOT,
|
||||
timeout: 30000
|
||||
});
|
||||
|
||||
// Clear todos from the message when undone
|
||||
if (message.todos) {
|
||||
const todoCount = message.todos.length;
|
||||
|
||||
Reference in New Issue
Block a user