Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit c6b866c

Browse files
committed
fix: queue messages when ask is superseded during command_output
When a user sends a message during command_output (e.g., while a command like `sleep 10` is running), a race condition can occur where the command completes and updates lastMessageTs just as the user response arrives. This causes the ask to throw AskIgnoredError("superseded") and the user message is silently discarded. This fix captures the pending response content (text and images) before throwing AskIgnoredError and queues it via messageQueueService so the message can be processed when the next ask is ready. This ensures user messages are never lost during rapid state transitions. Fixes EXT-674
1 parent fe722da commit c6b866c

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/core/task/Task.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,25 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
14731473
// Could happen if we send multiple asks in a row i.e. with
14741474
// command_output. It's important that when we know an ask could
14751475
// fail, it is handled gracefully.
1476+
//
1477+
// If there's a pending response with user content, queue it so the
1478+
// message isn't lost. This handles the race condition where a user
1479+
// sends a message during command_output but the command completes
1480+
// at nearly the same time (causing say("command_output") to update
1481+
// lastMessageTs before we can return the response).
1482+
//
1483+
// Use type assertions to break TypeScript's control flow narrowing
1484+
// from the pWaitFor callback, which incorrectly narrows these
1485+
// properties to 'never' in this branch.
1486+
const pendingText = this.askResponseText as string | undefined
1487+
const pendingImages = this.askResponseImages as string[] | undefined
1488+
if (this.askResponse === "messageResponse" && (pendingText?.trim() || pendingImages?.length)) {
1489+
this.messageQueueService.addMessage(pendingText || "", pendingImages)
1490+
}
1491+
// Clear response fields to prevent stale data affecting subsequent asks
1492+
this.askResponse = undefined
1493+
this.askResponseText = undefined
1494+
this.askResponseImages = undefined
14761495
throw new AskIgnoredError("superseded")
14771496
}
14781497

0 commit comments

Comments
 (0)