Repository navigation
fix: report tool_use when an OpenAI stream ends a tool call with finish_reason stop - #145
Merged
lich0821 merged 1 commit intoOct 23, 2026
Conversation
…sh_reason stop OpenAI-compatible providers such as Gemini finish tool calls with finish_reason "stop". OpenAIStreamToClaude mapped that to end_turn even though a tool_use block had been sent, so Claude clients stopped instead of running the tool. It now reports tool_use when a tool block was started, also when the stream ends with [DONE] without a finish_reason. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
What
OpenAIStreamToClaudemapped everyfinish_reasonother than"tool_calls"tostop_reason: "end_turn". OpenAI-compatible providers such as Gemini end tool calls withfinish_reason: "stop", so the Claude client received atool_useblock followed byend_turnand stopped instead of running the tool. The non-stream path (OpenAIRespToClaude) already reportstool_usewhenever the response has tool calls.The stream converter now reports
tool_usewhen atool_useblock was started and the finish reason is"stop"(or"tool_calls"). It also does so when the stream ends with[DONE]without anyfinish_reason. Other finish reasons (for examplelength) and text-only replies are unchanged.Tests
In
internal/transformer/convert/claude_openai_test.go:TestOpenAIStreamToClaudeStopWithToolCallReportsToolUse: a tool call in the same chunk asfinish_reason: "stop"reportstool_useand neverend_turn.TestOpenAIStreamToClaudeDoneWithToolCallAndNoFinishReasonReportsToolUse: a stream that ends with[DONE]after a tool call reportstool_use.TestOpenAIStreamToClaudeStopWithoutToolCallReportsEndTurn: a plain text reply still reportsend_turn.The first two fail on
masterand all pass now.go test ./internal/transformer/...andgo vet ./internal/transformer/...pass.This change was made with Claude Code; the tests above were run on the branch to check it.