Repository navigation
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe change updates Claude tool schema conversion to omit ChangesClaude tool schema fix
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
|
有人来审一下吗?挺小的一个改动 |
7f2931a to
dfd42f9
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
service/relayconvert/internal/oai_chat/to_claude_messages_req.go (1)
40-42: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winUnguarded type assertion on
params["type"]can panic.
params["type"].(string)will panic iftypeis present but not a string (e.g., a JSON Schema type union array). This is the same class of bug this PR is fixing forrequired/properties—an unsafe read of a dynamically-typed map value. Since tool parameter schemas are typically root-level"object"this is unlikely in practice, but a malformed/unexpected tool schema would crash the request instead of gracefully degrading.🛡️ Proposed fix using comma-ok idiom
- if params["type"] != nil { - claudeTool.InputSchema["type"] = params["type"].(string) - } + if typeVal, ok := params["type"].(string); ok { + claudeTool.InputSchema["type"] = typeVal + }Since this involves a Go type-assertion/language-semantics concern, please confirm whether upstream validation guarantees
typeis always a string before reaching this function.🤖 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 `@service/relayconvert/internal/oai_chat/to_claude_messages_req.go` around lines 40 - 42, Update the type handling in the tool-schema conversion logic to use a guarded string type assertion for params["type"] instead of directly asserting it. Only assign claudeTool.InputSchema["type"] when the value is actually a string, allowing unexpected schema values such as arrays to degrade gracefully without panicking; verify whether upstream validation guarantees this type before relying on it.
🤖 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 `@service/relayconvert/internal/oai_chat/to_claude_messages_req_test.go`:
- Around line 56-64: Replace the non-fatal value checks in the test with assert,
including the webSearchTools emptiness check and the InputSchema
presence/content checks for both tools. Keep require.Len for the
setup/index-safety assertion so subsequent tool-specific assertions remain
valid.
---
Nitpick comments:
In `@service/relayconvert/internal/oai_chat/to_claude_messages_req.go`:
- Around line 40-42: Update the type handling in the tool-schema conversion
logic to use a guarded string type assertion for params["type"] instead of
directly asserting it. Only assign claudeTool.InputSchema["type"] when the value
is actually a string, allowing unexpected schema values such as arrays to
degrade gracefully without panicking; verify whether upstream validation
guarantees this type before relying on it.
🪄 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: a08233b7-ad9c-4679-b993-580232b36ba4
📒 Files selected for processing (2)
service/relayconvert/internal/oai_chat/to_claude_messages_req.goservice/relayconvert/internal/oai_chat/to_claude_messages_req_test.go
|
注意到main分支对相关文件进行重构,已同步 |
移植自上游 PR QuantumNous#6039。OpenAI→Claude 工具转换无条件拷贝 params["required"]/params["properties"],源 schema 未声明该键时 map 取值为 nil,序列化成 "required": null 被 Claude 上游按 `null is not of type "array"` 拒绝(Codex 的 list_mcp_resources 等无必填参数工具全部 400)。改为仅在键存在时拷贝,并补回归测试。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
OpenAIChatRequestToClaudeMessages copied `properties`/`required` from the source OpenAI tool schema into the Anthropic input_schema map unconditionally. When a function omits `required` (valid for a tool with no required params, e.g. list_mcp_resources), the missing map key reads back as nil, gets stored explicitly, and marshals to `"required": null`. Upstreams that validate the schema reject it with `null is not of type "array"` (HTTP 400). Guard both assignments with a nil check, matching the existing `type` handling above, so absent keys stay absent.
Add TestOpenAIChatRequestToClaudeMessagesOmitsAbsentToolRequired: a tool that omits `required` must not serialize it (it previously became "required": null), while a tool that declares `required` keeps it intact.
86266ee to
df60dc9
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
relaykit/relayconvert/internal/oai_chat/to_claude_messages_req_test.go (1)
18-48: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for omitted
properties.Both test schemas include
properties. The test does not protect the omission branch added in the converter. Add a schema withoutpropertiesand assert that its outputInputSchemadoes not contain that key.Also applies to: 60-65
🤖 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 `@relaykit/relayconvert/internal/oai_chat/to_claude_messages_req_test.go` around lines 18 - 48, Add a tool schema case without a properties field in the test fixtures for the converter, then assert the converted tool’s InputSchema omits the properties key. Keep the existing schemas and assertions intact, and target the test covering the conversion of Tools into Claude messages.Source: Coding guidelines
🤖 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 `@relaykit/relayconvert/internal/oai_chat/to_claude_messages_req_test.go`:
- Around line 6-7: Update the test invoking OpenAIChatRequestToClaudeMessages to
pass context.Context, convmeta.Meta, and relaykit/dto.GeneralOpenAIRequest, and
replace the root dto import with github.com/QuantumNous/new-api/relaykit/dto.
Verify with GOWORK=off go build ./... and go test
./relayconvert/internal/oai_chat from relaykit.
---
Nitpick comments:
In `@relaykit/relayconvert/internal/oai_chat/to_claude_messages_req_test.go`:
- Around line 18-48: Add a tool schema case without a properties field in the
test fixtures for the converter, then assert the converted tool’s InputSchema
omits the properties key. Keep the existing schemas and assertions intact, and
target the test covering the conversion of Tools into Claude messages.
🪄 Autofix
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 Plus
Run ID: b8e42d55-297a-4934-891f-907ca457f501
📒 Files selected for processing (2)
relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.gorelaykit/relayconvert/internal/oai_chat/to_claude_messages_req_test.go
Import relaykit-local dto/convmeta instead of the root module so relaykit stays independently buildable, pass convmeta.Meta to the converter, and set max_tokens which the current converter requires.
|
@coderabbitai resume |
✅ Action performedReviews resumed. |
|
Fixed in #6862 维护者看起来还挺忙的( |
Important
📝 变更描述 / Description
chatCompletions 格式在转换 tools 中 required 这个键的时候加上空判断,防止类似 required: null 这种情况出现,从而导致请求失败
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
修改后自己构建进行请求:

多轮不出现问题,而修改前仅需几轮就会报错
Summary by CodeRabbit
Bug Fixes
requiredfields from appearing when no required properties are specified.Tests