-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: prevent consecutive user messages on streaming retry #9249
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
Re-review completed. The auto-retry path has been fixed, but manual retry has the same issue.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
189f412 to
6f7ddee
Compare
When a streaming error occurs after a tool use, the retry logic was adding a duplicate user message to the API conversation history, causing 400 errors. The fix skips adding the user message on retry attempts since it was already added in the first attempt.
6f7ddee to
b9d1e28
Compare
The previous fix prevented adding user messages on retry attempts to avoid consecutive user messages. However, when the assistant returns an empty response, the user message is removed from conversation history (line 2534). On retry, the fix would skip re-adding the message, leaving the conversation incomplete. Solution: Track when the user message was removed and re-add it on retry only in that specific case, while still preventing duplicate messages in normal mid-stream retry scenarios.
| userContent: currentUserContent, | ||
| includeFileDetails: false, | ||
| retryAttempt: (currentItem.retryAttempt ?? 0) + 1, | ||
| userMessageWasRemoved: true, |
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.
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.
Fixes the 400 error that occurs when a streaming error happens after a tool use.
Problem
When a stream fails mid-execution (e.g., after a tool use), the retry logic was adding a duplicate user message to the API conversation history, causing consecutive user messages which violate API validation rules.
Solution
Skip adding the user message to conversation history on retry attempts (retryAttempt > 0) since it was already added in the first attempt.
Impact