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 {
|
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');
|
if (hasOutput) {
|
||||||
const args = ['--message', '/undo'];
|
log('Sending undo command to opencode', { sessionId, messageId, opencodeSessionId: session.opencodeSessionId });
|
||||||
|
|
||||||
// Add session if we have one
|
const cliCommand = resolveCliCommand('opencode');
|
||||||
if (session.opencodeSessionId) {
|
const args = ['--message', '/undo'];
|
||||||
args.push('--session', session.opencodeSessionId);
|
|
||||||
|
// 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
|
// Clear todos from the message when undone
|
||||||
if (message.todos) {
|
if (message.todos) {
|
||||||
const todoCount = message.todos.length;
|
const todoCount = message.todos.length;
|
||||||
|
|||||||
Reference in New Issue
Block a user