Codex on /v1/responses with a DeepSeek-named model served at Mistral
(preset mistral or api.mistral.ai, here deepseek-v4-1-flash-1017) broke
after its first tool call: the Chat build replays an earlier turn's
thinking in reasoning_content for any model whose name says DeepSeek,
wherever it is served (chatReplaysReasoning keys on the name), and
Mistral answers that field with 422 extra_forbidden. The #494 fix
converted it to Mistral's typed thinking part (mistralThinking) only on
the Chat passthrough route, so /v1/chat/completions on the same provider
answered 200 while every follow-up on /v1/responses was refused.
forwardTranslated now runs mistralThinking on the body built for a
Mistral upstream, with the same gate the relayed route uses. Other
upstreams keep the #1462 replay (a DeepSeek at DeepSeek still gets
reasoning_content), and the relayed route is unchanged.
MystryMocha's nit: a whitespace-only thinking (the " " placeholder the
replay gives a tool turn with no reasoning item) is now dropped instead
of being sent as a blank thinking part. This applies to the relayed
route too; Mistral accepts the dropped field (MystryMocha's raw table).
Ported from skygunner's 29b0ea308 (branch
fix/4906-mistral-translated-reasoning), on origin/main 1c45645b5.
Edward4226's 0b8aee26f was an independent fix of the same shape.
Run (all through mote-run, at this tree):
- gofmt -l internal/gateway docs: empty
- go test -tags nogui ./internal/gateway -count=1 -timeout 45m: ok (894.9s)
- GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...,
go vet ./..., go build: ok
Run at this change on 1c45645b5, then rebased onto 3f53fa1f3; the
two commits between (763ea9438, 3f53fa1f3) touch GUI CSS, webfonts.js
and GUI tests only, nothing Go.
Broken by hand:
- forwardTranslated's mistralThinking call taken out:
TestTranslatedReasoningAsThinkingForMistral red with the reporter's
422 at messages[1].assistant.reasoning_content ("I should read
note.txt with the tool."), and the new
TestTranslatedToolTurnWithoutReasoningForMistral red with the same
422 on the " " placeholder.
- TrimSpace reverted to think == "": only
TestTranslatedToolTurnWithoutReasoningForMistral red ("the call was
given a blank thinking part").
Real use: not tried here, no Mistral key. MystryMocha ran skygunner's
29b0ea308 on main a92cc3f3 (Windows/amd64) against the real Mistral API
and in real Codex Desktop on mistral/deepseek-v4-1-flash-1017: a
12-minute session of many tool calls with no 422, and turn 2 and a tool
turn without a reasoning item 422 on main, 200 with the fix. The
TrimSpace change on top of it was not run against the real API; per the
same report, Mistral answers 200 with the field dropped.
Co-authored-by: skygunner <84759+skygunner@users.noreply.github.com>