Skip to content

fix: preserve empty reasoning_content for DeepSeek V4 in non-streaming and streaming paths#24200

Closed
ihoooohi wants to merge 1 commit intoanomalyco:devfrom
ihoooohi:fix/deepseek-v4-reasoning-content-empty
Closed

fix: preserve empty reasoning_content for DeepSeek V4 in non-streaming and streaming paths#24200
ihoooohi wants to merge 1 commit intoanomalyco:devfrom
ihoooohi:fix/deepseek-v4-reasoning-content-empty

Conversation

@ihoooohi
Copy link
Copy Markdown

@ihoooohi ihoooohi commented Apr 24, 2026

Issue for this PR

Closes #24190

Type of change

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

What does this PR do?

Fixes the remaining cases where empty reasoning_content (reasoning_content: "") from DeepSeek V4 is discarded, causing "The reasoning_content in the thinking mode must be passed back to the API" errors in multi-turn tool call chains.

PR #24146 fixed the transform.ts outbound path (removing the if (reasoningText) guard), but three upstream locations still drop empty reasoning_content via truthy checks:

  1. Non-streaming response parser (openai-compatible-chat-language-model.ts): if (reasoning != null && reasoning.length > 0) drops "" — the reasoning part is never created in the stored message.
  2. Streaming response parser (openai-compatible-chat-language-model.ts): if (reasoningContent) drops "" — no reasoning-start emitted, so the part is never created.
  3. Outbound converter (convert-to-openai-compatible-chat-messages.ts): if (part.text) drops "" — empty reasoning text lost in outbound construction.

Fix:

  • Non-streaming: if (reasoning != null) preserves empty reasoning_text.
  • Streaming: if ("reasoning_text" in delta) detects field presence; emits reasoning-start, only emits reasoning-delta for non-empty content.
  • Outbound: reasoningText = part.text ?? "" preserves empty text.

How did you verify your code works?

Screenshots / recordings

N/A — no UI change.

Checklist

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

…g and streaming paths

Three truthy checks were dropping empty reasoning_content ('') from DeepSeek
V4's thinking mode responses, causing 'must be passed back to the API' errors
in multi-turn tool call chains:

1. Non-streaming parser: if (reasoning != null && reasoning.length > 0)
   -> Now: if (reasoning != null) to preserve empty strings
2. Streaming parser: if (reasoningContent) truthy check
   -> Now: if ('reasoning_text' in delta) to detect field presence
3. Outbound converter: if (part.text) reasoningText = part.text
   -> Now: reasoningText = part.text ?? '' to preserve empty text

PR anomalyco#24146 fixed the transform.ts path; this completes the remaining cases.
@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 github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

@kipropbrian
Copy link
Copy Markdown

kipropbrian commented Apr 24, 2026

Wasn't this fixed here too #24146 ?
Edit: I have just seen your other message. This looks good.

@ihoooohi
Copy link
Copy Markdown
Author

Yep — #24146 fixed transform.ts, this catches the remaining two parser paths where empty reasoning_content was still dropped before reaching storage.

@rekram1-node
Copy link
Copy Markdown
Collaborator

no this is completely wrong, it literally says github copilot sdk, I have left multiple notes for you and your agent not to touch this code path....

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 V4] reasoning_content not round-tripped — 400 error on multi-turn tool calls

3 participants