FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(llm): accept `reasoning` field in OpenAI-compatible streams by mickaeldamatha · Pull Request #35187 · anomalyco/opencode · GitHub

fix(llm): accept reasoning field in OpenAI-compatible streams - #35187

Closed
mickaeldamatha wants to merge 1 commit into
anomalyco:devfrom
mickaeldamatha:fix/openai-compatible-reasoning-field
Closed

fix(llm): accept reasoning field in OpenAI-compatible streams#35187
mickaeldamatha wants to merge 1 commit into
anomalyco:devfrom
mickaeldamatha:fix/openai-compatible-reasoning-field

Conversation

mickaeldamatha commented Jul 3, 2026
edited
Loading

Copy link
Copy Markdown

Issue for this PR

No existing issue — standalone bug fix.

Closes #

Type of change

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

What does this PR do?

The OpenAI Chat streaming delta schema (OpenAIChatDelta in
packages/llm/src/protocols/openai-chat.ts) only declares reasoning_content.
Each SSE chunk is decoded with Protocol.jsonEvent → Schema.fromJsonString,
which strips any key that isn't on the struct. So when a provider streams its
thinking under reasoning instead of reasoning_content, that key is dropped
during decoding and step() never sees it — the reasoning is silently lost.

I ran into this with Scaleway; it also affects self-hosted vLLM / SGLang
deployments and OpenRouter's reasoning field. The model was clearly reasoning
but nothing surfaced in the stream. I had been working around it by rewriting
reasoning → reasoning_content in a proxy sitting in front of
opencode serve; this patch makes that workaround unnecessary.

Two changes:

  • add reasoning to OpenAIChatDelta so the decoder keeps the field
  • in step(), read delta.reasoning_content ?? delta.reasoning, so
    reasoning_content still takes precedence when a provider sends both

It's additive to the wire schema — providers that only send reasoning_content
(DeepSeek etc.) hit the same code path as before and are unaffected.

How did you verify your code works?

Added two streaming tests in packages/llm/test/provider/openai-chat.test.ts,
alongside the existing reasoning_content one:

  • reasoning arriving via the reasoning field emits the expected
    reasoning-start / reasoning-delta / reasoning-end events
  • when both fields are present, reasoning_content wins

bun test in packages/llm: 29 pass / 0 fail. bun typecheck is clean (the
pre-push hook also ran the full monorepo typecheck, 30/30).

Screenshots / recordings

N/A — not a UI change.

Checklist

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

Some OpenAI-compatible providers (Scaleway, vLLM/SGLang, OpenRouter, ...)
stream chain-of-thought under a `reasoning` delta field instead of the
`reasoning_content` field emitted by DeepSeek et al. The OpenAI Chat
protocol only declared and read `reasoning_content`, so `reasoning` was
stripped by the delta schema and the model's thinking was silently
dropped for those providers.

Declare `reasoning` on the delta schema and fall back to it when
`reasoning_content` is absent, preferring `reasoning_content` when both
are present. Adds streaming tests for both cases.
github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jul 3, 2026

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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

Based on my search, I found the following related PRs that are worth reviewing:

Related PRs (same domain, different scope):

None of these are direct duplicates of PR #35187, but they are all related to reasoning field handling in OpenAI Chat streaming. PR #34698 appears most closely related as it also modifies reasoning chunk handling in the same protocol.

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 3, 2026
github-actions Bot closed this Jul 3, 2026
github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jul 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL