Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Dec 18, 2025

Related GitHub Issue

Closes: #10175

Description

This PR attempts to address Issue #10175 where DeepSeek V3.2 API returns a 400 error after context condense.

Root Cause: DeepSeek's reasoner model (deepseek-reasoner) requires ALL assistant messages to have a reasoning_content field when using thinking mode. When context is condensed, the summary message is created without this field, causing the API to reject the request.

Fix: Modified src/api/transform/r1-format.ts to ensure that when converting messages for DeepSeek's thinking mode (indicated by mergeToolResultText: true), ALL assistant messages include the reasoning_content field, even if empty.

Changes made:

  1. Array content handling (lines 193-208): Added logic to always include reasoning_content (empty string if none) when mergeToolResultText is true
  2. String content handling (lines 240-252): Same logic applied for simple string content assistant messages

Test Procedure

  1. Added 4 new unit tests in src/api/transform/__tests__/r1-format.spec.ts:

    • Test that summary messages get empty reasoning_content when mergeToolResultText: true
    • Test that non-thinking models remain unaffected (no reasoning_content added)
    • Test array content handling with mergeToolResultText: true
    • Test that existing reasoning_content is preserved when present
  2. All 24 tests pass: cd src && npx vitest run api/transform/__tests__/r1-format.spec.ts

  3. User @BowerMotorsport confirmed the fix works in their local testing

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • 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 (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

Feedback and guidance are welcome!

… mode

When using DeepSeek reasoner models with context condense, the API returns
400 error "Missing reasoning_content field in the assistant message" because
condensed summary messages lack the reasoning_content field.

DeepSeek's API requires ALL assistant messages to have reasoning_content
when using thinking mode. This fix ensures reasoning_content is always
included (even if empty string) on assistant messages when mergeToolResultText
is enabled (which indicates thinking mode).

Fixes #10175
@roomote
Copy link
Contributor Author

roomote bot commented Dec 18, 2025

Rooviewer Clock   See task on Roo Cloud

Reviewed and found no issues. The fix correctly ensures reasoning_content is always present on assistant messages when using DeepSeek's thinking mode, addressing the reported 400 error after context condense.

  • No issues found

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Deepseek V3.2 API error 400 after context condense

3 participants