mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
fix: prevent consecutive user messages on streaming retry (#9249)
This commit is contained in:
parent
38e3529c1e
commit
d139eff9fc
1 changed files with 11 additions and 2 deletions
|
|
@ -1768,6 +1768,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 }]
|
||||
|
|
@ -1868,8 +1869,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
|
||||
|
|
@ -2553,10 +2560,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,
|
||||
})
|
||||
|
||||
// Continue to retry the request
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue