fix(translator): use deterministic tool call IDs in Gemini request translators - #194
Open
warelik wants to merge 2 commits into
Open
fix(translator): use deterministic tool call IDs in Gemini request translators#194warelik wants to merge 2 commits into
warelik wants to merge 2 commits into
Conversation
added 2 commits
August 20, 2026 13:29
…anslators Generate sequential deterministic tool and call IDs for Gemini requests without explicit IDs to prevent prompt cache misses across multi-turn conversations. Refs router-for-me/CLIProxyAPI#5107
This was referenced Aug 20, 2026
Open
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.
Problem
In Gemini API multi-turn conversations, the client re-sends the entire conversation history in
contentson each turn. GeminifunctionCallandfunctionResponseobjects do not carry mandatory ID fields.When translating Gemini requests to Claude (
ConvertGeminiRequestToClaude) and Codex (ConvertGeminiRequestToCodex), missing tool/call IDs were generated using random number generators (crypto/rand). Consequently, historical tool calls were assigned different random IDs on every subsequent turn, completely invalidating upstream LLM prompt caches (Anthropic Prompt Caching and OpenAI Prefix Caching) and resulting in a 100% cache miss rate, higher latencies, and increased token costs.Fix
internal/translator/claude/gemini/claude_gemini_request.go:89: Pre-scans payloadcontentsfor existing explicit tool IDs and generates deterministic sequential IDs (toolu_1,toolu_2, ...) while avoiding collisions with explicit IDs.internal/translator/codex/gemini/codex_gemini_request.go:92: Pre-scans payloadcontentsfor existing explicit call IDs and generates deterministic sequential IDs (call_1,call_2, ...) while avoiding collisions with explicit IDs.Tests
internal/translator/claude/gemini/claude_gemini_request_test.go:TestConvertGeminiRequestToClaude_DeterministicToolIDsAcrossRepeatedTranslations: Verifies identical multi-turn history produces byte-for-byte identical tool IDs across multiple translations.TestConvertGeminiRequestToClaude_ToolIDsUniqueWithinRequest: Verifies tool IDs within a single request are distinct.TestConvertGeminiRequestToClaude_ExplicitIDWinsOverGenerated: Verifies explicit tool IDs in Gemini payload are preserved.TestConvertGeminiRequestToClaude_ExplicitIDCollisionAvoided: Verifies generated IDs skip existing explicit IDs.TestConvertGeminiRequestToClaude_ExplicitIDAfterGeneratedCollisionAvoided: Verifies collision avoidance regardless of payload ordering.internal/translator/codex/gemini/codex_gemini_request_test.go:TestConvertGeminiRequestToCodex_DeterministicCallIDsAcrossRepeatedTranslations: Verifies repeated translation produces identical call IDs.TestConvertGeminiRequestToCodex_CallIDsUniqueWithinRequest: Verifies unique call IDs per request.TestConvertGeminiRequestToCodex_ExplicitIDWinsOverGenerated: Verifies explicit call IDs are preserved.TestConvertGeminiRequestToCodex_ExplicitIDCollisionAvoided: Verifies generated IDs avoid collisions with explicit call IDs.TestConvertGeminiRequestToCodex_ExplicitIDAfterGeneratedCollisionAvoided: Verifies collision avoidance across mixed ordering.Reverse bite-check
Reverting
internal/translator/claude/gemini/claude_gemini_request.goandinternal/translator/codex/gemini/codex_gemini_request.goto random ID generation produces immediate test failures across both test suites:Claude Request Translator:
Codex Request Translator:
Verification
Output:
Tooling note
The
jbcontextsemantic-search CLI is installed but non-functional in this environment(
jbcontext searchfails withthe OS keychain is not accessible). The equivalentreview passes were performed with the repository's own tooling and manual inspection
instead; this is disclosed for transparency about how the change was reviewed.