fix: preserve existing reasoning_content on second interleaved pass (#24146 follow-up)#24428
fix: preserve existing reasoning_content on second interleaved pass (#24146 follow-up)#24428claudianus wants to merge 2 commits intoanomalyco:devfrom
Conversation
PR anomalyco#24146 unconditionally sets reasoning_content to the extracted value. On the second pass through transform (after DB storage), content parts no longer have reasoning (already extracted in first pass), so the extracted value is empty. This overwrites the previously correct providerOptions.reasoning_content, causing DeepSeek 400: The 'reasoning_content' in the thinking mode must be passed back to the API. Fix: when reasoningText is empty, fall back to the existing providerOptions[sdk][field] value before defaulting to empty string. This preserves non-empty reasoning from the first pass while still sending empty reasoning_content when DeepSeek requires it (the case PR anomalyco#24146 was fixing). Also use dynamic SDK key ([sdk]) instead of hardcoded openaiCompatible for provider flexibility.
Models.dev may have reasoning:true but no explicit interleaved config.
Default interleaved to {field: 'reasoning_content'} so the transform
pipeline correctly extracts reasoning parts into providerOptions.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PRs Found:
These PRs are addressing overlapping concerns around reasoning_content preservation and interleaved transform handling. Consider checking if PR #24250 duplicates or supersedes the work in this PR, or vice versa. |
|
Issue is closed, so unless there is a secondary issue with repro steps im going to close this |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Problem
PR #24146 fixed empty reasoning_content preservation for DeepSeek V4 by unconditionally setting
[field]: reasoningTextin providerOptions. However, this introduced a regression: on the second pass through the interleaved transform (after DB storage), content parts no longer have reasoning (already extracted in first pass), soreasoningTextis empty. This overwrites the previously correctproviderOptions.reasoning_content, causing DeepSeek 400:Root Cause
The interleaved transform runs on every request. The first pass correctly extracts reasoning from content parts → stores in providerOptions → removes from content. On the second pass, content has no reasoning parts →
reasoningText = ""→ unconditionally overwrites providerOptions → reasoning_content lost.Fix
When
reasoningTextis empty, fall back to the existingproviderOptions[sdk][field]value before defaulting to empty string:This preserves non-empty reasoning from the first pass while still sending empty reasoning_content when DeepSeek requires it (the case #24146 was fixing).
Additional changes
[sdk]) instead of hardcodedopenaiCompatiblefor provider flexibilityinterleavedfor reasoning models infromModelsDevModelwhen models.dev hasreasoning: truebut no explicitinterleavedconfigVerification
""✅