Skip to content

fix(llm): forward reasoning_content in experimental OpenAI Chat assistant messages#28346

Open
nilo85 wants to merge 4 commits into
anomalyco:devfrom
nilo85:feature/fix-historical-reasoning-payload
Open

fix(llm): forward reasoning_content in experimental OpenAI Chat assistant messages#28346
nilo85 wants to merge 4 commits into
anomalyco:devfrom
nilo85:feature/fix-historical-reasoning-payload

Conversation

@nilo85
Copy link
Copy Markdown

@nilo85 nilo85 commented May 19, 2026

Issue for this PR

Closes #19081

Note: This is fixing a future bug with experimental code; the current production issue is still being investigated against the AI SDK.

Type of change

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

What does this PR do?

The OpenAI Chat protocol was reading message.native?.openaiCompatible but the actual structure after the transform chain is message.native.providerOptions.openaiCompatible. This caused reasoning_content to be stripped from historical assistant messages during tool-call workflows, destroying KV cache optimization on multi-turn conversations with local reasoning models.

The openAICompatibleReasoningContent helper in packages/llm/src/protocols/openai-chat.ts was looking for message.native?.openaiCompatible, but the only place that populates message.native is native-request.ts:118, which wraps provider options as { providerOptions: { openaiCompatible: { reasoning_content: "..." } } }. The function always returned undefined.

This only affects the experimental native LLM adapter (OPENCODE_EXPERIMENTAL_NATIVE_LLM=true). The default AI SDK path handles reasoning content separately and is not impacted.

The fix passes message.native directly to the helper and navigates the actual structure with explicit isRecord guards at each level: native → providerOptions → openaiCompatible → reasoning_content. This restores reasoning_content on historical assistant messages so the LLM receives the full conversation history including reasoning from previous turns.

How did you verify your code works?

  • Added a unit test in packages/llm/test/provider/openai-chat.test.ts that constructs a message with the correct native shape and asserts reasoning_content appears in the prepared body.
  • Ran a live session with local/qwen3.6-35b-a3b through a tool-call workflow — KV cache hit rate went from 0% to ~87% on turn 2.

Screenshots / recordings

N/A — no UI changes

Checklist

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

nilo85 added 4 commits May 19, 2026 14:01
The OpenAI Chat protocol was reading message.native?.openaiCompatible but
the actual structure after the transform chain is
message.native?.providerOptions?.openaiCompatible. This caused
reasoning_content to be stripped from historical assistant messages during
tool-call workflows, destroying KV cache optimization on multi-turn
conversations with local reasoning models.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:title labels May 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title Feature/fix historical reasoning payload doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@nilo85 nilo85 changed the title Feature/fix historical reasoning payload fix(llm): forward reasoning_content in experimental OpenAI Chat assistant messages May 19, 2026
@github-actions
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.

@nilo85 nilo85 marked this pull request as draft May 19, 2026 13:43
@nilo85 nilo85 marked this pull request as ready for review May 19, 2026 13:44
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reasoning_content stripped from assistant messages on replay, causing KV cache invalidation on local inference

1 participant