-
Couldn't load subscription status.
- Fork 2.3k
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
Conversation
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.
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.
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.