fix(cli,gateway): fully preserve DeepSeek reasoning_content across tool calls#9502
fix(cli,gateway): fully preserve DeepSeek reasoning_content across tool calls#9502scottnzuk wants to merge 5 commits intoKilo-Org:mainfrom
Conversation
…ol calls Apply complete fix for DeepSeek reasoning_content 400 errors in multi-turn tool call conversations. Addresses four interconnected root causes: - Layer 1: Add extractReasoning: true to gateway provider creation - Layer 2: Dynamic SDK key selection and unconditional reasoning_content injection - Layer 3: Auto-enable interleaved capability for reasoning models - Layer 4: Comprehensive test coverage for all provider paths Fixes issues with OpenRouter, native DeepSeek API, and custom OpenAI-compatible providers. Ensures backward compatibility with historical messages and seamless multi-turn conversations. Closes Kilo-Org#9471, Kilo-Org#9482 Related upstream: anomalyco/opencode#24250
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (5 files)
Reviewed by gpt-5.4-2026-03-05 · 529,365 tokens |
- Make interleaved auto-enablement specific to DeepSeek models only - Fix interleaved block to handle string content assistant messages - Add test for string content message handling - Ensure no early return prevents fallback processing
✅ Code Review Issues AddressedI've fixed both issues identified by the code review: Issue 1: Auto-enabling interleaved for all reasoning modelsFixed: Made the auto-enablement specific to DeepSeek models only by checking instead of applying to all reasoning models. This prevents incorrect handling for providers that don't use this field format. Issue 2: Early return skipping string content handlingFixed: Removed the early return in the interleaved block and modified it to handle both array and string content messages. Now assistant messages with string content (not just array content) get proper injection when they don't already have it. Additional Changes:
The fixes ensure that only DeepSeek models get the interleaved auto-enablement, and all assistant message types (array and string content) are properly handled for reasoning content injection. |
✅ Code Review Issues AddressedI've fixed both issues identified by the code review: Issue 1: Auto-enabling interleaved for all reasoning modelsFixed: Made the auto-enablement specific to DeepSeek models only by checking Issue 2: Early return skipping string content handlingFixed: Removed the early return in the interleaved block and modified it to handle both array and string content messages. Now assistant messages with string content (not just array content) get proper Additional Changes:
The fixes ensure that only DeepSeek models get the interleaved auto-enablement, and all assistant message types (array and string content) are properly handled for reasoning content injection. |
📊 Updated Testing ResultsUpdated the testing results in the PR description:
Tasks: 12 successful, 12 total
The additional test covers string content message handling that was added to address the code review feedback. |
|
@kilocode-bot anything else needed from me? |
Resolves DeepSeek reasoning_content API error by ensuring the Vercel AI SDK includes reasoning content in requests for reasoning models when using OpenAI-compatible providers. Fixes: The 'reasoning_content in the thinking mode must be passed back to the API' error that occurred on the 9th+ assistant message in sessions with DeepSeek reasoning models. This change adds the extractReasoning: true option to provider options when: - The model has reasoning capability (model.capabilities.reasoning === true) - The extractReasoning option is not already explicitly set The fix mirrors what was already implemented in the Kilo Gateway provider but was missing from the CLI's direct provider creation for bundled SDKs.,
|
Well after 3 revisions, endless token use and testing, still can't get to the bottom of this.. if anyone else wants to review this and see if I'm on the right track, and/or fix it, that would be amazing. For now, my fix is: when the error shows up, swap from Deepseek-V4 Flash to Deepseek-Chat. Oddly enough, they are actually both the same DeepSeek pass and API calls to chat to the new flash. But it allows me to skip over the error and carry on. ugh lol |
|
Issue is related to openrouter OpenRouterTeam/ai-sdk-provider#487 |
that would be correct for kilo version but i use direct api that or is that using open router back end as well? |
|
please fix it |
Context
The
reasoning_contentfix from PR #9470 was incomplete. Three additional layers needed: gateway extractReasoning, dynamic SDK key for OpenRouter, and unconditional injection for historical messages. This PR applies the complete fix matching upstream anomalyco/opencode#24250.Fixes #9501 - DeepSeek reasoning_content error in multi-turn tool call conversations.
Implementation
Layer 1: Gateway extractReasoning
extractReasoning: trueto gateway'screateOpenAI()andcreateOpenAICompatible()callsLayer 2: Transform Logic Updates
sdkKey()for dynamic providerOptions key selection in interleaved blockreasoning_contentfor all assistant messages on reasoning modelsLayer 3: Auto-Enable Interleaved
provider.tsto auto-enableinterleavedfor reasoning modelsreasoning: truegets the interleaved treatmentLayer 4: Comprehensive Testing
Screenshots
N/A (no UI changes)
How to Test
Use a DeepSeek model with thinking mode, trigger a tool call (e.g., ask it to run a bash command), then send a follow-up message. Both turns should succeed without 400 errors.
Verify with both OpenRouter and native DeepSeek provider paths.
Files Changed
packages/kilo-gateway/src/provider.ts- Added extractReasoning flagspackages/opencode/src/provider/transform.ts- Dynamic SDK key + unconditional fallbackpackages/opencode/src/provider/provider.ts- Auto-enable interleaved for reasoning modelspackages/opencode/test/provider/transform.test.ts- Added comprehensive tests.changeset/deepseek-reasoning-complete.md- Release notesTesting Results
bun turbo typecheckpasses across all packagesGet in Touch
Questions about the implementation or testing scenarios.