Repository navigation
Conversation
WalkthroughIn ChangesClaude Tool-Call Argument Parsing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 2
🤖 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/claude/relay-claude.go`:
- Line 414: Replace the direct json.Unmarshal call on line 414 with
common.Unmarshal from the common/json.go wrapper package. Change
json.Unmarshal([]byte(args), &inputObj) to use the common.Unmarshal wrapper
function instead, which is the standardized approach for all JSON
marshal/unmarshal operations in business logic throughout the repository.
- Line 415: The SysLog call at line 415 logs the raw toolCall.Function.Arguments
which can contain sensitive data. Replace the logging of the full raw arguments
with metadata instead: log the tool function name (toolCall.Function.Name) and
the byte length of the arguments (using len() on the serialized form) rather
than the full content using fmt.Sprintf("%v", toolCall.Function.Arguments). This
preserves debugging information while avoiding exposure of sensitive user/tool
data in logs.
🪄 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: b670e4f0-b44c-408f-8301-1e389abf0503
📒 Files selected for processing (1)
relay/channel/claude/relay-claude.go
| common.SysLog("tool call function arguments is not a map[string]any: " + fmt.Sprintf("%v", toolCall.Function.Arguments)) | ||
| continue | ||
| if args := toolCall.Function.Arguments; args != "" { | ||
| if err := json.Unmarshal([]byte(args), &inputObj); err != nil { |
There was a problem hiding this comment.
Replace direct json.Unmarshal with common.Unmarshal.
Line 414 directly calls encoding/json in business logic, which violates the repository rule for Go JSON handling.
Proposed fix
- if err := json.Unmarshal([]byte(args), &inputObj); err != nil {
+ if err := common.Unmarshal([]byte(args), &inputObj); err != nil {
common.SysLog("tool call function arguments is not a map[string]any: " + fmt.Sprintf("%v", toolCall.Function.Arguments))
}As per coding guidelines, all JSON marshal/unmarshal operations in business code must use wrappers from common/json.go, and this path is application-level parsing rather than a Gin response-helper exemption.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if err := json.Unmarshal([]byte(args), &inputObj); err != nil { | |
| if err := common.Unmarshal([]byte(args), &inputObj); err != nil { | |
| common.SysLog("tool call function arguments is not a map[string]any: " + fmt.Sprintf("%v", toolCall.Function.Arguments)) | |
| } |
🤖 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/claude/relay-claude.go` at line 414, Replace the direct
json.Unmarshal call on line 414 with common.Unmarshal from the common/json.go
wrapper package. Change json.Unmarshal([]byte(args), &inputObj) to use the
common.Unmarshal wrapper function instead, which is the standardized approach
for all JSON marshal/unmarshal operations in business logic throughout the
repository.
Sources: Coding guidelines, Learnings
| continue | ||
| if args := toolCall.Function.Arguments; args != "" { | ||
| if err := json.Unmarshal([]byte(args), &inputObj); err != nil { | ||
| common.SysLog("tool call function arguments is not a map[string]any: " + fmt.Sprintf("%v", toolCall.Function.Arguments)) |
There was a problem hiding this comment.
Do not log raw tool arguments on parse failure.
Line 415 logs full toolCall.Function.Arguments; malformed payloads can still contain sensitive user/tool data. Log metadata (tool id/name + byte length) instead of raw content.
Proposed fix
- common.SysLog("tool call function arguments is not a map[string]any: " + fmt.Sprintf("%v", toolCall.Function.Arguments))
+ common.SysLog(fmt.Sprintf(
+ "tool call arguments parse failed: tool_id=%s tool_name=%s args_len=%d",
+ toolCall.ID, toolCall.Function.Name, len(args),
+ ))📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| common.SysLog("tool call function arguments is not a map[string]any: " + fmt.Sprintf("%v", toolCall.Function.Arguments)) | |
| common.SysLog(fmt.Sprintf( | |
| "tool call arguments parse failed: tool_id=%s tool_name=%s args_len=%d", | |
| toolCall.ID, toolCall.Function.Name, len(args), | |
| )) |
🤖 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/claude/relay-claude.go` at line 415, The SysLog call at line
415 logs the raw toolCall.Function.Arguments which can contain sensitive data.
Replace the logging of the full raw arguments with metadata instead: log the
tool function name (toolCall.Function.Name) and the byte length of the arguments
(using len() on the serialized form) rather than the full content using
fmt.Sprintf("%v", toolCall.Function.Arguments). This preserves debugging
information while avoiding exposure of sensitive user/tool data in logs.
dev 与 upstream 无共同祖先、不能 cherry-pick,按文件手工 port: - 502858d fix(QuantumNous#5543): tool 调用 arguments 为空时保留 tool_use 块 - 45cc95a fix(gemini): ToolConfig 加 IncludeServerSideToolInvocations 字段 - 8ca1033 fix: ReasoningContent/Reasoning 改 *string,修复空思考内容转发被静默丢弃 (并适配 dev 自研 openaicompat/responses_to_chat.go 的 *string 赋值) - 867d8ac fix(QuantumNous#5390): kimi-k2.6 温度归一化(import 冲突已解,去掉未用的 channelconstant) - ff06067 fix(QuantumNous#5095): 移除 fcIdx -1 偏移,修复并发工具调用撞键 go build ./... 与 go vet 均通过。 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
包含:QuantumNous#5543 tool_use / gemini 字段 / ReasoningContent *string / QuantumNous#5390 kimi 温度 / QuantumNous#5095 并发工具撞键 / aa56667 A 防上游 request-id 覆盖
(cherry picked from commit 502858d)
📝 变更描述 / Description
OpenAI 格式转 Claude 时,
RequestOpenAI2ClaudeMessage会把tool_calls转成tool_use块。原逻辑对function.arguments直接json.Unmarshal,解析失败就continue跳过整个块。部分模型在无参数工具调用时
arguments为空字符串"",反序列化必然失败,导致对应的tool_use块被整个丢弃。而 Claude 要求tool_use与后续tool_result一一对应,块丢失后请求结构被破坏,会触发上游报错。修复:仅在
arguments非空时才反序列化;即使解析失败也不再跳过,照常追加tool_use(input 为空对象),保证块完整。🚀 变更类型 / Type of change
修复前:


修复后:
Summary by CodeRabbit