diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index 8a1bf1101d4..b1fde1e8932 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -987,32 +987,26 @@ export class Task extends EventEmitter { return "just now" })() - const lastTaskResumptionIndex = newUserContent.findIndex( - (x) => x.type === "text" && x.text.startsWith("[TASK RESUMPTION]"), - ) - if (lastTaskResumptionIndex !== -1) { - newUserContent.splice(lastTaskResumptionIndex, newUserContent.length - lastTaskResumptionIndex) + if (responseText) { + newUserContent.push({ + type: "text", + text: `\n\nNew instructions for task continuation:\n\n${responseText}\n`, + }) } - const wasRecent = lastClineMessage?.ts && Date.now() - lastClineMessage.ts < 30_000 - - newUserContent.push({ - type: "text", - text: - `[TASK RESUMPTION] This task was interrupted ${agoText}. It may or may not be complete, so please reassess the task context. Be aware that the project state may have changed since then. If the task has not been completed, retry the last step before interruption and proceed with completing the task.\n\nNote: If you previously attempted a tool use that the user did not provide a result for, you should assume the tool use was not successful and assess whether you should retry. If the last tool was a browser_action, the browser has been closed and you must launch a new browser if needed.${ - wasRecent - ? "\n\nIMPORTANT: If the last tool use was a write_to_file that was interrupted, the file was reverted back to its original state before the interrupted edit, and you do NOT need to re-read the file as you already have its up-to-date contents." - : "" - }` + - (responseText - ? `\n\nNew instructions for task continuation:\n\n${responseText}\n` - : ""), - }) - if (responseImages && responseImages.length > 0) { newUserContent.push(...formatResponse.imageBlocks(responseImages)) } + // Ensure we have at least some content to send to the API + // If newUserContent is empty, add a minimal resumption message + if (newUserContent.length === 0) { + newUserContent.push({ + type: "text", + text: "[TASK RESUMPTION] Resuming task...", + }) + } + await this.overwriteApiConversationHistory(modifiedApiConversationHistory) console.log(`[subtasks] task ${this.taskId}.${this.instanceId} resuming from history item`)