fix:gemini to claude tool_use err#5041
Conversation
WalkthroughThe PR modifies Gemini relay handlers to detect tool calls in streamed responses and conditionally emit stop/final responses based on the target relay format. For Claude-format conversions, stop messages are suppressed and final responses return in stop form with computed usage tracking. ChangesGemini Tool-Call Relay Format Handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@relay/channel/gemini/relay-gemini.go`:
- Around line 1342-1349: The Claude branch rebuilds streamed tool-calls with
fresh UUIDs because getResponseToolCall() is called each chunk and keyed by
tool.ID, causing reindexing and duplicate tool-use blocks; fix this by
persisting a stable ID per choice/tool across chunks (e.g., maintain a map keyed
by choice index and tool name or choice index+tool type) in relay-gemini.go and
use that stable ID when converting deltas for Claude instead of generating a new
UUID in getResponseToolCall(); update the logic around response.IsToolCall(),
response.Choices and tool.ID so the conversion reuses the stored ID for the same
logical tool call across chunks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: efac3ff4-57d6-4291-8d81-bc80cf78d1ae
📒 Files selected for processing (1)
relay/channel/gemini/relay-gemini.go
| if response.IsToolCall() { | ||
| finishReason = constant.FinishReasonToolCalls | ||
| if info.RelayFormat == types.RelayFormatClaude { | ||
| for choiceIdx := range response.Choices { | ||
| response.Choices[choiceIdx].FinishReason = nil | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Keep streamed tool-call IDs stable across deltas.
This Claude branch relies on response.IsToolCall(), but the streamed tool calls are still rebuilt with a fresh UUID in getResponseToolCall() every chunk. Because the reindexing map below keys on tool.ID, one logical tool call never reuses its prior slot and gets emitted as multiple tool-use blocks as arguments stream in. Please persist a stable ID per choice/tool across chunks before converting these deltas for Claude.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@relay/channel/gemini/relay-gemini.go` around lines 1342 - 1349, The Claude
branch rebuilds streamed tool-calls with fresh UUIDs because
getResponseToolCall() is called each chunk and keyed by tool.ID, causing
reindexing and duplicate tool-use blocks; fix this by persisting a stable ID per
choice/tool across chunks (e.g., maintain a map keyed by choice index and tool
name or choice index+tool type) in relay-gemini.go and use that stable ID when
converting deltas for Claude instead of generating a new UUID in
getResponseToolCall(); update the logic around response.IsToolCall(),
response.Choices and tool.ID so the conversion reuses the stored ID for the same
logical tool call across chunks.
📝 变更描述 / Description
修复Gemini转Claude接口的工具兼容问题
🚀 变更类型 / Type of change
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)


后:
前:
Summary by CodeRabbit