-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix message queue re-queue loop in Task.ask() #7823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When the queue had messages during an ask operation, Task.ask() would call submitUserMessage() which posts an 'invoke: sendMessage' to the webview. However, since sendingDisabled is true during ask operations, the webview would re-queue the message, creating an infinite loop. Fixed by directly calling setMessageResponse() when processing queued messages, bypassing the webview round-trip and immediately satisfying the pending ask operation.
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! I've reviewed the changes and the fix looks good overall. The solution correctly addresses the infinite re-queue loop by bypassing the webview's disabled guard. I've left some suggestions inline to help improve test coverage and documentation.
When a file is edited using tools (write_to_file, apply_diff, insert_content, search_and_replace), any user messages that were queued during the edit operation were not being sent afterwards. This fix ensures that after each file edit tool completes, it checks the message queue and processes one queued message if present. The fix prevents messages from getting stuck in the queue after file edits, ensuring a smooth user experience when typing while the assistant is performing file operations.
- Added processQueuedMessages() method to Task class for centralized queue handling - Integrated queue processing in all file editing tools: - writeToFileTool: processes queue after completion - applyDiffTool: processes queue after completion, rejection, or error - insertContentTool: processes queue after completion - searchAndReplaceTool: processes queue after completion - multiApplyDiffTool: processes queue after completion or error - Ensures user messages typed during file edits are sent immediately after edit completes - Prevents messages from getting stuck in the queue
When messages are queued while a tool is waiting for approval, they now properly handle the approval before sending. This prevents tools from being rejected when processing queued messages.
- Modified Task.ts to check if the ask type requires approval (tool, command, browser_action_launch, use_mcp_server)
- For approval-required asks, use handleWebviewAskResponse('yesButtonClicked') instead of setMessageResponse()
- For other ask types like followup, continue using setMessageResponse() as before
This ensures the correct order: approve tools first, then send messages.
cte
approved these changes
Sep 12, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
lgtm
This PR has been approved by a maintainer
PR - Needs Review
size:M
This PR changes 30-99 lines, ignoring generated files.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a regression where messages in the queue would fail to send during an ask operation, getting stuck in an infinite re-queue loop.
Problem
When
Task.ask()had queued messages to process, it would:submitUserMessage()which posts an 'invoke: sendMessage' to the webviewsendingDisabled=trueduring ask operations, would re-queue the messageSolution
Replace the webview round-trip with a direct call to
setMessageResponse()when processing queued messages. This:handleWebviewAskResponseChanges
Task.ask()to usesetMessageResponse()instead ofsubmitUserMessage()when processing queued messagesTesting
The existing tests should verify that:
Important
Fixes infinite re-queue loop in
Task.ask()by directly processing queued messages, ensuring proper message handling after file edits.Task.ask()by replacingsubmitUserMessage()withsetMessageResponse()for queued messages inTask.ts.applyDiffTool.ts,insertContentTool.ts, andwriteToFileTool.ts.applyDiffTool.experiment.spec.tsandmultiApplyDiffTool.spec.tsto mockprocessQueuedMessages()and verify message processing behavior.processQueuedMessages()call inapplyDiffTool.ts,insertContentTool.ts,multiApplyDiffTool.ts,searchAndReplaceTool.ts, andwriteToFileTool.tsafter file operations.This description was created by
for 400f26e. You can customize this summary. It will automatically update as commits are pushed.