Repository navigation
perf(provider): prompt-cache breakpoints for Anthropic Messages and Bedrock Converse (C4) - #61
Merged
lg2m merged 2 commits intoSep 17, 2026
Conversation
…and Bedrock Converse (C4) Neither codec asked the provider to cache anything, so every turn of a long Anthropic or Bedrock session re-processed the full transcript uncached: time to first token grew linearly with context and input cost was roughly an order of magnitude higher than it needed to be. Both providers require explicit breakpoints. Anthropic Messages now sends the system prompt as one text block with `cache_control: ephemeral`, marks the last tool declaration and the last block of the last message, and leaves everything else unmarked so consecutive turns extend one cached prefix. Bedrock Converse places the equivalent `cachePoint` blocks at the same three positions, gated to the Anthropic model family (regional, global, and inference-profile ids) because Converse rejects the block for families without prompt caching. `ResolvedModel.prompt_cache.control` reports `Native` for both APIs. Wire change: single-text Anthropic messages serialize as block arrays. `provider_encode` anthropic 195 → 204 µs on a 1.1 MiB body.
…r-turn call cap (C5) (#62) A turn with one edit and five reads ran all six in series; a turn naming seventeen calls killed the run with a provider-protocol failure. Every reference harness overlaps read-only calls and none fails a run for batching well. The tool phase now splits the turn at the first call that is not an overlappable read: the leading reads run under MAX_PARALLEL_READS, the rest in request order, so a read after a mutation is still ordered against it. Calls past the sixteenth are admitted with a not-executed tool error that tells the model to re-issue them; a turn naming more than 64 calls remains a protocol failure. Prompt version 14 asks the model to batch independent calls and names the cap.
lg2m
force-pushed
the
perf/context-usability-4-cache-breakpoints
branch
from
September 17, 2026 01:50
d595eee to
55ea7a7
Compare
This was referenced Sep 17, 2026
Merged
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.
C4:
cache_control/cachePointon system, last tool, last message blockSpec: docs/plans/context-usability.md § C4. Stacked on #59 (C3); review against that base.
User-visible behavior
Anthropic and Bedrock-Anthropic sessions get provider prompt caching. Before,
qq-provideremitted no cache markers, so every turn re-processed the entire transcript: TTFT grew linearly with context and input tokens were billed at full price each turn. pi, fx, OpenCode, and Codex all mark the same three positions.What changed
providers/anthropic.rs:systemis one text block withcache_control: {type: ephemeral}; the lasttools[]entry and the last content block of the last message carry the same marker; nothing else does, so turn N+1 extends turn N's cached prefix. Wire change: single-text messages serialize as[{type: text, …}]arrays rather than bare strings (both accepted by the API).providers/bedrock.rs:SystemContentBlock::CachePoint,Tool::CachePoint,ContentBlock::CachePointat the same three positions, only when the model id has ananthropicsegment (anthropic.,us.anthropic.,global.anthropic., inference-profile ARNs). Nova/Llama/Mistral/OpenAI-OSS are untouched because Converse rejectscachePointfor them.src/runtime.rs:ResolvedModel.prompt_cache.control = NativeforAnthropicMessagesandBedrockConverse.How verified
cargo test --workspace;cargo test -p qq-provider --no-default-features --features test-support(minimal profile); fmt; strict all-target clippy.anthropic::cache_breakpoints_mark_exactly_the_system_last_tool_and_last_block(exactly three markers on a two-tool, three-message request);bedrock::maps_the_system_prompt_to_converse_system_blocks_with_a_cache_point;bedrock::cache_points_follow_the_anthropic_family_and_no_other; rootresolved_modelassertsNativefor Bedrock.controlis an existing enum).Measurements
provider_encodeanthropic, 1 MiB + 32 schemasLive
cache_read_input_tokens > 0on turn 2 is a paid check; not run here.Docs
docs/design/providers.md(codec breakpoint rule); ledger.