Skip to content

fix: support reasoning field in OpenAiHandler for OpenAI-compatible providers#11496

Draft
roomote[bot] wants to merge 1 commit intomainfrom
fix/openai-reasoning-field-support
Draft

fix: support reasoning field in OpenAiHandler for OpenAI-compatible providers#11496
roomote[bot] wants to merge 1 commit intomainfrom
fix/openai-reasoning-field-support

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Feb 17, 2026

Related GitHub Issue

Closes: #11495

Description

This PR attempts to address Issue #11495. Feedback and guidance are welcome.

Problem: OpenAiHandler only checked for reasoning_content field in streaming responses and had no reasoning extraction at all in non-streaming responses. Some OpenAI-compatible providers (e.g., vLLM after v0.15.1) return reasoning in the reasoning field instead, following OpenAI's own recommendations.

Changes (all in src/api/providers/openai.ts):

  1. Streaming path: Replaced the single reasoning_content check with a loop that checks both reasoning_content and reasoning fields, matching the pattern already used in BaseOpenAiCompatibleProvider. Also added whitespace-trimming filter to avoid yielding empty reasoning chunks.

  2. Non-streaming path: Added reasoning extraction from the response message for both reasoning_content and reasoning fields before yielding the text content.

  3. Tests: Added 7 new test cases in src/api/providers/__tests__/openai.spec.ts covering:

    • Streaming with reasoning_content field
    • Streaming with reasoning field
    • Priority when both fields present (prefers reasoning_content)
    • Empty/whitespace-only reasoning is filtered out
    • Non-streaming with reasoning_content field
    • Non-streaming with reasoning field

Test Procedure

  • Run: cd src && npx vitest run api/providers/__tests__/openai.spec.ts
  • All 54 tests pass (including 7 new reasoning field tests)

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue
  • Scope: Changes are focused on the linked issue
  • Self-Review: Performed self-review
  • Testing: New tests added to cover changes
  • Documentation Impact: No documentation updates required
  • Contribution Guidelines: Read and agree

Documentation Updates

  • No documentation updates are required.

Start a new Roo Code Cloud session on this branch

@roomote
Copy link
Contributor Author

roomote bot commented Feb 17, 2026

Rooviewer Clock   See task

The changes correctly align OpenAiHandler with the existing pattern in BaseOpenAiCompatibleProvider for both streaming and non-streaming paths. One minor inconsistency flagged:

  • Non-streaming reasoning extraction missing whitespace-trim filter (inconsistent with streaming path)

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Comment on lines +266 to +271
for (const key of ["reasoning_content", "reasoning"] as const) {
if (message && key in message && (message as any)[key]) {
yield { type: "reasoning", text: (message as any)[key] as string }
break
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-streaming path doesn't apply the same whitespace-trimming filter as the streaming path (line 205). A whitespace-only string like " " is truthy, so it would be yielded as a reasoning chunk here but filtered out in streaming mode. This is unlikely to cause real problems since providers rarely return whitespace-only reasoning in complete responses, but it's an inconsistency that could be worth aligning.

Suggested change
for (const key of ["reasoning_content", "reasoning"] as const) {
if (message && key in message && (message as any)[key]) {
yield { type: "reasoning", text: (message as any)[key] as string }
break
}
}
for (const key of ["reasoning_content", "reasoning"] as const) {
if (message && key in message && (message as any)[key]) {
const reasoning = (message as any)[key] as string
if (reasoning.trim()) {
yield { type: "reasoning", text: reasoning }
}
break
}
}

Fix it with Roo Code or mention @roomote and request a fix.

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.

[BUG] OpenAiHandler doesn't support reasoning field for OpenAI-compatible providers

1 participant

Comments