Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 12, 2026

Related GitHub Issue

Closes: #10618

Related: #10540 (same root cause, different provider)

Description

This PR attempts to address Issue #10618. Feedback and guidance are welcome.

Root Cause:
The error "Unexpected role 'user' after role 'tool'" occurs because Mistral/Devstral models have strict message ordering requirements. After a tool role message, the next message cannot be a user role message.

Solution:

  1. Extended model detection to include "devstral" (the model mistralai/devstral-2512 contains "devstral" not "mistral")
  2. Added mergeToolResultText: true to the conversion options, which merges text content (like environment_details) into the last tool message instead of creating a separate user message

This uses the same mergeToolResultText mechanism that PR #10598 exposes as a setting for OpenAI Compatible providers, but applies it automatically for Mistral family models in OpenRouter since we can detect them by model ID.

Test Procedure

  1. Configure OpenRouter with a Mistral/Devstral model (e.g., mistralai/devstral-2512)
  2. Start a task that uses tools
  3. Verify that tool calls complete without the "Unexpected role user after role tool" error
  4. The existing mergeToolResultText tests in openai-format.spec.ts cover the underlying functionality

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: The underlying mergeToolResultText functionality is already tested.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

This is a minimal fix that leverages existing infrastructure. The mergeToolResultText option was added in a previous PR and is already used by DeepSeek, Z.ai, and MiniMax providers for similar message ordering issues.


Important

Extends model detection and uses mergeToolResultText for Mistral/Devstral models in OpenRouterHandler to fix message ordering errors.

This description was created by Ellipsis for ce38fd4. You can customize this summary. It will automatically update as commits are pushed.

Fixes the "Unexpected role user after role tool" error for Mistral and
Devstral models when using OpenRouter.

Changes:
- Extended model detection to include "devstral" (e.g. mistralai/devstral-2512)
- Added mergeToolResultText: true to merge text content into tool messages
  instead of creating a separate user message that violates Mistral ordering

Closes #10618
@roomote
Copy link
Contributor Author

roomote bot commented Jan 12, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The change correctly extends Mistral model detection to include Devstral models and adds mergeToolResultText: true to prevent the "Unexpected role 'user' after role 'tool'" error. The fix leverages existing tested infrastructure.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] openrouter:mistralai/devstral-2512 -> "completion error"

3 participants