Skip to content

fix(transform): inject reasoning_content for ALL assistant msgs to fix DeepSeek thinking mode#24150

Closed
fkyah3 wants to merge 1 commit intoanomalyco:devfrom
fkyah3:fix/reasoning-content-pr
Closed

fix(transform): inject reasoning_content for ALL assistant msgs to fix DeepSeek thinking mode#24150
fkyah3 wants to merge 1 commit intoanomalyco:devfrom
fkyah3:fix/reasoning-content-pr

Conversation

@fkyah3
Copy link
Copy Markdown

@fkyah3 fkyah3 commented Apr 24, 2026

Issue for this PR

Closes #24104

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

DeepSeek thinking mode requires
easoning_content on every assistant message, even empty ones. The current code only injects it for interleaved-capable models and skips when
easoningText is empty.

This fails for:

  • Models with capabilities.reasoning but no interleaved config (e.g., DeepSeek via @ai-sdk/openai-compatible)
  • Old DB-replayed messages without reasoning parts
  • String-content assistant messages (legacy format)

The fix broadens the trigger condition, defaults the providerOptions field to "reasoning_content", removes the if (reasoningText) guard, and handles string-content messages.

Note: PR #24146 by @heimoshuiyu addresses the same symptom (empty reasoning_content) but only for interleaved-configured models. This PR covers a broader set of scenarios including non-interleaved models and legacy message formats.

How did you verify your code works?

Applied the same logic to local fork, ran for multiple sessions with DeepSeek reasoning model — no more
easoning_content must be passed back errors.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…x DeepSeek thinking mode

DeepSeek reasoning API requires ALL assistant messages in conversation
history to carry reasoning_content (even empty string). The prior
interleaved-only guard missed:
- Models with reasoning capability but no interleaved config
- Old DB-replayed messages without reasoning parts
- String-content assistant messages (legacy format)

Key changes:
1. Broaden trigger to include model.capabilities.reasoning and any msg
   with existing reasoning parts (for DB replay)
2. Default field to reasoning_content when interleaved not configured
3. Always inject reasoning_content (empty string for legacy msgs)
4. Handle string-content assistant messages
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

Based on my search, I found 2 related open PRs that are potential duplicates or closely related:

  1. PR fix: preserve empty reasoning_content for DeepSeek V4 thinking mode #24146 - "fix: preserve empty reasoning_content for DeepSeek V4 thinking mode"

  2. PR fix(opencode): Error 400 missing reasoning_content – transform reasoning according to DeepSeek API and aditional test cases #17529 - "fix(opencode): Error 400 missing reasoning_content – transform reasoning according to DeepSeek API and aditional test cases"

Recommendation: Check PR #24146 for overlap with the current PR #24150, as both appear to be recent fixes addressing the same DeepSeek reasoning content issue.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@fkyah3
Copy link
Copy Markdown
Author

fkyah3 commented Apr 24, 2026

Our more comprehensive fix is available in our fork (commit b5b6ad05d). The simpler fix #24146 covers the common case. Closing as superseded.

@fkyah3 fkyah3 closed this Apr 24, 2026
@fkyah3 fkyah3 reopened this Apr 24, 2026
@fkyah3
Copy link
Copy Markdown
Author

fkyah3 commented Apr 24, 2026

Re-evaluated the approach — a smaller provider-level default config fix (<10 lines) is safer for upstream than modifying normalizeMessages core logic. Closing in favor of a targeted fix for @ai-sdk/openai-compatible provider.

@fkyah3 fkyah3 closed this Apr 24, 2026
@fkyah3
Copy link
Copy Markdown
Author

fkyah3 commented Apr 24, 2026

Followed your suggestion — opened a minimal 1-line PR at #24218. Different approach: defaults interleaved to { field: "reasoning_content" } when reasoning: true is set, instead of false. Closes the same gap without touching normalizeMessages.

@vr2uiu vr2uiu mentioned this pull request Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeepSeek thinking mode: reasoning_content must be passed back to API on conversation continuation

1 participant