fix: add mergeToolResultText for Mistral/Devstral models on OpenRouter#11643
Draft
roomote[bot] wants to merge 1 commit intomainfrom
Draft
fix: add mergeToolResultText for Mistral/Devstral models on OpenRouter#11643roomote[bot] wants to merge 1 commit intomainfrom
roomote[bot] wants to merge 1 commit intomainfrom
Conversation
Fixes the "Unexpected role user after role tool" and empty response errors for mistralai/devstral-2512 on OpenRouter by: 1. Extending model detection to also match "devstral" in the model ID 2. Adding mergeToolResultText: true so text content after tool results is merged into the last tool message instead of creating a separate user message Closes #10618
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #10618
Description
This PR attempts to address Issue #10618 where
mistralai/devstral-2512on OpenRouter produces errors like "Unexpected role user after role tool" or "The language model did not provide any assistant messages."Root cause: Mistral/Devstral models enforce strict message ordering and reject a
userrole message directly after atoolrole message. The current code normalizes tool call IDs for Mistral models but does not merge text content that follows tool results into the tool message, causing an invalidtool->usermessage sequence.Changes:
devstralin the model ID (for robustness, even thoughmistralai/devstral-2512already matches viamistralai)mergeToolResultText: trueto the Mistral options passed toconvertToOpenAiMessages(), which merges text content after tool results into the last tool message instead of creating a separate user messageThis uses the same
mergeToolResultTextmechanism already available in the codebase and tested inopenai-format.spec.ts.Feedback and guidance are welcome.
Test Procedure
openrouter.spec.tsunder "Mistral/Devstral message formatting":Run tests:
cd src && npx vitest run api/providers/__tests__/openrouter.spec.tsPre-Submission Checklist
Documentation Updates
Additional Notes
Previous PRs #10630 and #10751 addressed the same issue but were never merged. This PR incorporates the same fix on the current main branch.
Start a new Roo Code Cloud session on this branch