fix: ensure reasoning_content is always present for DeepSeek thinking mode #10178
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.
Related GitHub Issue
Closes: #10175
Description
This PR attempts to address Issue #10175 where DeepSeek V3.2 API returns a 400 error after context condense.
Root Cause: DeepSeek's reasoner model (
deepseek-reasoner) requires ALL assistant messages to have areasoning_contentfield when using thinking mode. When context is condensed, the summary message is created without this field, causing the API to reject the request.Fix: Modified
src/api/transform/r1-format.tsto ensure that when converting messages for DeepSeek's thinking mode (indicated bymergeToolResultText: true), ALL assistant messages include thereasoning_contentfield, even if empty.Changes made:
reasoning_content(empty string if none) whenmergeToolResultTextis trueTest Procedure
Added 4 new unit tests in
src/api/transform/__tests__/r1-format.spec.ts:reasoning_contentwhenmergeToolResultText: truereasoning_contentadded)mergeToolResultText: truereasoning_contentis preserved when presentAll 24 tests pass:
cd src && npx vitest run api/transform/__tests__/r1-format.spec.tsUser @BowerMotorsport confirmed the fix works in their local testing
Pre-Submission Checklist
Documentation Updates
Additional Notes
Feedback and guidance are welcome!