diff --git a/server.js b/server.js index 13920f1..9d3a278 100644 --- a/server.js +++ b/server.js @@ -777,7 +777,12 @@ async function waitForCommandResult(executionId, commandId, timeout) { if (execution.length > 0) { const logs = typeof execution[0].logs === 'string' ? JSON.parse(execution[0].logs) : execution[0].logs; - const resultLog = logs.find(log => log.command_id === commandId && log.action === 'command_result'); + // Find the command_sent entry for this commandId, then look for the next command_result after it. + // (Worker doesn't echo command_id back, so we can't match by command_id directly.) + const sentIdx = logs.findIndex(l => l.command_id === commandId && l.action === 'command_sent'); + const resultLog = sentIdx >= 0 + ? logs.slice(sentIdx + 1).find(l => l.action === 'command_result') + : logs.find(l => l.command_id === commandId && l.action === 'command_result'); if (resultLog) { clearInterval(checkInterval);