Skip to content

Conversation

@daniel-lxs
Copy link
Member

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

  • Streaming retries after tool use will no longer cause 400 errors
  • Conversation history remains valid across retry attempts

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Nov 13, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 13, 2025

Rooviewer Clock   See task on Roo Cloud

Re-review completed. The auto-retry path has been fixed, but manual retry has the same issue.

  • Manual retry after empty assistant response doesn't set userMessageWasRemoved flag, causing consecutive user messages
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 13, 2025
@daniel-lxs daniel-lxs force-pushed the fix/streaming-retry-consecutive-user-messages branch from 189f412 to 6f7ddee Compare November 13, 2025 22:28
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Nov 13, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 13, 2025
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.
@daniel-lxs daniel-lxs force-pushed the fix/streaming-retry-consecutive-user-messages branch from 6f7ddee to b9d1e28 Compare November 13, 2025 23:12
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.
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Nov 13, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Nov 13, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Nov 13, 2025
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.

@mrubens mrubens merged commit d139eff into main Nov 14, 2025
22 of 23 checks passed
@mrubens mrubens deleted the fix/streaming-retry-consecutive-user-messages branch November 14, 2025 03:31
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Nov 14, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants