fix(opencode): resolve Mistral tool→user message ordering error #7490
+292
−4
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.
Issue
Fixes #7488
Problem
When using Mistral or Devstral models with tool calls (especially via vLLM or openai-compatible endpoints), requests fail with:
I guess this occurs because Mistral enforces strict message ordering: a tool message must be followed by an assistant message before any user message.
I then looked in the code and saw the transform logic to fix message ordering already existed in
transform.ts, but it never ran because the middleware inllm.tsline 187 was transforming the wrong parameter (args.params.promptinstead ofargs.params.messages) (im TS noob so please help me out here if wrong).The changes I did:
src/session/llm.ts: Changed transform to targetargs.params.messagesinstead ofpromptsrc/provider/transform.ts): Now detects Mistral variants including:model.idandmodel.api.idtest/provider/transform.test.ts): 6 newThe flow should now be from
user→assistant(tool_calls) →tool→usertouser→assistant(tool_calls) →tool→assistant("Done.") →userI hope this meets your standards. :)