Skip to content

Improve interleaved reasoning context#55085

Closed
Echsecutor wants to merge 11 commits into
zed-industries:mainfrom
european-epc-competence-center:fixing_reasoning_context
Closed

Improve interleaved reasoning context#55085
Echsecutor wants to merge 11 commits into
zed-industries:mainfrom
european-epc-competence-center:fixing_reasoning_context

Conversation

@Echsecutor

Copy link
Copy Markdown

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
  • [ x] Tests cover the new/changed behavior
  • [ x] Performance impact has been considered and is acceptable

Closes #51743

  • Added trace logging in into_open_ai for request building, SSE chunk processing, and tool-call stream events.

  • Added a warn log when an assistant tool-call message is created with interleaved_reasoning=true but no reasoning content was accumulated, to help diagnose proxy/API forwarding issues.

  • Added trace logging of the full JSON request body in stream_completion.

  • Added into_open_ai_interleaved_reasoning_thinking_only_before_tool_use test covering single-turn and multi-turn scenarios where the assistant responds with thinking + tool_calls and no text content.

Release Notes:

  • Fixed interleaved reasoning content being lost on tool-only assistant turns
    When interleaved_reasoning is enabled and an assistant message contains only thinking content followed by a tool use (with no text block), the accumulated reasoning_content is 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.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 28, 2026
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Apr 28, 2026
@SomeoneToIgnore SomeoneToIgnore added the area:ai Related to Agent Panel, Edit Prediction, Copilot, or other AI features label Apr 28, 2026
@Echsecutor Echsecutor changed the title improved error logging for reasoning context improved interleaved reasoning context Apr 28, 2026
@nervgh

nervgh commented Apr 28, 2026

Copy link
Copy Markdown

Thank you for your efforts!

By the way, Deepseek v4 has the same problem.

@maxdeviant maxdeviant changed the title improved interleaved reasoning context Improve interleaved reasoning context Apr 28, 2026
@Echsecutor

Copy link
Copy Markdown
Author

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.

@infused-kim

Copy link
Copy Markdown

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 reasoning_content to " " (string with a space). Setting it to an empty string didn't work because either the opencode proxy or the API requet code was removing the parameter.

You can find my branch with the commit here:
https://github.com/infused-kim/zed/tree/epc/fixing_reasoning_context

My test prompt was Can you please run the env command and show me the output?.

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,
            },
          },
        ],
      },
    },
  },

@infused-kim

infused-kim commented May 3, 2026

Copy link
Copy Markdown

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 (Zed.app) instead of (Zed Dev.app).

You can build it by checking out the branch and then running ./script/bundle-mac. You may need to install various dependencies. For more info check the documentation here:
https://github.com/zed-industries/zed/tree/28a54ce122fdd5efb2e23cc77a5efab78c07061c/docs/src/development

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,
            },
          },
        ],
      },
    },
  },

@Echsecutor

Copy link
Copy Markdown
Author

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 " " instead of none/empty string sounds a bit hacky, but I am happy to check and maybe integrate into this PR if that helps in your provider setup. Can you point me to the specific commit/change? Trying to Pull your branch into mine creates a huge diff, that's probably not intended.

There is also some discussion about this PR in #51743 , btw.

infused-kim added a commit to infused-kim/zed that referenced this pull request May 4, 2026
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
@infused-kim

Copy link
Copy Markdown

@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:
infused-kim@76556c0
https://github.com/infused-kim/zed/commits/pr-orig/55085-opencode-thinking-fix/

pull Bot pushed a commit to esinanturan/zed that referenced this pull request May 5, 2026
…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
zed-zippy Bot added a commit that referenced this pull request May 5, 2026
…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>
ebaah46 pushed a commit to ebaah46/zed that referenced this pull request May 6, 2026
…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
@cla-bot

cla-bot Bot commented May 7, 2026

Copy link
Copy Markdown

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 cla-bot Bot removed the cla-signed The user has signed the Contributor License Agreement label May 7, 2026
@cla-bot

cla-bot Bot commented May 7, 2026

Copy link
Copy Markdown

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'.

@Echsecutor

Copy link
Copy Markdown
Author

@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 😉

@cla-bot

cla-bot Bot commented May 7, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown

@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.

@cla-bot

cla-bot Bot commented May 7, 2026

Copy link
Copy Markdown

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

cla-bot Bot commented May 7, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@Vlaaaaaaad

Copy link
Copy Markdown
Contributor

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

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?

@raphaelluethy

Copy link
Copy Markdown
Contributor

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

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.

@Vlaaaaaaad

Copy link
Copy Markdown
Contributor

@raphaelluethy yup the " " hack fixes the Kimi K2.6 from OpenCode Go issue (which has been known for a while)! In my comment I was talking about Zed 1.1.5 still being broken — I should've made that clearer, sorry!

@raphaelluethy

raphaelluethy commented May 8, 2026

Copy link
Copy Markdown
Contributor

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
I leave this up to the maintainers which approach they would like to follow.

@cla-bot

cla-bot Bot commented May 12, 2026

Copy link
Copy Markdown

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'.

@Echsecutor

Copy link
Copy Markdown
Author

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 😉

@cla-bot

cla-bot Bot commented May 12, 2026

Copy link
Copy Markdown

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

cla-bot Bot commented May 12, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@infused-kim

Copy link
Copy Markdown

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 12, 2026
@cla-bot

cla-bot Bot commented May 12, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@infused-kim

Copy link
Copy Markdown

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.

@infused-kim

Copy link
Copy Markdown

@cla-bot check

@cla-bot

cla-bot Bot commented May 12, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@benbrandt

Copy link
Copy Markdown
Member

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?

@benbrandt benbrandt closed this May 17, 2026
@Echsecutor

Copy link
Copy Markdown
Author

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 😉

@infused-kim

Copy link
Copy Markdown

I believe I saw in another issue that this was fixed on OpenCode's side. Thank you for all your work on it @Echsecutor .

jasonsmithio pushed a commit to paddleboarddev/paddleboard that referenced this pull request May 31, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai Related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kimi k2.5 error "thinking is enabled but reasoning_content is missing in assistant tool call message"

8 participants