From 226469dab2717fe156b56d9ae00530c264b84ce3 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Thu, 15 Jan 2026 09:33:45 +0000 Subject: [PATCH] fix: add mergeToolResultText for Mistral/Devstral models in OpenRouter Fixes #10618 Extended model detection to include "devstral" models (mistralai/devstral-2512 contains "devstral" not "mistral") and added mergeToolResultText: true to prevent "Unexpected role user after role tool" errors. Root cause: Mistral/Devstral models enforce strict message ordering and reject a "user" role message immediately after a "tool" role message. --- src/api/providers/openrouter.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/api/providers/openrouter.ts b/src/api/providers/openrouter.ts index d435a05618e..d5278fe4de3 100644 --- a/src/api/providers/openrouter.ts +++ b/src/api/providers/openrouter.ts @@ -231,12 +231,15 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH // Convert Anthropic messages to OpenAI format. // Pass normalization function for Mistral compatibility (requires 9-char alphanumeric IDs) - const isMistral = modelId.toLowerCase().includes("mistral") + // Also detect Devstral models which are part of the Mistral family + const isMistralFamily = modelId.toLowerCase().includes("mistral") || modelId.toLowerCase().includes("devstral") let openAiMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [ { role: "system", content: systemPrompt }, ...convertToOpenAiMessages( messages, - isMistral ? { normalizeToolCallId: normalizeMistralToolCallId } : undefined, + isMistralFamily + ? { normalizeToolCallId: normalizeMistralToolCallId, mergeToolResultText: true } + : undefined, ), ]