Skip to content

fix: accept Ollama reasoning field in OpenAI Chat deltas - #36068

Closed
twhittock wants to merge 2 commits into
anomalyco:devfrom
twhittock:fix/ollama-reasoning-field
Closed

fix: accept Ollama reasoning field in OpenAI Chat deltas#36068
twhittock wants to merge 2 commits into
anomalyco:devfrom
twhittock:fix/ollama-reasoning-field

Conversation

@twhittock

Copy link
Copy Markdown

Ollama's /v1/chat/completions endpoint emits reasoning output in a reasoning field (both streaming deltas and non-streaming messages), not reasoning_content which is the DeepSeek/LM Studio convention. Effect's Schema.Struct strips unknown keys, so the reasoning content was silently discarded - producing empty responses for thinking models like glm-5.2 via Ollama Cloud.

Adds reasoning as a fallback alongside reasoning_content in the delta schema, message schema, and helper function, matching how other OpenAI-compatible clients already handle this.

Refs: ollama/ollama#16853, RightNow-AI/openfang#805

Issue for this PR

Closes#34798

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Extends "OpenAI compatible" schema shape to include Ollama's reasoning field alongside the existing reasoning_content.

How did you verify your code works?

Build & run locally, observed GLM-5.2 responses from ollama cloud are now working.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found a related PR that appears to be addressing the same issue:

PR #35284: fix(llm): accept \reasoning` field in OpenAI-compatible streams`
#35284

This PR appears to be directly related to the current PR #36068 since both are working on accepting the reasoning field in OpenAI-compatible streams. The earlier PR #35284 may already address this issue, so you should verify whether:

  1. PR fix(llm): accept reasoning field in OpenAI-compatible streams #35284 was merged and already includes this fix
  2. PR fix: accept Ollama reasoning field in OpenAI Chat deltas #36068 is updating or extending that work further
  3. These PRs are actually addressing the same problem or different aspects

Additionally, PR #34283: fix(provider): expose xhigh instead of max for GLM-5.2 on OpenAI-compatible is contextually related since it also deals with GLM-5.2 handling on OpenAI-compatible providers, which is the model mentioned in your PR description.

CreatorGhost added a commit to CreatorGhost/TheCode that referenced this pull request Jul 12, 2026
CreatorGhost added a commit to CreatorGhost/TheCode that referenced this pull request Jul 12, 2026
@twhittock
twhittockforce-pushed the fix/ollama-reasoning-field branch from aa72711 to 0bdc839CompareJuly 15, 2026 04:25
@twhittock
twhittockforce-pushed the fix/ollama-reasoning-field branch 2 times, most recently from aa18e0b to 73fd534CompareJuly 17, 2026 07:01
@twhittock
twhittockforce-pushed the fix/ollama-reasoning-field branch from 73fd534 to 8247198CompareJuly 21, 2026 06:09
@twhittock
twhittockforce-pushed the fix/ollama-reasoning-field branch 4 times, most recently from be240e6 to 125b02dCompareJuly 31, 2026 07:01
@twhittock
twhittockforce-pushed the fix/ollama-reasoning-field branch 2 times, most recently from 2fdd4b3 to 5935528CompareAugust 4, 2026 07:02
opencodeand others added 2 commits August 4, 2026 12:12
Ollama's /v1/chat/completions endpoint emits reasoning output in a
`reasoning` field (both streaming deltas and non-streaming messages),
not `reasoning_content` which is the DeepSeek/LM Studio convention.
Effect's Schema.Struct strips unknown keys, so the reasoning content
was silently discarded - producing empty responses for thinking
models like glm-5.2 via Ollama Cloud.
Adds `reasoning` as a fallback alongside `reasoning_content`
in the delta schema, message schema, and helper function, matching
how other OpenAI-compatible clients already handle this.
Refs: ollama/ollama#16853, RightNow-AI/openfang#805
@twhittock
twhittockforce-pushed the fix/ollama-reasoning-field branch from 5935528 to a9659f8CompareAugust 5, 2026 07:02
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conversations hang after first response when provider returns a reasoning field (using Ollama/Qwen3)

1 participant

@twhittock