Skip to content

fix(core): sanitize Mistral reasoning content - #3934

Closed
Jerry2003826 wants to merge 1 commit into
QwenLM:mainfrom
Jerry2003826:codex/fix-mistral-reasoning-content-sanitization
Closed

fix(core): sanitize Mistral reasoning content#3934
Jerry2003826 wants to merge 1 commit into
QwenLM:mainfrom
Jerry2003826:codex/fix-mistral-reasoning-content-sanitization

Conversation

@Jerry2003826

Copy link
Copy Markdown
Contributor

Fixes #3304

Summary

  • Add a Mistral OpenAI-compatible provider selected by the official Mistral host or Mistral model-name fallback.
  • Sanitize outbound Mistral chat requests by removing reasoning_content from assistant messages before the provider call.
  • Preserve shared chat history and the existing OpenAI-compatible request pipeline; the sanitization happens only in buildRequest().

Root Cause

When users switch from a reasoning model to Mistral in the same session, previous assistant turns can contain reasoning_content. Mistral's strict OpenAI-compatible API rejects that non-standard message field, while Qwen Code was forwarding the shared history unchanged.

Validation

  • npm run test --workspace=packages/core -- src/core/openaiContentGenerator/provider/mistral.test.ts -t reasoning_content
  • npm run test --workspace=packages/core -- src/core/openaiContentGenerator/provider/mistral.test.ts src/core/openaiContentGenerator/provider/deepseek.test.ts
  • npm run lint --workspace=packages/core
  • npm run typecheck --workspace=packages/core
  • npx prettier --check packages/core/src/core/openaiContentGenerator/provider/mistral.ts packages/core/src/core/openaiContentGenerator/provider/mistral.test.ts packages/core/src/core/openaiContentGenerator/provider/index.ts packages/core/src/core/openaiContentGenerator/index.ts

@wenshao wenshao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found. LGTM! ✅ — deepseek-v4-pro via Qwen Code /review

@Jerry2003826
Jerry2003826 marked this pull request as ready for review May 8, 2026 14:05

@tanzhenxin tanzhenxin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Thanks for the fix! Unfortunately #3882 landed a few hours before this and addresses the same issue (#3304) with the same approach — a dedicated Mistral provider that strips reasoning_content from outbound messages, detected by official base URL plus model-name fallback. The file layout, detection logic, and test shape are essentially identical.

Closing this in favor of the merged PR seems like the right call. Really appreciate the careful work here — the root-cause writeup and validation steps were great. Hope you'll take another swing at something else soon.

Verdict

COMMENT — duplicate of merged #3882; no action needed on this PR.

@tanzhenxin tanzhenxin closed this May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Switching models mid-session causes API failures.

3 participants