Repository navigation
fix(translator): map non-streaming Claude stop reasons the way the streaming path does - #16544
Merged
diegosouzapw merged 2 commits intoOct 15, 2026
Conversation
…reaming path does A non-streaming Claude response only translated end_turn, tool_use and max_tokens. refusal, model_context_window_exceeded, stop_sequence and pause_turn stayed raw, so a Gemini client got a refusal or a context-window stop as a clean STOP. Use the shared OpenAI-compatible normalizer, which already holds the same mapping as convertStopReason.
diegosouzapw
merged commit Oct 15, 2026
607072b
into
cheaper-inference:release/v3.8.52
32 of 51 checks passed
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.
Summary
end_turn,tool_useandmax_tokens(responseTranslator.ts, the Claude branch oftranslateNonStreamingResponse).refusal,model_context_window_exceeded,stop_sequenceandpause_turnstayed raw.sanitizeOpenAIResponsenormalises them later. A Gemini client has no such step:OPENAI_TO_GEMINI_FINISH_REASONfalls back toSTOP, so a refusal or a context-window stop reached it as a cleanSTOP. Measured on e23fb0f:refusal -> STOP,model_context_window_exceeded -> STOP.normalizeOpenAICompatibleFinishReasonString, which already holds the same mapping as the streamingconvertStopReason:refusal -> content_filter,max_tokensandmodel_context_window_exceeded -> length,stop_sequenceandpause_turn -> stop. A Gemini client now getsSAFETYandMAX_TOKENS.Related Issues
Target Branch
release/v3.8.xbranch (the highest openrelease/v*), notmainv4-featurelabel for the v4 channelValidation
npm run lint(eslint on the changed files: clean)Tests Added Or Updated
tests/unit/claude-nonstream-stop-reasons.test.ts(new): 6 tests. On the base 5 fail and 1 passes; with the fix all 6 pass. One of them checks thatend_turn,tool_useandmax_tokenskeep their mappings for both OpenAI and Gemini clients.Coverage Notes
responseTranslator: 375/375 pass with the fix.Reviewer Notes