Skip to content

Commit 484d5cf

Browse files
committed
fix(task): never dequeue queued messages for an aborted task
Tools now await the write checkpoint before handing off queued work, so a cancellation can land between the write and the handoff. processQueuedMessages dequeued unconditionally and scheduled submitUserMessage, which rejects once abort is set - the queued message was consumed and dropped instead of being left for the resume/abort flow. The dequeue is now skipped while the task is aborted, guarding every handoff site at the lowest layer. Regression test pins that an aborted task leaves the queue intact (negative control verified: the unconditional dequeue reddens it). Review feedback on PR 1404 (Lifecycle Resource Cleanup row); ported to every unit of this series.
1 parent c6a23c5 commit 484d5cf

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

‎src/core/task/Task.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6310,6 +6310,14 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
63106310
* @param context - Context string for logging (e.g., the calling tool name)
63116311
*/
63126312
public processQueuedMessages(): void {
6313+
// An aborted task must not dequeue queued messages: submitUserMessage
6314+
// rejects once abort is set, so consuming the queue here would drop the
6315+
// message instead of leaving it for the resume/abort flow. Tools await
6316+
// checkpoint saves before handing off, so a cancellation can land between
6317+
// the write and this call.
6318+
if (this.abort) {
6319+
return
6320+
}
63136321
try {
63146322
if (!this.messageQueueService.isEmpty()) {
63156323
const queued = this.messageQueueService.dequeueMessage()

‎src/core/task/__tests__/Task.spec.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7119,6 +7119,34 @@ describe("Queued message processing after condense", () => {
71197119
expect(submitSpy).toHaveBeenCalledWith("queued text", ["img1.png"])
71207120
expect(task.messageQueueService.isEmpty()).toBe(true)
71217121
})
7122+
it("does not dequeue queued messages once the task is aborted", () => {
7123+
// Tools await the checkpoint before handing off queued work; a
7124+
// cancellation landing during that await must not consume the queued
7125+
// message: submitUserMessage rejects once abort is set, so dequeuing
7126+
// would drop the input instead of leaving it for the resume flow.
7127+
if (!TelemetryService.hasInstance()) {
7128+
TelemetryService.createInstance([])
7129+
}
7130+
const provider = createProvider()
7131+
const task = new Task({
7132+
provider,
7133+
apiConfiguration: apiConfig,
7134+
task: "initial task",
7135+
startTask: false,
7136+
})
7137+
const submitSpy = vi.spyOn(task, "submitUserMessage").mockResolvedValue(undefined)
7138+
7139+
task.messageQueueService.addMessage("queued text")
7140+
task.abort = true
7141+
try {
7142+
task.processQueuedMessages()
7143+
} finally {
7144+
task.abort = false
7145+
}
7146+
7147+
expect(submitSpy).not.toHaveBeenCalled()
7148+
expect(task.messageQueueService.isEmpty()).toBe(false)
7149+
})
71227150

71237151
it("does not cross-drain queues between separate tasks", async () => {
71247152
const providerA = createProvider()

‎webview-ui/src/components/settings/__tests__/SettingsView.spec.tsx‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,3 +1008,50 @@ describe("SettingsView - openAiStrictToolSchemas save round trip", () => {
10081008
expect(posted()?.apiConfiguration?.openAiStrictToolSchemas).toBeUndefined()
10091009
})
10101010
})
1011+
1012+
describe("SettingsView - per-write checkpoints save (B1)", () => {
1013+
beforeEach(() => {
1014+
vi.clearAllMocks()
1015+
})
1016+
1017+
it("saves the default-on payload when Save is clicked with the setting unset", () => {
1018+
// An unset setting shows (and saves) the shared default-on value:
1019+
// the cached state seeds DEFAULT_PER_WRITE_CHECKPOINTS, so the host
1020+
// receives an explicit boolean instead of an omitted key.
1021+
const { activateTab, getSettingsContent } = renderSettingsView()
1022+
activateTab("checkpoints")
1023+
1024+
const content = getSettingsContent()
1025+
const perWrite = within(content).getByRole("checkbox", { name: "settings:checkpoints.perWrite.label" })
1026+
expect(perWrite).toBeChecked()
1027+
// Toggle a sibling setting so Save is enabled without touching perWrite.
1028+
fireEvent.click(within(content).getByRole("checkbox", { name: "settings:checkpoints.enable.label" }))
1029+
fireEvent.click(screen.getByTestId("save-button"))
1030+
1031+
expect(vscode.postMessage).toHaveBeenCalledWith(
1032+
expect.objectContaining({
1033+
type: "updateSettings",
1034+
updatedSettings: expect.objectContaining({ perWriteCheckpoints: true }),
1035+
}),
1036+
)
1037+
})
1038+
1039+
it("saves an explicit false payload after unchecking and clicking Save", () => {
1040+
const { activateTab, getSettingsContent } = renderSettingsView({ perWriteCheckpoints: true })
1041+
activateTab("checkpoints")
1042+
1043+
const content = getSettingsContent()
1044+
const perWrite = within(content).getByRole("checkbox", { name: "settings:checkpoints.perWrite.label" })
1045+
expect(perWrite).toBeChecked()
1046+
fireEvent.click(perWrite)
1047+
expect(perWrite).not.toBeChecked()
1048+
fireEvent.click(screen.getByTestId("save-button"))
1049+
1050+
expect(vscode.postMessage).toHaveBeenCalledWith(
1051+
expect.objectContaining({
1052+
type: "updateSettings",
1053+
updatedSettings: expect.objectContaining({ perWriteCheckpoints: false }),
1054+
}),
1055+
)
1056+
})
1057+
})

0 commit comments

Comments
 (0)