Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
userContent: Anthropic.Messages.ContentBlockParam[]
includeFileDetails: boolean
retryAttempt?: number
userMessageWasRemoved?: boolean // Track if user message was removed due to empty response
}

const stack: StackItem[] = [{ userContent, includeFileDetails, retryAttempt: 0 }]
Expand Down Expand Up @@ -1867,8 +1868,14 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
// results.
const finalUserContent = [...parsedUserContent, { type: "text" as const, text: environmentDetails }]

await this.addToApiConversationHistory({ role: "user", content: finalUserContent })
TelemetryService.instance.captureConversationMessage(this.taskId, "user")
// Only add user message to conversation history if:
// 1. This is the first attempt (retryAttempt === 0), OR
// 2. The message was removed in a previous iteration (userMessageWasRemoved === true)
// This prevents consecutive user messages while allowing re-add when needed
if ((currentItem.retryAttempt ?? 0) === 0 || currentItem.userMessageWasRemoved) {
await this.addToApiConversationHistory({ role: "user", content: finalUserContent })
TelemetryService.instance.captureConversationMessage(this.taskId, "user")
}

// Since we sent off a placeholder api_req_started message to update the
// webview while waiting to actually start the API request (to load
Expand Down Expand Up @@ -2552,10 +2559,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
}

// Push the same content back onto the stack to retry, incrementing the retry attempt counter
// Mark that user message was removed so it gets re-added on retry
stack.push({
userContent: currentUserContent,
includeFileDetails: false,
retryAttempt: (currentItem.retryAttempt ?? 0) + 1,
userMessageWasRemoved: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auto-retry path correctly sets userMessageWasRemoved: true, but the manual retry path (lines 2583-2587) doesn't set this flag. When native protocol removes the user message at line 2536 and the user manually approves retry, the missing flag means the user message won't be re-added, causing the same consecutive user message validation error. The manual retry path should also set userMessageWasRemoved: true for consistency.

Fix it with Roo Code or mention @roomote and request a fix.

})

// Continue to retry the request
Expand Down
Loading