Skip to content

fix: preserve existing reasoning_content on second interleaved pass (#24146 follow-up)#24428

Closed
claudianus wants to merge 2 commits intoanomalyco:devfrom
claudianus:fix/interleaved-reasoning-preserve-existing
Closed

fix: preserve existing reasoning_content on second interleaved pass (#24146 follow-up)#24428
claudianus wants to merge 2 commits intoanomalyco:devfrom
claudianus:fix/interleaved-reasoning-preserve-existing

Conversation

@claudianus
Copy link
Copy Markdown
Contributor

Problem

PR #24146 fixed empty reasoning_content preservation for DeepSeek V4 by unconditionally setting [field]: reasoningText in 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), so reasoningText 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.

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 reasoningText is empty, fall back to the existing providerOptions[sdk][field] value before defaulting to empty string:

const existingField = msg.providerOptions?.[sdk]?.[field]
const resolvedText = reasoningText || existingField || ""

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

  • Use dynamic SDK key ([sdk]) instead of hardcoded openaiCompatible for provider flexibility
  • Default interleaved for reasoning models in fromModelsDevModel when models.dev has reasoning: true but no explicit interleaved config

Verification

  • Empty reasoning_content → still sent as ""
  • Non-empty reasoning_content on second pass → preserved from providerOptions ✅
  • Both DeepSeek direct and OpenRouter-routed DeepSeek covered

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.
@github-actions github-actions Bot added contributor needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Apr 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

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.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs Found:

  1. PR fix(provider): complete DeepSeek reasoning_content round-trip for multi-turn conversations #24250 - fix(provider): complete DeepSeek reasoning_content round-trip for multi-turn conversations

    • Relation: Addresses similar DeepSeek reasoning_content preservation issues in multi-turn conversations. This is closely related to the same regression area.
  2. PR fix(provider): auto-enable interleaved for reasoning models #24218 - fix(provider): auto-enable interleaved for reasoning models

    • Relation: Handles auto-enabling interleaved mode for reasoning models, which is mentioned in your PR's additional changes.
  3. PR fix(provider): preserve assistant message content when reasoning blocks present #21370 - fix(provider): preserve assistant message content when reasoning blocks present

    • Relation: Related to preserving content when reasoning blocks are present, a precursor to the current reasoning_content handling.

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.

@rekram1-node
Copy link
Copy Markdown
Collaborator

Issue is closed, so unless there is a secondary issue with repro steps im going to close this

@github-actions
Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 26, 2026
@github-actions github-actions Bot closed this Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants