fix(opencode): Error 400 missing reasoning_content – transform reasoning according to DeepSeek API and aditional test cases#17529
Open
dixoxib wants to merge 6 commits intoanomalyco:devfrom
Open
fix(opencode): Error 400 missing reasoning_content – transform reasoning according to DeepSeek API and aditional test cases#17529dixoxib wants to merge 6 commits intoanomalyco:devfrom
dixoxib wants to merge 6 commits intoanomalyco:devfrom
Conversation
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
- Set empty reasoning_content for assistant messages after last user message - Only apply when thinking mode is enabled (reasoner model or thinking option) - Add comprehensive tests for all thinking mode conditions
This was referenced Mar 15, 2026
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.
Issue for this PR
Closes #17523, #9397, #8934, #5577
Type of change
What does this PR do?
reasoning_contentfield when thinking mode is enabled.Problem: When using DeepSeek models with thinking mode (via reasoner model IDs or thinking option), assistant messages after the last user message were missing the
reasoning_contentfield. The DeepSeek API expects this field to be present (even if empty) for proper thinking mode operation in multi-turn conversations. The official DeepSeek API only utilizes current turn reasoning, no need for previous reasoning to be provided.Changes made:
Modified
packages/opencode/src/provider/transform.tsto:capabilities.reasoning, model ID containing "deepseek-reasoner", orthinking: { type: "enabled" }option)reasoning_contentfor all assistant messages after that index when thinking mode is activeAdded tests in
packages/opencode/test/provider/transform.test.tscovering:Why it works: The DeepSeek API documentation indicates that thinking mode requires the
reasoning_contentfield to be present on assistant messages. By setting it to an empty string for assistant messages after the last user message, we comply with API expectations while maintaining backward compatibility for non-thinking mode usage.How did you verify your code works?
bun testpassesScreenshots / recordings
N/A - This is a backend fix with no UI changes.
Checklist
If you do not follow this template your PR will be automatically rejected.