Skip to content

fix(openai): DeepSeek V4 thinking mode compatibility (builds on #12181)#12204

Open
abcxlab wants to merge 7 commits intoRooCodeInc:mainfrom
abcxlab:DeepSeekV4
Open

fix(openai): DeepSeek V4 thinking mode compatibility (builds on #12181)#12204
abcxlab wants to merge 7 commits intoRooCodeInc:mainfrom
abcxlab:DeepSeekV4

Conversation

@abcxlab
Copy link
Copy Markdown

@abcxlab abcxlab commented Apr 27, 2026

Related GitHub Issue

Builds on: #12181 (OpenAI Compatible DeepSeek R1 Support)

Closes: #12173
Closes: #12177
Closes: #12174

Roo Code Task Context (Optional)

Description

This PR provides an incremental fix for DeepSeek V4 compatibility when using the "OpenAI Compatible" provider, building upon the foundations laid in #12181. It specifically addresses the 400 OpenAI completion error: 400 The reasoning_content in the thinking mode must be passed back to the API error that occurs during tool-calling sequences.

Key Implementation Details:

  • Protocol Integrity: Enabled mergeToolResultText: true for R1/DeepSeek models in OpenAiHandler. This ensures environment_details are merged into the preceding tool message instead of being sent as a separate user message, which prevents breaking the V4 reasoning chain.
  • DeepSeek V4 Spec Alignment:
    • Injected extra_body.thinking: { type: "enabled" } into the API request as required by the official DeepSeek V4 documentation for OpenAI SDK usage.
    • Implemented specific reasoning_effort mapping (e.g., mapping xhigh to max for DeepSeek).
    • Automatically cleared conflicting parameters like temperature and top_p when thinking mode is active.
  • Reasoning Persistence: Added preserveReasoning: true to model capabilities and enhanced Task.buildCleanConversationHistory to recognize and retain reasoning_content in the conversation history, preventing it from being stripped during context cleaning.

Test Procedure

  • Unit Testing: Added a comprehensive test suite in src/api/providers/__tests__/openai.spec.ts ("DeepSeek V4 / R1 Compatibility"). These tests verify correct parameter injection, strength mapping, and that standard models (like GPT-4o) remain unaffected.
  • Manual Verification: Confirmed that complex tasks involving multiple tool calls no longer trigger 400 errors when using DeepSeek V4 via the OpenAI Compatible provider.

Pre-Submission Checklist

  • Issue Linked: Related to Add support for Deepseek V4 Pro and Deepseek V4 Flash #12181.
  • Scope: Focused on DeepSeek V4 thinking mode compatibility.
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes.
  • Documentation Impact: Internal logic change, no user-facing doc updates required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A (Backend logic and protocol fix).

Documentation Updates

  • No documentation updates are required.

Additional Notes

Get in Touch

Interactively review PR in Roo Code Cloud

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Apr 27, 2026
Comment thread src/api/providers/openai.ts Fixed
Comment thread src/api/providers/openai.ts Fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

3 participants