@@ -845,9 +845,19 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
845845 const message = this . messageQueueService . dequeueMessage ( )
846846
847847 if ( message ) {
848- setTimeout ( async ( ) => {
849- await this . submitUserMessage ( message . text , message . images )
850- } , 0 )
848+ // Check if this is a tool approval ask that needs to be handled
849+ if (
850+ type === "tool" ||
851+ type === "command" ||
852+ type === "browser_action_launch" ||
853+ type === "use_mcp_server"
854+ ) {
855+ // For tool approvals, we need to approve first, then send the message if there's text/images
856+ this . handleWebviewAskResponse ( "yesButtonClicked" , message . text , message . images )
857+ } else {
858+ // For other ask types (like followup), fulfill the ask directly
859+ this . setMessageResponse ( message . text , message . images )
860+ }
851861 }
852862 }
853863
@@ -2898,4 +2908,28 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
28982908 public get cwd ( ) {
28992909 return this . workspacePath
29002910 }
2911+
2912+ /**
2913+ * Process any queued messages by dequeuing and submitting them.
2914+ * This ensures that queued user messages are sent when appropriate,
2915+ * preventing them from getting stuck in the queue.
2916+ *
2917+ * @param context - Context string for logging (e.g., the calling tool name)
2918+ */
2919+ public processQueuedMessages ( ) : void {
2920+ try {
2921+ if ( ! this . messageQueueService . isEmpty ( ) ) {
2922+ const queued = this . messageQueueService . dequeueMessage ( )
2923+ if ( queued ) {
2924+ setTimeout ( ( ) => {
2925+ this . submitUserMessage ( queued . text , queued . images ) . catch ( ( err ) =>
2926+ console . error ( `[Task] Failed to submit queued message:` , err ) ,
2927+ )
2928+ } , 0 )
2929+ }
2930+ }
2931+ } catch ( e ) {
2932+ console . error ( `[Task] Queue processing error:` , e )
2933+ }
2934+ }
29012935}
0 commit comments