fix(console): strip reasoning from oa-compatible history#28308
Open
JGoP-L wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds request sanitization for the OpenAI-compatible provider by removing non-standard reasoning fields from chat messages, along with a regression test to ensure outgoing requests don’t include those fields.
Changes:
- Sanitize outgoing
messagesby stripping the non-standardreasoningproperty before sending requests viaoaCompatHelper.modifyBody. - Add a Bun test validating that
reasoningis removed from messages on same-format conversions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/console/app/src/routes/zen/util/provider/openai-compatible.ts | Sanitize body.messages by removing reasoning before building the outgoing request body. |
| packages/console/app/test/openai-compatible.test.ts | Adds coverage to ensure the OpenAI-compatible request path strips reasoning from chat history. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+84
to
+91
| function stripNonStandardMessageFields(body: Record<string, any>) { | ||
| if (!Array.isArray(body.messages)) return body | ||
| return { | ||
| ...body, | ||
| messages: body.messages.map((message) => { | ||
| if (!message || typeof message !== "object") return message | ||
| const { reasoning: _reasoning, ...sanitized } = message | ||
| return sanitized |
Comment on lines
+84
to
+94
| function stripNonStandardMessageFields(body: Record<string, any>) { | ||
| if (!Array.isArray(body.messages)) return body | ||
| return { | ||
| ...body, | ||
| messages: body.messages.map((message) => { | ||
| if (!message || typeof message !== "object") return message | ||
| const { reasoning: _reasoning, ...sanitized } = message | ||
| return sanitized | ||
| }), | ||
| } | ||
| } |
Comment on lines
33
to
39
| modifyBody: (body: Record<string, any>, _workspaceID?: string) => { | ||
| const sanitized = stripNonStandardMessageFields(body) | ||
| return { | ||
| ...body, | ||
| ...(body.stream ? { stream_options: { include_usage: true } } : {}), | ||
| ...sanitized, | ||
| ...(sanitized.stream ? { stream_options: { include_usage: true } } : {}), | ||
| } | ||
| }, |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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 #27852
Type of change
What does this PR do?
Some OpenAI-compatible providers reject non-standard fields inside chat history messages. In the reported case,
messages[].reasoningwas forwarded to OpenCode Go forkimi-k2.6, which caused a 400 response because the gateway rejected that field.This change removes only the non-standard
reasoningfield from outgoing OpenAI-compatible chat history messages before the provider request is sent.It does not remove top-level reasoning settings, and it does not remove provider-specific content fields such as
reasoning_content.How did you verify your code works?
Added a regression test for the OpenAI-compatible request path and ran:
Screenshots / recordings
Not a UI change.
Checklist