From 8ad040ec4c72d6d4db91c200287ef1164f925c6b Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sun, 30 Nov 2025 10:54:25 +0000 Subject: [PATCH] fix: prevent AI from getting stuck when assistantMessageContent is empty - Add early check for empty content when streaming is complete - Ensure userMessageContentReady is set even with no content - Add additional safety check for edge cases - Improve handling of partial blocks with pending updates Fixes #9702 --- .../presentAssistantMessage.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/core/assistant-message/presentAssistantMessage.ts b/src/core/assistant-message/presentAssistantMessage.ts index 519a1dc0fa..4f09501a07 100644 --- a/src/core/assistant-message/presentAssistantMessage.ts +++ b/src/core/assistant-message/presentAssistantMessage.ts @@ -73,6 +73,14 @@ export async function presentAssistantMessage(cline: Task) { cline.presentAssistantMessageLocked = true cline.presentAssistantMessageHasPendingUpdates = false + // Handle empty content case immediately + if (cline.assistantMessageContent.length === 0 && cline.didCompleteReadingStream) { + // If there's no content and streaming is complete, mark as ready + cline.userMessageContentReady = true + cline.presentAssistantMessageLocked = false + return + } + if (cline.currentStreamingContentIndex >= cline.assistantMessageContent.length) { // This may happen if the last content block was completed before // streaming could finish. If streaming is finished, and we're out of @@ -1064,11 +1072,19 @@ export async function presentAssistantMessage(cline: Task) { cline.userMessageContentReady = true } } + } else if (block.partial && cline.presentAssistantMessageHasPendingUpdates) { + // Block is partial, but the read stream may have finished or has pending updates + presentAssistantMessage(cline) } - // Block is partial, but the read stream may have finished. - if (cline.presentAssistantMessageHasPendingUpdates) { - presentAssistantMessage(cline) + // Additional safety check: If streaming is complete but we haven't set userMessageContentReady yet + // This can happen if the last block was partial and didn't trigger the normal completion flow + if ( + cline.didCompleteReadingStream && + !cline.userMessageContentReady && + cline.assistantMessageContent.length === 0 + ) { + cline.userMessageContentReady = true } }