Skip to content

ollama: Fix thinking being also sent as content - #55540

Merged
benbrandt merged 1 commit into
zed-industries:mainfrom
marius851000:ollama_fix_thinking_sent_as_content
May 6, 2026
Merged

ollama: Fix thinking being also sent as content#55540
benbrandt merged 1 commit into
zed-industries:mainfrom
marius851000:ollama_fix_thinking_sent_as_content

Conversation

@marius851000

@marius851000 marius851000 commented May 3, 2026

Copy link
Copy Markdown
Contributor

"msg.string_contents();" return more than just content. It also return tool result (which need special handling, and should be emitted from the tool role) and thinking (which need already implemented special handling).

This resulted in thinking being sent as content, which apparently ollama’s gemma4 parser didn’t handled well, and caused a number of issue that manifested by 1. outputting end of though token where unappropriate and 2. repeating things endlessly

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist (no UI/UX impact)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable (a quick review, without benchmark, show that this should be at least as fast as the previous code. This is called only exceptionally anyway.)

Closes #55537

Release Notes:

  • Fixed "thinking" text being badly formatted when sent to Ollama

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 3, 2026
@github-actions github-actions Bot added the community champion Issues filed by our amazing community champions! 🫶 label May 3, 2026
@maxdeviant maxdeviant changed the title Ollama: Fix thinking being also send as content ollama: Fix thinking being also sent as content May 3, 2026
@SomeoneToIgnore SomeoneToIgnore added the area:ai Related to Agent Panel, Edit Prediction, Copilot, or other AI features label May 3, 2026
@marius851000

marius851000 commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

In the end, I still have issue with gemma4. Less systematic, but I suspect there are still issue somewhere between Zed and Ollama. Changed the release notes in accordance. (this patch is benificial nonetheless)

@benbrandt benbrandt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thanks!
Should we also be appending thinking text?

@marius851000

Copy link
Copy Markdown
Contributor Author

Appending thinking text? As in, merging ChatMessage::Assistant to contain both the thinking part and the generated part? Maybe. But looking at the generated text feed to the model by ollama, I notice nothing wrong beside what is fixed here.

@benbrandt
benbrandt enabled auto-merge May 6, 2026 12:54
@benbrandt
benbrandt added this pull request to the merge queue May 6, 2026
Merged via the queue into zed-industries:main with commit 65107c9 May 6, 2026
45 checks passed
ubunatic pushed a commit to ubunatic/zed that referenced this pull request May 16, 2026
"msg.string_contents();" return more than just content. It also return
tool result (which need special handling, and should be emitted from the
tool role) and thinking (which need already implemented special
handling).

This resulted in thinking being sent as content, which apparently
ollama’s gemma4 parser didn’t handled well, and caused a number of issue
that manifested by 1. outputting end of though token where unappropriate
and 2. repeating things endlessly

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
(no UI/UX impact)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable (a quick
review, without benchmark, show that this should be at least as fast as
the previous code. This is called only exceptionally anyway.)

Closes zed-industries#55537

Release Notes:

- Fixed "thinking" text being badly formatted when sent to Ollama
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
"msg.string_contents();" return more than just content. It also return
tool result (which need special handling, and should be emitted from the
tool role) and thinking (which need already implemented special
handling).

This resulted in thinking being sent as content, which apparently
ollama’s gemma4 parser didn’t handled well, and caused a number of issue
that manifested by 1. outputting end of though token where unappropriate
and 2. repeating things endlessly

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
(no UI/UX impact)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable (a quick
review, without benchmark, show that this should be at least as fast as
the previous code. This is called only exceptionally anyway.)

Closes zed-industries#55537

Release Notes:

- Fixed "thinking" text being badly formatted when sent to Ollama
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
"msg.string_contents();" return more than just content. It also return
tool result (which need special handling, and should be emitted from the
tool role) and thinking (which need already implemented special
handling).

This resulted in thinking being sent as content, which apparently
ollama’s gemma4 parser didn’t handled well, and caused a number of issue
that manifested by 1. outputting end of though token where unappropriate
and 2. repeating things endlessly

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
(no UI/UX impact)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable (a quick
review, without benchmark, show that this should be at least as fast as
the previous code. This is called only exceptionally anyway.)

Closes zed-industries#55537

Release Notes:

- Fixed "thinking" text being badly formatted when sent to Ollama
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 community champion Issues filed by our amazing community champions! 🫶

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ollama: thinking is also sent as content

4 participants