fix: stop evicting message-level cache breakpoints for Anthropic Messages API#4410
Merged
fix: stop evicting message-level cache breakpoints for Anthropic Messages API#4410
Conversation
…emCacheControl Message-level cache_control entries are more valuable than tools/system breakpoints for long conversations because they implicitly cache the tools+system prefix (Anthropic cache hierarchy: tools → system → messages) and maintain the 20-block lookback chain needed for cache hits in long agent sessions. Previously, the function would evict earliest message breakpoints to make room for tools+system breakpoints, breaking cache coverage for claude-opus-4.6-1m conversations with many tool calls. Now tools+system breakpoints are only added when spare slots exist (existing < 4), never evicting message breakpoints.
1de96e2 to
c8bc699
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts Anthropic Messages API cache breakpoint handling to preserve message-level cache_control entries (which are more valuable for long agent conversations), preventing cache-rate regressions on long-context Claude models.
Changes:
- Update
addToolsAndSystemCacheControlto only add tool/system breakpoints when there are spare slots, without evicting message-level breakpoints. - Update and expand unit tests to cover “spare slot” vs “no spare slots” scenarios and ensure message breakpoints are preserved.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/platform/endpoint/node/messagesApi.ts |
Changes cache-control slot allocation logic to avoid evicting message-level breakpoints and to only add tool/system breakpoints when capacity remains. |
src/platform/endpoint/test/node/messagesApi.spec.ts |
Updates/extends tests to validate the new non-evicting behavior and slot-based tool/system prioritization. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
justschen
approved these changes
Mar 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cache rates for claude-opus-4.6-1m dropped dramatically because
addToolsAndSystemCacheControlwas evicting message-levelcache_controlentries to make room for tools+system breakpoints. Message breakpoints are more valuable in long agent conversations — they implicitly cache the tools+system prefix (Anthropic hierarchy: tools → system → messages) and maintain the 20-block lookback chain. Now tools+system breakpoints are only added when spare slots exist, never evicting message breakpoints.