DeepSeek's Chat API in thinking mode refuses a whole request with 400
"The `reasoning_content` in the thinking mode must be passed back to the
API" when an assistant tool-call message since the user's last message
comes back without reasoning_content. OpenCode (and any client that
continues a turn another model made, or that dropped the thinking) sends
such turns, and magpie relayed them as they came.
What changed:
- chatReplaysReasoning(host, model) names the Chat upstreams that want
reasoning back: a DeepSeek host, a model named deepseek wherever it is
served (OpenCode Go's deepseek-v4.1-flash, OpenRouter), and Command
Code's plugin. buildChat uses it as before.
- Passthrough (gateway.go, provider.Chat): for such an upstream, not
Mistral (#494), withReasoningOnToolTurns gives every assistant
tool-call message without reasoning_content one: its thinking from
another field (reasoning, OpenRouter's) when it has some, else " ".
The gate takes the member's model, so a group reaching a DeepSeek
member is covered.
- Translated (buildChat, Responses/Anthropic -> Chat): a tool-call turn
with no thinking gets " " too.
- Every tool turn, not only the last: DeepSeek also refuses an earlier
tool turn of the current user turn missing it.
- " ", not "": DeepSeek's Chat takes "", but relays that omit empty
fields drop it, and DeepSeek's Responses API refuses an empty
reasoning_text. A vendor that refuses the field still gets the #494
retry without it.
Checked against api.deepseek.com (owner's key, deepseek-flash, Chat):
last tool turn missing -> 400; "" -> 200; " " -> 200; real -> 200; an
earlier tool turn of the current user turn missing -> 400; a tool turn
before the latest user message missing -> 200; answers missing -> 200.
Not changed, found on the way: DeepSeek's Responses API refuses a
function_call with no reasoning item (and empty reasoning_text), and its
Anthropic API a tool_use with no thinking block; magpie relays those
natively as they come. OpenCode Go's deepseek-v4.1-flash could not be
tried for real: the owner's workspace answers "requires Global regions".
Run:
- New tests fail on the old code (TestChatToolTurnWithoutReasoningRelayed:
400 "reasoning_content ... must be passed back"; TestTranslatedToolTurn
WithoutReasoning: 400), pass now; TestChatToolTurnWithoutReasoning
NotForMistral and the Mistral/MessageReasoning tests pass.
- gofmt -l clean; go vet -tags nogui ./internal/gateway on darwin,
GOOS=linux, GOOS=windows.
- go test -tags nogui -count=1 ./... under a temp HOME: all ok.
- Real use: the built binary's gateway in a sandbox HOME with only the
DeepSeek provider. Old: last tool turn missing 400, earlier one
missing (stream) 400, plain answer 200. New: all three 200.