Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 14, 2026

Related GitHub Issue

Closes: #10684

Related: #10618, #10540, #10695 (same root cause, different providers/approaches)

Description

This PR attempts to address Issue #10684 based on feedback from @maksir suggesting we should check the model family before applying the mergeToolResultText fix to avoid affecting other models.

Changes:

  • Added isMistralFamily check that detects Mistral/Devstral models by checking if the model ID contains "mistral" or "devstral" (case-insensitive)
  • Pass { mergeToolResultText: true } to convertToOpenAiMessages() only when isMistralFamily is true
  • Updated all 4 convertToOpenAiMessages() calls in the OpenAI provider (both streaming and non-streaming modes, including O3 family handlers)

This follows the same pattern as PR #10630 which implements the model family check for OpenRouter.

Root Cause:
Mistral/Devstral models enforce strict message ordering and reject a "user" role message immediately after a "tool" role message. The mergeToolResultText option merges text content into the last tool message instead of creating a separate user message.

Test Procedure

  1. Configure OpenAI provider with a local vLLM/llama.cpp/Ollama server serving a Mistral/Devstral model
  2. Start a task that uses tools
  3. Verify that tool calls complete without the "Unexpected role user after role tool" error
  4. Test with non-Mistral models to verify normal behavior is preserved

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: All existing tests pass. The underlying mergeToolResultText functionality is tested in openai-format.spec.ts.
  • 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 approach is more conservative than PR #10695 which applies mergeToolResultText: true to all models. By checking the model family first, we avoid any potential side effects on models that do not require this fix.

Feedback and guidance are welcome!


Important

Adds isMistralFamily check in OpenAiHandler to conditionally apply mergeToolResultText for Mistral/Devstral models, ensuring correct message ordering.

  • Behavior:
    • Adds isMistralFamily check in OpenAiHandler to identify Mistral/Devstral models by checking modelId for "mistral" or "devstral".
    • Applies { mergeToolResultText: true } in convertToOpenAiMessages() only if isMistralFamily is true.
    • Updates all 4 convertToOpenAiMessages() calls in OpenAiHandler for both streaming and non-streaming modes.
  • Root Cause:
    • Mistral/Devstral models require strict message ordering, rejecting a "user" role message immediately after a "tool" role message.
  • Testing:
    • Ensure no "Unexpected role user after role tool" error with Mistral/Devstral models.
    • Verify normal behavior with non-Mistral models.

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

@roomote
Copy link
Contributor Author

roomote bot commented Jan 14, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly adds isMistralFamily detection and conditionally applies mergeToolResultText: true for Mistral/Devstral models, which prevents the "Unexpected role 'user' after role 'tool'" error. The fix is applied to all 4 convertToOpenAiMessages() calls and follows the established pattern from other providers.

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

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Local vllm devstral2 -> OpenAI completion error

2 participants