fix(llm): forward reasoning_content in experimental OpenAI Chat assistant messages#28346
Open
nilo85 wants to merge 4 commits into
Open
fix(llm): forward reasoning_content in experimental OpenAI Chat assistant messages#28346nilo85 wants to merge 4 commits into
nilo85 wants to merge 4 commits into
Conversation
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.
…nt to avoid IDE errors
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
3 tasks
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
What does this PR do?
The OpenAI Chat protocol was reading
message.native?.openaiCompatiblebut the actual structure after the transform chain ismessage.native.providerOptions.openaiCompatible. This causedreasoning_contentto be stripped from historical assistant messages during tool-call workflows, destroying KV cache optimization on multi-turn conversations with local reasoning models.The
openAICompatibleReasoningContenthelper inpackages/llm/src/protocols/openai-chat.tswas looking formessage.native?.openaiCompatible, but the only place that populatesmessage.nativeisnative-request.ts:118, which wraps provider options as{ providerOptions: { openaiCompatible: { reasoning_content: "..." } } }. The function always returnedundefined.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.nativedirectly to the helper and navigates the actual structure with explicitisRecordguards at each level:native → providerOptions → openaiCompatible → reasoning_content. This restoresreasoning_contenton historical assistant messages so the LLM receives the full conversation history including reasoning from previous turns.How did you verify your code works?
packages/llm/test/provider/openai-chat.test.tsthat constructs a message with the correctnativeshape and assertsreasoning_contentappears in the prepared body.local/qwen3.6-35b-a3bthrough a tool-call workflow — KV cache hit rate went from 0% to ~87% on turn 2.Screenshots / recordings
N/A — no UI changes
Checklist