Skip to content

fix: report tool_use when an OpenAI stream ends a tool call with finish_reason stop - #145

Merged
lich0821 merged 1 commit into
lich0821:masterfrom
pcbeingused333:fix/stream-stop-with-tool-calls
Oct 23, 2026
Merged

lich0821 merged 1 commit into
lich0821:masterfrom
pcbeingused333:fix/stream-stop-with-tool-calls

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

What

OpenAIStreamToClaude mapped every finish_reason other than "tool_calls" to stop_reason: "end_turn". OpenAI-compatible providers such as Gemini end tool calls with finish_reason: "stop", so the Claude client received a tool_use block followed by end_turn and stopped instead of running the tool. The non-stream path (OpenAIRespToClaude) already reports tool_use whenever the response has tool calls.

The stream converter now reports tool_use when a tool_use block was started and the finish reason is "stop" (or "tool_calls"). It also does so when the stream ends with [DONE] without any finish_reason. Other finish reasons (for example length) and text-only replies are unchanged.

Tests

In internal/transformer/convert/claude_openai_test.go:

  • TestOpenAIStreamToClaudeStopWithToolCallReportsToolUse: a tool call in the same chunk as finish_reason: "stop" reports tool_use and never end_turn.
  • TestOpenAIStreamToClaudeDoneWithToolCallAndNoFinishReasonReportsToolUse: a stream that ends with [DONE] after a tool call reports tool_use.
  • TestOpenAIStreamToClaudeStopWithoutToolCallReportsEndTurn: a plain text reply still reports end_turn.

The first two fail on master and all pass now. go test ./internal/transformer/... and go vet ./internal/transformer/... pass.

This change was made with Claude Code; the tests above were run on the branch to check it.

…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>
@lich0821
lich0821 merged commit 3ec45c7 into lich0821:master Oct 23, 2026
6 checks passed
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.

2 participants