Repository navigation
Conversation
Mistral reasoning models return `content` as typed `thinking`/`text` blocks. The native /v1/chat/completions lane relayed those arrays as-is, so OpenAI-compatible Chat clients that expect a string `delta.content` rejected the stream. For canonical key-auth Mistral, reuse the translated path's `chatContentEvents` converter: - streamed deltas split into one chunk per run in source order (thinking -> `reasoning_content`, text -> `content`); `role` leads, the last chunk keeps the other delta fields, `finish_reason`, `usage` - buffered `message.content` joins text into `content` (null when empty) and thinking into `reasoning_content`, which also feeds synthesized SSE - unsupported blocks fail closed with a 502 Reasoning replay capture keeps reading the raw upstream chunk, so request history sent back to Mistral is unchanged. Other destinations and plain string content pass through unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Contributor
|
✅ Deterministic PR hygiene checks passed. |
Contributor
⏳ DRAFT
What to do
Review readiness checklist
0/4 boxes ticked. This PR stays in draft until every box above is ticked. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #8251.
On native
/v1/chat/completionspassthrough, Mistral reasoning models returncontentas typedthinking/textblocks. The native Chat lane relayed those arrays unchanged, so OpenAI-compatible Chat clients that expect a stringdelta.contentrejected the stream. OpenCode, for example, fails withInvalid ... stream event. The translated path already converts these blocks withchatContentEvents. This PR reuses that converter on the native lane, for canonical key-auth Mistral only (isCanonicalMistralChat).src/server/chat-native-sse.ts): a typed delta becomes one chunk per run, in source order. Thinking goes toreasoning_contentand text tocontent.rolerides the first chunk. The last chunk keeps the other delta fields,finish_reasonandusage, and every emitted choice carries itsindex. Stall, first-output and EOF-recovery tracking now see the converted text, so a typed-only stream cut before its terminal frame recovers with[DONE]and no longer ends asupstream_sse_truncated.src/server/chat-native.ts): a typedmessage.contentjoins its text intocontent(nullwhen there is none, matching the streamed collector) and its thinking intoreasoning_content. This also feeds the synthesized SSE for streaming clients when the upstream answers with JSON.reasoning_contentinto history, which is not the thinking-chunk format the translated path sends back to Mistral, so request history is deliberately unchanged here.Docs:
docs-site/.../reference/adapters.mdandstructure/providers/chat-compat.md.Verification
All runs were local on Linux, at commit
99cd96e2rebased ondev7ea41c36, with Bun 1.4.4 from the repo's pinned dependency afterbun install --frozen-lockfile.bun test tests/responses/chat-native-mistral-content.test.ts: 9 pass, 0 fail.dev(7ea41c36): 8 fail, 1 pass. The pass is the "other destinations unchanged" control, as intended.bun run typecheck: no type errors (2,322 files).bun run structure:check: passed.bun run privacy:scan: passed.bun test tests/ci-workflows/file-size-ratchet.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts: all pass.layout-chat.json, becauselayout.jsonsits at its 2,000-line cap.bun run test(full suite,--parallel=4, 895 s, every file ran): 61,445 pass, 712 skip, 6 fail. All 6 failures are pre-existing and unrelated:tests/codex-integration/codex-cli-update-apply.test.ts: 3 failtests/codex-integration/codex-composed-acceptance.test.ts: 1 failtests/codex-integration/codex-config-write-lock.test.ts: 2 faildev7ea41c36in this environment.Not covered:
reasoning_content, and some echo it back on assistant messages. Native passthrough forwards those messages unchanged; this PR does not alter that, and I have not verified how Mistral treats that field.Checklist
🤖 Generated with Claude Code
Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
Required local validation passed; commands, results, and any full-suite exception are documented.
I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.