Skip to content

fix: preserve empty reasoning_content for DeepSeek V4 thinking mode - #261

Merged
Astro-Han merged 1 commit into
devfrom
worktree-claude+fix-deepseek-v4-reasoning
Apr 27, 2026
Merged

fix: preserve empty reasoning_content for DeepSeek V4 thinking mode#261
Astro-Han merged 1 commit into
devfrom
worktree-claude+fix-deepseek-v4-reasoning

Conversation

@Astro-Han

Copy link
Copy Markdown
Owner

Summary

Cherry-pick upstream opencode PR #24146 to fix DeepSeek V4 multi-turn failures when switching models mid-conversation.

Why

DeepSeek V4 thinking mode requires reasoning_content on every assistant message in subsequent requests. Previously normalizeMessages only injected the field when reasoningText was non-empty, so historical assistant messages produced by other models (e.g. GLM-5, GPT-4o) had no reasoning_content and DeepSeek rejected the request with 400 The reasoning_content in the thinking mode must be passed back to the API. Fix always sets the field — empty string included — so cross-model history is accepted.

Related Issue

Closes #250

How To Verify

Manual repro on dev:desktop with this branch:

  1. Start a session with GLM-5 (or any non-DeepSeek-V4 model), exchange one turn.
  2. Switch model to deepseek-v4-pro, send another message.
  3. Before the fix: 400 reasoning_content must be passed back. After the fix: assistant replies normally with finish=stop, reasoning tokens recorded.

Verified locally via session export pawwork-session-mighty-canyon-2026-04-27: glm-5 → deepseek-v4-pro turn completes with error=null, finish=stop, 258 reasoning tokens preserved. CI handles broader checks.

Screenshots or Recordings

N/A — backend transform fix, no UI surface.

Checklist

  • I linked the related issue, or stated why there is no issue
  • This PR has type, scope, and priority labels, or I requested maintainer labeling
  • I listed the relevant verification steps, including tests when behavior changed
  • I manually checked visible UI or copy changes when needed, with screenshots or recordings
  • I considered macOS and Windows impact for desktop, packaging, updater, signing, paths, shell, or permissions changes
  • I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, or generated/local file changes when relevant
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English

…#24146)

Co-authored-by: Simon Klee <hello@simonklee.dk>
(cherry picked from commit 923af96d26bd7777ae335ddade89854ac5fc8841)
@Astro-Han Astro-Han added bug Something isn't working P1 High priority harness Model harness, prompts, tool descriptions, and session mechanics labels Apr 27, 2026
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@Astro-Han has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 15 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 839679f3-fc6a-48d5-ba12-4b4e01c58b7e

📥 Commits

Reviewing files that changed from the base of the PR and between 98b7233 and a33486d.

📒 Files selected for processing (1)
  • packages/opencode/src/provider/transform.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-claude+fix-deepseek-v4-reasoning

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the normalizeMessages function in packages/opencode/src/provider/transform.ts to ensure that reasoning content fields are always included in the providerOptions.openaiCompatible object, even when the content is empty. This change is designed to maintain compatibility with providers like DeepSeek that require these fields to be present in subsequent requests. I have no feedback to provide as there are no review comments to evaluate.

@Astro-Han
Astro-Han merged commit ae800e6 into dev Apr 27, 2026
25 checks passed
@Astro-Han
Astro-Han deleted the worktree-claude+fix-deepseek-v4-reasoning branch April 27, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working harness Model harness, prompts, tool descriptions, and session mechanics P1 High priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] DeepSeek V4 multi-turn conversation fails with 400: reasoning_content must be passed back

2 participants