Repository navigation
fix: report truncation between Gemini MAX_TOKENS and Claude/OpenAI - #148
Merged
lich0821 merged 1 commit intoOct 23, 2026
Merged
Conversation
The Gemini converters never mapped a reply cut off by the token limit. Gemini finishReason MAX_TOKENS always became Claude end_turn or OpenAI stop, and Claude max_tokens became Gemini STOP, so clients treated a truncated reply as complete. Map them in the Gemini <-> Claude and Gemini -> OpenAI converters. 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
The Gemini converters never mapped a reply cut off by the token limit:
finishReason: "MAX_TOKENS"always became Claudestop_reason: "end_turn"(GeminiRespToClaude,GeminiStreamToClaude) or OpenAIfinish_reason: "stop"(GeminiRespToOpenAI,GeminiStreamToOpenAI).stop_reason: "max_tokens"always became GeminifinishReason: "STOP"(ClaudeRespToGemini).A client behind ccNexus therefore saw a truncated reply as a complete one.
These five now map
MAX_TOKENStomax_tokens(Claude),length(OpenAI) and back (MAX_TOKENS).MAX_TOKENSwins overtool_use/tool_calls, since a call cut off mid-arguments is a truncated reply. The streaming converters from Claude and OpenAI to Gemini carry no finish reason at all and are not touched. The same fix for the Claude <-> OpenAI pair is a separate change.Tests
New
internal/transformer/convert/gemini_truncation_test.go, one test per converter:TestGeminiRespToClaudeMaxTokensReportsMaxTokensandTestGeminiStreamToClaudeMaxTokensReportsMaxTokensTestGeminiRespToOpenAIMaxTokensReportsLengthandTestGeminiStreamToOpenAIMaxTokensReportsLengthTestClaudeRespToGeminiMaxTokensReportsMaxTokensAll five fail on
masterand 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.