-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(openai): handle providers emitting both reasoning and reasoning_content fields #2911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1ff9b7e
fix(openai): handle providers emitting both reasoning and reasoning_c…
tusharmath 80f1252
fix(openai): merge reasoning fields by longest non-empty value
tusharmath 15c5a3b
test(openai): add unit tests for reasoning field selection logic
tusharmath 4da35c5
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
crates/forge_app/src/dto/openai/fixtures/chutes_completion_response.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "id": "chatcmpl-a9db7cc9005c6568", | ||
| "object": "chat.completion.chunk", | ||
| "created": 1775233185, | ||
| "model": "moonshotai/Kimi-K2.5-TEE", | ||
| "choices": [ | ||
| { | ||
| "index": 0, | ||
| "delta": { "reasoning": " The", "reasoning_content": " The" }, | ||
| "logprobs": null, | ||
| "finish_reason": null, | ||
| "token_ids": null, | ||
| "hidden_states": null | ||
| } | ||
| ], | ||
| "usage": { | ||
| "prompt_tokens": 8764, | ||
| "total_tokens": 8765, | ||
| "completion_tokens": 1, | ||
| "reasoning_tokens": 1 | ||
| }, | ||
| "chutes_verification": "6bbeaf04d5800d774cc497b0a619acee" | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
reasoning()method returns inconsistent data: trimmed strings when both fields are present, but untrimmed strings when only one field is present.When both
reasoningandreasoning_contentexist (line 173-180), the returned value is the trimmed version (a.trim()orb.trim()). However, when only one field exists (lines 182-183), the original untrimmed string is returned.For example:
reasoning(Some(" hello "), None)returns" hello "(untrimmed)reasoning(Some(" hello "), Some(""))returns"hello"(trimmed)This inconsistency could cause production issues if downstream code expects consistent whitespace handling.
Fix: Either always return trimmed strings or always return untrimmed strings. For consistency with the filtering logic that checks
!s.trim().is_empty(), the method should return trimmed strings in all cases:Spotted by Graphite

Is this helpful? React 👍 or 👎 to let us know.