Skip to content

Commit c1a90f3

Browse files
committed
fix(task): restore ask abort prefix and cover abort during auto-approval
1 parent 352b8e2 commit c1a90f3

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎src/core/task/Task.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
15421542
// simply removes the reference to this instance, but the instance is
15431543
// still alive until this promise resolves or rejects.)
15441544
if (this.abort) {
1545-
throw new Error(`[ZooCode#ask] task ${this.taskId}.${this.instanceId} aborted`)
1545+
throw new Error(`[RooCode#ask] task ${this.taskId}.${this.instanceId} aborted`)
15461546
}
15471547

15481548
let askTs: number
@@ -1573,7 +1573,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
15731573
if (queuedMessage) {
15741574
this.messageQueueService.releaseMessage(queuedMessage.id)
15751575
}
1576-
throw new Error(`[ZooCode#ask] task ${this.taskId}.${this.instanceId} aborted`)
1576+
throw new Error(`[RooCode#ask] task ${this.taskId}.${this.instanceId} aborted`)
15771577
}
15781578

15791579
if (partial !== undefined) {

‎src/core/task/__tests__/ask-abort-race.spec.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import type { ClineMessage } from "@roo-code/types"
22

3+
import { checkAutoApproval } from "../../auto-approval"
34
import { MessageQueueService } from "../../message-queue/MessageQueueService"
45
import { Task } from "../Task"
56

7+
vi.mock("../../auto-approval", async (importOriginal) => {
8+
const actual = await importOriginal<typeof import("../../auto-approval")>()
9+
return { ...actual, checkAutoApproval: vi.fn(actual.checkAutoApproval) }
10+
})
11+
612
function buildTask(getState: () => Promise<Record<string, unknown>>) {
713
const task = Object.create(Task.prototype) as Task
814
task["abort"] = false
@@ -46,6 +52,24 @@ describe("Task.ask abort during the auto-approval await", () => {
4652
expect(task["lastMessageTs"]).toBeUndefined()
4753
})
4854

55+
it("does not add an ask row when aborted while checkAutoApproval is pending", async () => {
56+
const gate = deferred()
57+
vi.mocked(checkAutoApproval).mockImplementationOnce(async () => {
58+
await gate.promise
59+
return { decision: "ask" }
60+
})
61+
const task = buildTask(async () => ({}))
62+
63+
const askPromise = task.ask("tool", JSON.stringify({ tool: "readFile" }), false)
64+
await vi.waitFor(() => expect(checkAutoApproval).toHaveBeenCalled())
65+
task["abort"] = true
66+
gate.release()
67+
68+
await expect(askPromise).rejects.toThrow(/aborted/)
69+
expect(task["addToClineMessages"]).not.toHaveBeenCalled()
70+
expect(task["lastMessageTs"]).toBeUndefined()
71+
})
72+
4973
it.each([
5074
["partial update", true],
5175
["partial completion", false],

0 commit comments

Comments
 (0)