Skip to content

feat(anthropic): perserve top level cache control, close #1484#1486

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
Apr 25, 2026
Merged

feat(anthropic): perserve top level cache control, close #1484#1486
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented Apr 25, 2026

Copy link
Copy Markdown
Owner

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Anthropic's top-level automatic prompt caching. The changes ensure that the cache_control field is captured during inbound request parsing, propagated through the internal pipeline via TransformerMetadata, and restored in the outbound request to the upstream API. When automatic caching is active, the system's internal per-block breakpoint optimization is bypassed. Feedback was provided to explicitly clear any existing per-block cache controls when the top-level field is present to avoid potential 400 Bad Request errors from the Anthropic API due to mixed caching modes.

Comment on lines +172 to 174
if anthropicReq.CacheControl == nil && countCacheControls(anthropicReq) > 0 {
optimizeCacheControl(anthropicReq)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Anthropic does not allow mixing automatic prompt caching (top-level cache_control) with explicit cache breakpoints (per-block cache_control). If the top-level field is present, any existing per-block breakpoints should be cleared to avoid a 400 Bad Request error from the upstream API. Since optimizeCacheControl already performs a clear-and-rebuild, we should explicitly clear when skipping optimization.

Suggested change
if anthropicReq.CacheControl == nil && countCacheControls(anthropicReq) > 0 {
optimizeCacheControl(anthropicReq)
}
if anthropicReq.CacheControl != nil {
clearCacheControls(anthropicReq)
} else if countCacheControls(anthropicReq) > 0 {
optimizeCacheControl(anthropicReq)
}

@looplj looplj merged commit 44827f9 into unstable Apr 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant