Skip to content

Commit 41eb35a

Browse files
committed
fix(provider): preserve reasoning_content on second interleaved pass
When the interleaved transform runs on subsequent requests (after DB round-trip), content parts no longer contain reasoning blocks (they were extracted on the first pass). The unconditional [field]: reasoningText overwrites the previously correct providerOptions.reasoning_content with empty string, causing DeepSeek 400: 'The reasoning_content in the thinking mode must be passed back to the API.' Fix: set [field]: reasoningText first, then spread existing providerOptions so that preserved values from DB take priority over empty reasoningText. Closes #24442 (co-discovered with @claudianus)
1 parent a4373c8 commit 41eb35a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

packages/opencode/src/provider/transform.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,18 @@ function normalizeMessages(
208208
// Include reasoning_content | reasoning_details directly on the message for all assistant messages.
209209
// Always set the field even when empty — some providers (e.g. DeepSeek) may return empty
210210
// reasoning_content which still needs to be sent back in subsequent requests.
211+
// Preserve existing providerOptions[field] when content no longer has reasoning
212+
// parts (e.g. after a prior transform pass already extracted them). The first
213+
// pass sets the field from reasoning parts; on subsequent passes reasoningText
214+
// is empty and must not overwrite the preserved value from DB.
211215
return {
212216
...msg,
213217
content: filteredContent,
214218
providerOptions: {
215219
...msg.providerOptions,
216220
[sdk]: {
217-
...msg.providerOptions?.[sdk],
218221
[field]: reasoningText,
222+
...msg.providerOptions?.[sdk],
219223
},
220224
},
221225
}

0 commit comments

Comments
 (0)