Improve interleaved reasoning context#55085
Conversation
Signed-off-by: Sebastian Schmittner <sebastian.schmittner@eecc.de>
|
Thank you for your efforts! By the way, Deepseek v4 has the same problem. |
I just tried with deepseek-v4-pro. This model works as well with the ZED binary build from this branch. |
|
Thank you for your work on this issue. I tried your branch, but still received the same error if there was no accumulated reasoning. I was able to fix it by setting You can find my branch with the commit here: My test prompt was And my config was: {
"language_models": {
"openai_compatible": {
"OpenCode Go": {
"api_url": "https://opencode.ai/zen/go/v1",
"available_models": [
{
"name": "kimi-k2.6",
"max_tokens": 262144,
"max_output_tokens": 65536,
"max_completion_tokens": 262144,
"capabilities": {
"tools": true,
"images": true,
"parallel_tool_calls": true,
"prompt_cache_key": true,
"chat_completions": true,
"interleaved_reasoning": true,
},
},
],
},
},
}, |
|
For anyone else who wants to start using opencode go before this gets merged, I created a branch based of v1.0.0 that adds only the required commits to fix this issue: https://github.com/infused-kim/zed/tree/pr-testing/55085-opencode-thinking-fix This produces a release build ( You can build it by checking out the branch and then running And my full config is: {
"language_models": {
"openai_compatible": {
"OpenCode Go": {
"api_url": "https://opencode.ai/zen/go/v1",
// For more models:
// https://models.dev/?sort=model&order=asc&search=opencode+go
// https://github.com/anomalyco/models.dev/tree/dev/providers/opencode-go/models
"available_models": [
{
"name": "kimi-k2.6",
"max_tokens": 262144,
"max_output_tokens": 65536,
"max_completion_tokens": 262144,
"capabilities": {
"tools": true,
"images": true,
"parallel_tool_calls": true,
"prompt_cache_key": true,
"chat_completions": true,
"interleaved_reasoning": true,
},
},
{
"name": "glm-5.1",
"max_tokens": 204800,
"max_output_tokens": 131072,
"max_completion_tokens": 204800,
"capabilities": {
"tools": true,
"images": false,
"parallel_tool_calls": true,
"prompt_cache_key": true,
"chat_completions": true,
},
},
{
"name": "deepseek-v4-pro",
"max_tokens": 1000000,
"max_output_tokens": 384000,
"max_completion_tokens": 1000000,
"capabilities": {
"tools": true,
"images": false,
"parallel_tool_calls": true,
"prompt_cache_key": true,
"chat_completions": true,
"interleaved_reasoning": true,
},
},
{
"name": "deepseek-v4-flash",
"max_tokens": 1000000,
"max_output_tokens": 384000,
"max_completion_tokens": 1000000,
"capabilities": {
"tools": true,
"images": false,
"parallel_tool_calls": true,
"prompt_cache_key": true,
"chat_completions": true,
"interleaved_reasoning": true,
},
},
{
"name": "minimax-m2.7",
"max_tokens": 204800,
"max_output_tokens": 131072,
"max_completion_tokens": 204800,
"capabilities": {
"tools": true,
"images": false,
"parallel_tool_calls": true,
"prompt_cache_key": true,
"chat_completions": true,
},
},
{
"name": "qwen3.6-plus",
"max_tokens": 262144,
"max_output_tokens": 65536,
"max_completion_tokens": 262144,
"capabilities": {
"tools": true,
"images": true,
"parallel_tool_calls": true,
"prompt_cache_key": true,
"chat_completions": true,
},
},
],
},
},
}, |
|
Hi @infused-kim ! Thanks for testing! I am using zed build form this branch for actual coding with a lot of tool calling for a couple of days now with kimik 2.6 and deepseek 4 pro routing through an openai_compatible conversation API. This is working fine for me. In prinziple, sending There is also some discussion about this PR in #51743 , btw. |
commit c6a0aac Author: Kim Streich <kim@infusedinsight.com> Date: Sun May 3 13:46:43 2026 -0600 Set reasoning_content to “ “ if no content has accumulated commit 202be6e Author: Sebastian Schmittner <sebastian.schmittner@eecc.de> Date: Sat May 2 21:34:00 2026 +0200 commit message generation/context summary with interleved reasoning commit fbcb79c Author: Sebastian Schmittner <sebastian.schmittner@eecc.de> Date: Tue Apr 28 16:29:11 2026 +0200 Simplify reasoning content logic and add test helpers commit 54c9448 Author: Sebastian Schmittner <sebastian.schmittner@eecc.de> Date: Tue Apr 28 15:34:19 2026 +0200 improved error logging for reasoning context Signed-off-by: Sebastian Schmittner <sebastian.schmittner@eecc.de> commit 557ece0 Author: Bennet Bo Fenner <bennet@zed.dev> Date: Mon Apr 27 14:36:11 2026 +0200 agent: Allow tools to output multiple content parts (zed-industries#54518) Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes #ISSUE Release Notes: - N/A
|
@Echsecutor yeah, it could be an issue with OpenCode's implementation of the API. I am not sure, but without setting reasoning_content to " " it didn't work for me. I also agree that it feels dirty, but for now I just wanted to get it working. I rebased my branch on top of yours, so you should now be able to fast forward my commit: |
…ies#55574) OpenCode API endpoints for DeepSeek were [moved from Anthropic-compatible to OpenAI-compatible](anomalyco/opencode#24500) and DeepSeek requires interleaved reasoning enabled to work. I ran a _"rename this variable to potato"_ test and I can confirm DeepSeek V4 Flash and Pro both work now 🎉 Some other OpenCode Go models were marked [on models.dev](https://github.com/anomalyco/models.dev/tree/dev/providers/opencode-go/models) as supporting `interleaved_reasoning` so they too got that enabled. Kimi K2.5 and Kimi K2.6 continue to fail with zed-industries#51743 (zed-industries#55085 seems to hint at this being [an OpenCode issue](zed-industries#51743 (comment))?), but all other models seem to work fine both with `interleaved_reasoning` and without it 🤷 I assume it's better to have that turned on? Again, the intersection of OpenAI Chat Completions API, different models, different inference providers, how they all work together is something I know nothing about! Self-Review Checklist: - [X] I've reviewed my own diff for quality, security, and reliability - [X] Unsafe blocks (if any) have justifying comments - [X] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [X] Performance impact has been considered and is acceptable Release Notes: - OpenCode Go: use correct DeepSeek endpoints - OpenCode: add support for interleaved_reasoning
…erry-pick to preview) (#55777) Cherry-pick of #55574 to preview ---- OpenCode API endpoints for DeepSeek were [moved from Anthropic-compatible to OpenAI-compatible](anomalyco/opencode#24500) and DeepSeek requires interleaved reasoning enabled to work. I ran a _"rename this variable to potato"_ test and I can confirm DeepSeek V4 Flash and Pro both work now 🎉 Some other OpenCode Go models were marked [on models.dev](https://github.com/anomalyco/models.dev/tree/dev/providers/opencode-go/models) as supporting `interleaved_reasoning` so they too got that enabled. Kimi K2.5 and Kimi K2.6 continue to fail with #51743 (#55085 seems to hint at this being [an OpenCode issue](#51743 (comment))?), but all other models seem to work fine both with `interleaved_reasoning` and without it 🤷 I assume it's better to have that turned on? Again, the intersection of OpenAI Chat Completions API, different models, different inference providers, how they all work together is something I know nothing about! Self-Review Checklist: - [X] I've reviewed my own diff for quality, security, and reliability - [X] Unsafe blocks (if any) have justifying comments - [X] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [X] Performance impact has been considered and is acceptable Release Notes: - OpenCode Go: use correct DeepSeek endpoints - OpenCode: add support for interleaved_reasoning Co-authored-by: Vlad Ionescu <Vlaaaaaaad@users.noreply.github.com>
…ies#55574) OpenCode API endpoints for DeepSeek were [moved from Anthropic-compatible to OpenAI-compatible](anomalyco/opencode#24500) and DeepSeek requires interleaved reasoning enabled to work. I ran a _"rename this variable to potato"_ test and I can confirm DeepSeek V4 Flash and Pro both work now 🎉 Some other OpenCode Go models were marked [on models.dev](https://github.com/anomalyco/models.dev/tree/dev/providers/opencode-go/models) as supporting `interleaved_reasoning` so they too got that enabled. Kimi K2.5 and Kimi K2.6 continue to fail with zed-industries#51743 (zed-industries#55085 seems to hint at this being [an OpenCode issue](zed-industries#51743 (comment))?), but all other models seem to work fine both with `interleaved_reasoning` and without it 🤷 I assume it's better to have that turned on? Again, the intersection of OpenAI Chat Completions API, different models, different inference providers, how they all work together is something I know nothing about! Self-Review Checklist: - [X] I've reviewed my own diff for quality, security, and reliability - [X] Unsafe blocks (if any) have justifying comments - [X] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [X] Performance impact has been considered and is acceptable Release Notes: - OpenCode Go: use correct DeepSeek endpoints - OpenCode: add support for interleaved_reasoning
|
We require contributors to sign our Contributor License Agreement, and we don't have @infused-kim on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
We require contributors to sign our Contributor License Agreement, and we don't have @infused-kim on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@infused-kim ok, I have merged your contirbution, many thanks! But, as the bot says, you need to accept that cla for this PR to be mergeable now 😉 |
|
We require contributors to sign our Contributor License Agreement, and we don't have @infused-kim on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check @Echsecutor thank you! Actually, I’m not sure if that’s needed anymore. Version 1.1.5 that was published yesterday includes official open code go support. If this was an issue that was only happening with open code, then we might not even need this. |
|
We require contributors to sign our Contributor License Agreement, and we don't have @infused-kim on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
The cla-bot has been summoned, and re-checked this pull request! |
Kimi K2.6 from OpenCode Go still fails with the error from #51743 🙂 As I mentioned in this comment, I have no idea if the fix needs to be in Zed or in OpenCode 🤷 I don't know if other providers are still impacted by this or not — Moonshot was mentioned as impacted on the issue discussion? |
From my local testing on my own pr, the kimi models fail due to the reasoning content field being discarded when the string is empty. Simply adding an empty string with a space fixes the issue. Opencode seems to do the same in their cli, so i.g. this fix is the only (or easier) way. |
|
@raphaelluethy yup the |
|
As this is an issue on opencodes side, I published my testing branch that puts the fix in the opencode go provider. I think this this would be the cleaner version, as we dont pollute the global implementation of the openai compat provider. #56182 |
|
We require contributors to sign our Contributor License Agreement, and we don't have @infused-kim on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
@infused-kim did you click that agreement? since its like two lines of code I could also rewrite the history for this PR, but I would appreciate if your contribution is honored 😉 |
|
We require contributors to sign our Contributor License Agreement, and we don't have @infused-kim on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
Sorry for the delay @Echsecutor. I thought I already did it, but must have been mistaken. Thank you for your patience and for the effort to make sure my contribution is included. I really appreciate it. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
Hi given we reworked the responses api and other areas of the openai providers this week, I assume there is a decent amount of conflicts (github won't even show them to me, just that they exist) Mind doing another pass if needed off main? |
|
It seems like your reworking fixed the bug @benbrandt , I did not encounter it any more in the recent release versions, so this PR has probably outlived its purpose 😉 |
|
I believe I saw in another issue that this was fixed on OpenCode's side. Thank you for all your work on it @Echsecutor . |
OpenCode API endpoints for DeepSeek were [moved from Anthropic-compatible to OpenAI-compatible](anomalyco/opencode#24500) and DeepSeek requires interleaved reasoning enabled to work. I ran a _"rename this variable to potato"_ test and I can confirm DeepSeek V4 Flash and Pro both work now 🎉 Some other OpenCode Go models were marked [on models.dev](https://github.com/anomalyco/models.dev/tree/dev/providers/opencode-go/models) as supporting `interleaved_reasoning` so they too got that enabled. Kimi K2.5 and Kimi K2.6 continue to fail with zed-industries/zed#51743 (zed-industries/zed#55085 seems to hint at this being [an OpenCode issue](zed-industries/zed#51743 (comment))?), but all other models seem to work fine both with `interleaved_reasoning` and without it 🤷 I assume it's better to have that turned on? Again, the intersection of OpenAI Chat Completions API, different models, different inference providers, how they all work together is something I know nothing about! Self-Review Checklist: - [X] I've reviewed my own diff for quality, security, and reliability - [X] Unsafe blocks (if any) have justifying comments - [X] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [X] Performance impact has been considered and is acceptable Release Notes: - OpenCode Go: use correct DeepSeek endpoints - OpenCode: add support for interleaved_reasoning
Self-Review Checklist:
Closes #51743
Added
tracelogging ininto_open_aifor request building, SSE chunk processing, and tool-call stream events.Added a
warnlog when an assistant tool-call message is created withinterleaved_reasoning=truebut no reasoning content was accumulated, to help diagnose proxy/API forwarding issues.Added
tracelogging of the full JSON request body instream_completion.Added
into_open_ai_interleaved_reasoning_thinking_only_before_tool_usetest covering single-turn and multi-turn scenarios where the assistant responds with thinking + tool_calls and no text content.Release Notes:
When
interleaved_reasoningis enabled and an assistant message contains only thinking content followed by a tool use (with no text block), the accumulatedreasoning_contentis now correctly attached to the generated OpenAI-format assistant message. Previously this reasoning was dropped, causing API errors with models (e.g., Kimi) that require reasoning content in conversation history.