Repository navigation
fix(openai-chat): preserve native Mistral thinking on replay - #7814
Conversation
* Replay historical thinking as native content chunks for Mistral-hosted GLM, Small and Large, while honoring explicit opt-outs. * Keep scoped tool recovery, other destinations and native passthrough unchanged; never invent thinking placeholders or signatures. * Add two-turn regression coverage and document the text-only replay contract.
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
Mistral target and replay policy src/adapters/openai-chat/wire.ts, src/adapters/openai-chat/messages.ts, docs-site/src/content/docs/reference/configuration/providers.md |
The adapter identifies api.mistral.ai by hostname. When no explicit preserveReasoningContentModels list is set, Mistral targets preserve supplied reasoning by default. The provider documentation describes this policy. |
Native thinking serialization and validation src/adapters/openai-chat/messages.ts, structure/providers/chat-compat.md, tests/adapters/openai/openai-chat-mistral-content.test.ts |
Replayed reasoning is serialized as Mistral thinking content, followed by assistant text when present. Mistral serialization does not add placeholder reasoning when reasoning is absent. Tests cover response modes, opt-outs, and scoped cache recovery. The compatibility documentation describes the reconstructed content and its limits. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant ChatHistory
participant MessageSerializer
participant ReplayCache
participant MistralChatAPI
ChatHistory->>MessageSerializer: translated assistant history
MessageSerializer->>ReplayCache: look up scoped tool-call reasoning when needed
ReplayCache-->>MessageSerializer: cached reasoning text when scope matches
MessageSerializer->>MistralChatAPI: thinking content followed by assistant text
Suggested reviewers: lidge-j
Merge Risk: 
Minimal · previous review 84140
-
Mistral thinking is replayed as text-only chunks; no actionable merge-blocking defect was established.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 3 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment @coderabbitai help to get the list of available commands.
|
✅ Deterministic PR hygiene checks passed. |
✅ READY
Review readiness checklist
✅ 4/4 boxes ticked. This pull request has been marked Ready for Review. Hygiene✅ Deterministic PR hygiene checks passed. |
|
@coderabbitai full review |
✅ Action performed
|
|
Maintainer dev integration decision (per MAINTAINERS.md).
The readiness checklist was reset by the maintainer's branch update, so the maintainer marks this ready for integration. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Summary
Mistral's thinking can appear in Codex on the first turn but disappear from the next model request. The response parser and Responses replay keep the thinking text; the Chat serializer omits it. Adding
preserveReasoningContentModelsalone sendsreasoning_content, rather than Mistral's native thinking chunks.Replay the prior thinking as native
contentchunks before assistant text forapi.mistral.ai. This applies to hosted GLM and reasoning-enabled Mistral Small, Medium and Large. Explicit preserve lists, including[], retain control.For example, the second request follows a thinking response and a tool result:
{"role":"assistant","content":[{"type":"thinking","thinking":[{"type":"text","text":"Synthetic prior thinking."}]},{"type":"text","text":"Checking."}],"tool_calls":[{"id":"call_read","type":"function","function":{"name":"read_file","arguments":"{}"}}]}Use actual text from the existing scoped replay cache when needed, without inventing placeholders or signatures. The shared prompt projection counts the replayed thinking. Other destinations and native Chat passthrough keep their existing behavior.
This follows #7047's response-parsing fix. Mistral's multi-turn guidance calls for replaying assistant thinking chunks. The fix reconstructs thinking text; it does not restore original chunk boundaries or native signature/closed metadata, which the current parser does not retain.
Verification
Bun 1.4.4, Linux. Base:
736fa5087c0b807cc2c7fd54ebae1548e6b2d4cb(dev, 2.94.0). Published commit:8414064de8c81dd1922a66eecaeb25e5a7de6262. The branch is two commits behind the publication-timedevtip,f94e95ce5.bun scripts/test.ts --changed=736fa5087c0b807cc2c7fd54ebae1548e6b2d4cb --parallel=1 tests/adapters/openai/ tests/adapters/translator-budget.test.ts tests/adapters/translator-budget-lifetime.test.ts tests/providers/deepseek-reasoning-replay.test.ts tests/providers/zai-reasoning-replay.test.ts tests/responses/chat-native-reasoning-replay.test.ts: 950 pass across 38 files. The run usedupstream/devwhile it pointed to the exact base shown here.bun scripts/test.ts --parallel=1 tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/structure-ssot.test.ts tests/ci-workflows/repo-hygiene.test.ts tests/ci-workflows/file-size-ratchet.test.ts: 105 pass across five files. These explicit checks include source-as-data guards outside the import graph.bun run typecheck,bun run privacy:scan,bun run structure:check, andgit diff --check: pass on the published source.cd docs-site && bun run build: pass with the locked dependencies; 593 pages and 85,001 internal links checked.All upstream replies are synthetic. Used focused and import-graph checks to limit local resource use alongside other workstation work; the full suite, cross-platform CI, live model acceptance and external review remain pending. This does not establish a model-quality improvement or a fix for retry loops. Keep the PR in draft until review is complete.
Checklist
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.
Summary by CodeRabbit