Skip to content

fix: strip CacheControl from messages during compaction#2236

Merged
dgageot merged 1 commit into
docker:mainfrom
dgageot:board/cache-control-blocks-limit-in-anthropic-a48b23eb
Mar 25, 2026
Merged

fix: strip CacheControl from messages during compaction#2236
dgageot merged 1 commit into
docker:mainfrom
dgageot:board/cache-control-blocks-limit-in-anthropic-a48b23eb

Conversation

@dgageot

@dgageot dgageot commented Mar 25, 2026

Copy link
Copy Markdown
Member

When compaction runs, doCompact calls sess.GetMessages(a) which returns messages with CacheControl=true on the last invariant and last context system messages. These markers were preserved through compaction.BuildPrompt into the summarization session, which then added its own system message marker plus 2 more from applyMessageCacheControl, totaling 5 cache control breakpoints — exceeding Anthropic's limit of 4.

Fix: Strip CacheControl from cloned messages in BuildPrompt, just like Cost is already zeroed.

When compaction runs, the original session's system messages carry
CacheControl=true markers. These were preserved through BuildPrompt
into the summarization session, which then added its own markers plus
applyMessageCacheControl's 2 markers, exceeding Anthropic's limit of 4
cache control breakpoints.

Assisted-By: docker-agent
@dgageot
dgageot requested a review from a team as a code owner March 25, 2026 07:02
@dgageot
dgageot merged commit 513e243 into docker:main Mar 25, 2026
8 checks passed
Sayt-0 pushed a commit that referenced this pull request Jul 17, 2026
… the limit

The 4-breakpoint budget was an implicit cross-layer contract: the
session marks up to two system messages and the provider spends the
rest, but nothing enforced the global invariant \u2014 a third upstream
mark (e.g. from a hook-rewritten message list) would produce a request
Anthropic rejects outright (the failure mode of #2236).

Own the whole budget in cache_control.go: document the ledger and cap
honored system marks at maxSystemCacheBreakpoints, dropping the excess
instead of forwarding it. Behavior is unchanged for compliant input.
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.

2 participants