Repository navigation
fix(proxy): keep tool_use stop_reason when the stream ends with [DONE] - #238
Closed
pcbeingused333 wants to merge 1 commit into
Closed
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
The OpenAI->Anthropic SSE translator emitted a message_delta with the real stop_reason on finish_reason, then a second one with a hard-coded end_turn on [DONE], overwriting tool_use. Skip the fallback message_delta when a stop reason was already sent, and add regression tests.
VickyXAI
pushed a commit
that referenced
this pull request
Nov 3, 2026
src/proxy/sse-translator.ts (OpenAI-to-Anthropic SSE translation) has never been imported by any file in the repo's history. The proxy pipes the gateway's stream and reads usage from message_delta itself, so the class only drew fixes that had no runtime effect (PR #238).
Contributor
|
Thanks for the careful write-up and the tests. The bug you found in Rather than fix code that never runs, we removed the file in 1c108dd, so I'm closing this PR. One note in case you take on similar work: keeping the |
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.
Fixes the streaming proxy ending every OpenAI-format response with
stop_reason: end_turn, even when the model asked for a tool call.Cause
SSETranslator.processChunkhandlesfinish_reasonby emitting amessage_deltawith the mapped stop reason (tool_calls->tool_use). When the upstream then sends[DONE], it emitted a secondmessage_deltawith a hard-codedend_turn. Anthropic-format clients take the lastmessage_delta, sotool_usewas overwritten and the tool call was treated as a finished turn.Receipt (event sequence produced on main for an upstream stream ending in
finish_reason: "tool_calls"followed by[DONE], as asserted by the new test):Fix
Track whether a stop reason was already emitted and, on
[DONE], only send the fallbackend_turnmessage_deltawhen none was.message_stopis still always sent. The case where[DONE]arrives with nofinish_reasonkeeps the old fallback.Tests
New
test/sse-translator.local.mjs(added tonpm test): tool_calls finish keeps a singletool_use; normal stop gives a singleend_turn;[DONE]alone falls back toend_turn. Two of the three fail on main; all pass with the change.This PR was prepared with the help of an AI assistant, and the author is responsible for the change.