Repository navigation
Conversation
…baba#700) Some Anthropic-compatible gateways reject the cache_control field that OCR injects for prompt caching, causing 400 errors with unrecognizedProperty=cache_control. Add a disable_cache_control boolean (false by default) to: - ResolvedEndpoint / ClientConfig (runtime) - llmFileConfig.llm section (legacy config) - providerEntryConfig (providers / custom_providers) When true, cache_control is omitted from system blocks and tool definitions in buildAnthropicParams. All other providers are unaffected. Users can enable it via: ocr config set providers.anthropic.disable_cache_control true Adds TestBuildAnthropicParams_DisableCacheControl to verify the field is absent from all system blocks and tools when the option is set.
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
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 (4)
📝 WalkthroughWalkthroughThe change adds ChangesCache-control configuration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Configuration
participant ResolvedEndpoint
participant NewLLMClient
participant AnthropicRequest
Configuration->>ResolvedEndpoint: resolve disable_cache_control
ResolvedEndpoint->>NewLLMClient: forward DisableCacheControl
NewLLMClient->>AnthropicRequest: omit cache_control when enabled
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
User descriptionSummaryFixes alibaba#700 — Anthropic-compatible gateways/proxies that reject the OCR adds Changes
How to useocr config set providers.anthropic.disable_cache_control trueOr in {
"providers": {
"anthropic": { "disable_cache_control": true }
}
}Works for How to testgo test ./internal/llm/... -run TestBuildAnthropicParams_DisableCacheControl -v
# runs successfully; asserts all CacheControl.Type fields are empty
go test ./... -count=1 # all packages passCloses alibaba#700 CodeAnt-AI DescriptionAllow Anthropic-compatible proxies that reject cache-control fields to process reviews What Changed
Impact
💡 Usage GuideChecking Your Pull RequestEvery time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later. Talking to CodeAnt AIGot a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask: This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code. ExamplePreserve Org Learnings with CodeAntYou can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input: This helps CodeAnt AI learn and adapt to your team's coding style and standards. ExampleRetrigger reviewAsk CodeAnt AI to review the PR again, by typing: Check Your Repository HealthTo analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health. |
| Models []string `json:"models,omitempty"` | ||
| AuthHeader string `json:"auth_header,omitempty"` | ||
| TimeoutSec int `json:"timeout_sec,omitempty"` // per-request HTTP timeout in seconds | ||
| DisableCacheControl bool `json:"disable_cache_control,omitempty"` // omit cache_control from Anthropic requests |
There was a problem hiding this comment.
Suggestion: The newly accepted disable_cache_control field exists only in the resolver's private config structs. The public cmd/opencodereview.Config and ProviderEntry types do not define it, so the documented ocr config set providers.anthropic.disable_cache_control true command is rejected as an unknown provider field, and an existing manually-added setting is discarded the next time the CLI rewrites config.json. Add the field to the config-writing models and provider-field handling. [incomplete implementation]
Severity Level: Major ⚠️
- ❌ Documented providers.anthropic command always fails.
- ❌ Config rewrites silently remove manually added settings.
- ⚠️ Anthropic proxies continue rejecting cache_control fields.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** internal/llm/resolver.go
**Line:** 257:257
**Comment:**
*Incomplete Implementation: The newly accepted `disable_cache_control` field exists only in the resolver's private config structs. The public `cmd/opencodereview.Config` and `ProviderEntry` types do not define it, so the documented `ocr config set providers.anthropic.disable_cache_control true` command is rejected as an unknown provider field, and an existing manually-added setting is discarded the next time the CLI rewrites config.json. Add the field to the config-writing models and provider-field handling.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| Protocol: protocol, | ||
| AuthHeader: authHeader, | ||
| Source: "provider:" + cfg.Provider, | ||
| ExtraBody: extraBody, |
There was a problem hiding this comment.
Suggestion: extra_body is forwarded as unrestricted JSON overrides after the SDK request parameters are built. A provider configuration containing keys such as model, messages, tools, or input can replace the values assembled from the current ChatRequest, causing requests to use stale or attacker-controlled payload data instead of the current conversation. Reject reserved request-field collisions or restrict extra_body to vendor-specific fields. [api mismatch]
Severity Level: Major ⚠️
- ❌ Configured messages can replace the active review conversation.
- ❌ Configured tools can disable or alter tool execution.
- ⚠️ Configured model can ignore the selected request model.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** internal/llm/resolver.go
**Line:** 433:433
**Comment:**
*Api Mismatch: `extra_body` is forwarded as unrestricted JSON overrides after the SDK request parameters are built. A provider configuration containing keys such as `model`, `messages`, `tools`, or `input` can replace the values assembled from the current `ChatRequest`, causing requests to use stale or attacker-controlled payload data instead of the current conversation. Reject reserved request-field collisions or restrict extra_body to vendor-specific fields.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| AuthHeader: authHeader, | ||
| Source: "provider:" + cfg.Provider, | ||
| ExtraBody: extraBody, | ||
| ExtraHeaders: extraHeaders, |
There was a problem hiding this comment.
Suggestion: Configuration-file extra_headers are copied directly into the resolved endpoint without applying the reserved-header checks used by ParseExtraHeaders. A config entry containing Authorization, X-Api-Key, Content-Type, or User-Agent is therefore forwarded to the SDK and can override authentication or request metadata. Validate these maps with the same reserved-header rules before returning the endpoint. [security]
Severity Level: Major ⚠️
- ❌ Anthropic requests can use incorrect authentication headers.
- ⚠️ Configured Content-Type or User-Agent can corrupt request metadata.
- ⚠️ Manually edited provider configurations bypass reserved-header protection.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** internal/llm/resolver.go
**Line:** 434:434
**Comment:**
*Security: Configuration-file `extra_headers` are copied directly into the resolved endpoint without applying the reserved-header checks used by `ParseExtraHeaders`. A config entry containing `Authorization`, `X-Api-Key`, `Content-Type`, or `User-Agent` is therefore forwarded to the SDK and can override authentication or request metadata. Validate these maps with the same reserved-header rules before returning the endpoint.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
Summary
Fixes alibaba#700 — Anthropic-compatible gateways/proxies that reject the
cache_controlfield now have a config option to suppress it.OCR adds
cache_control: {"type": "ephemeral"}to the last systemblock and last tool definition to enable Anthropic prompt caching. Some
Bedrock-style proxies and custom gateways do not support this field and
return a 400 error:
Changes
internal/llm/client.go—ClientConfig.DisableCacheControlfield;buildAnthropicParamsguards bothCacheControlassignments behind!c.cfg.DisableCacheControl. No effect on OpenAI/OpenAI-Responses clients.internal/llm/resolver.go—ResolvedEndpoint.DisableCacheControl,llmFileConfig.disable_cache_control, andproviderEntryConfig.disable_cache_control(JSON-tagged). Threaded throughboth config-file resolution paths.
internal/llm/client_test.go—TestBuildAnthropicParams_DisableCacheControl:asserts no
cache_controlappears on any system block or tool when enabled.pages/src/content/docs/en/configuration.md— new section explainingthe option, with CLI and JSON examples.
How to use
Or in
~/.opencodereview/config.json:{ "providers": { "anthropic": { "disable_cache_control": true } } }Works for
custom_providerstoo.How to test
Closes alibaba#700