From e0b3871eada7670f1171be3bd65e6a03dc79d88c Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sat, 19 Jul 2025 18:45:54 +0000 Subject: [PATCH] fix: prevent "Current ask promise was ignored" error when cancelling tasks - Clear ask promise state (askResponse, askResponseText, askResponseImages) in abortTask() - Add abort check in ask() method to handle task cancellation gracefully - Clear ask promise state at the beginning of resumeTaskFromHistory() - This prevents the error that occurred when cancelling a task with an active ask promise Fixes #5955 --- src/core/task/Task.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index 53b8ef5b87..c95573bd83 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -518,7 +518,14 @@ export class Task extends EventEmitter { await this.addToClineMessages({ ts: askTs, type: "ask", ask: type, text, isProtected }) } - await pWaitFor(() => this.askResponse !== undefined || this.lastMessageTs !== askTs, { interval: 100 }) + await pWaitFor(() => this.askResponse !== undefined || this.lastMessageTs !== askTs || this.abort, { + interval: 100, + }) + + // If the task was aborted while waiting for a response, throw an abort error + if (this.abort) { + throw new Error(`[RooCode#ask] task ${this.taskId}.${this.instanceId} aborted while waiting for response`) + } if (this.lastMessageTs !== askTs) { // Could happen if we send multiple asks in a row i.e. with @@ -785,6 +792,12 @@ export class Task extends EventEmitter { } private async resumeTaskFromHistory() { + // Clear any lingering ask promise state from previous task instances + // This prevents "Current ask promise was ignored" errors when resuming + this.askResponse = undefined + this.askResponseText = undefined + this.askResponseImages = undefined + const modifiedClineMessages = await this.getSavedClineMessages() // Remove any resume messages that may have been added before @@ -1083,6 +1096,14 @@ export class Task extends EventEmitter { } this.abort = true + + // Clear any pending ask promise state to prevent "Current ask promise was ignored" errors + // when resuming from history + this.askResponse = undefined + this.askResponseText = undefined + this.askResponseImages = undefined + // Don't clear lastMessageTs here as it might be used by other parts of the code + this.emit("taskAborted") try {