Skip to content

Anthropic: a fourth cache breakpoint where the previous request ended - #21

Merged
ayman3000 merged 1 commit into
mainfrom
anthropic-previous-turn-breakpoint
Oct 9, 2026
Merged

ayman3000 merged 1 commit into
mainfrom
anthropic-previous-turn-breakpoint

Conversation

@ayman3000

Copy link
Copy Markdown
Owner

The single moving cache_control breakpoint on the last message could miss the previous request's cache entry after a step with many parallel tool calls (Anthropic's lookup walks back about 20 blocks).

  • New AnthropicProvider.markingPreviousTurnForCache: marks the last block of the entry right before the newest assistant turn — where the previous request ended.
  • Runs after mergingConsecutiveRoles, so it lands on merged entries (parallel tool results get one marker, on the merged entry's last block).
  • Total markers: tools + system + previous turn + last message = 4, Anthropic's limit. First message (no assistant yet) stays at 2–3.
  • Deterministic: same conversation, same body.
  • Tests: new AnthropicCacheBreakpointTests (6 tests); anthropicRequestCarriesCacheBreakpoints updated to the new rule.

🤖 Generated with Claude Code

The single moving breakpoint on the last message could not reach the
previous request's cache entry after a step with many parallel tool calls
(the lookup walks back about 20 blocks). The last block of the message
before the newest assistant turn now carries one too: tools, system,
previous turn and last message — four, the limit. Placed after
mergingConsecutiveRoles, so it lands on the merged entry's last block.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ayman3000
ayman3000 merged commit 8e9284d into main Oct 9, 2026
1 check passed
@ayman3000
ayman3000 deleted the anthropic-previous-turn-breakpoint branch October 9, 2026 08:33
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