Repository navigation
plan: ask for the prompt cache through the protocol, not the vendor (ADR 0346) - #1572
Merged
Merged
Conversation
Merged
10 of 21 tasks
aponcedeleonch
marked this pull request as ready for review
September 15, 2026 16:08
JAORMX
approved these changes
Sep 15, 2026
…ADR 0346) Acceptance contract for #1558. Some upstreams cache a prompt prefix only when the caller explicitly asks. ADR 0100 gated the Responses adapter's cache hints on a two-row allowlist of endpoint identities, so every other endpoint emitted nothing: free for an implicit cacher, roughly 10x for one that needs asking. Found in production, a budget exhausted in two hours on Claude Opus 4.8 through the ToolHive gateway with cache reads at zero. The decision is to ask through the protocol and never consult the vendor. ResponseInputTextParam.PromptCacheBreakpoint is a typed field in openai-go v3.61.0, retiring ADR 0100's stated reason for deferring it, and explicit breakpoints are additive to implicit caching by specification, so one marker is legal on every request. An implicit cacher gets both, an explicit-ask upstream gets the ask, and an endpoint that does not implement the field ignores it. A future vendor with the same semantics is covered with no code change. The failure direction is what makes a vendor-free rule affordable. The breakpoint is part of the protocol, so a wrong guess is an ignored field; root cache_control was an OpenRouter extension, so a wrong guess was a 400 and therefore a hard outage. Root cache_control is retired. Two alternatives are recorded as rejected. An operator-declared dialect permission asks an operator to assert a remote, mutable property whose wrong value is an outage. A vendor-family matcher breaks when a second vendor ships explicit-ask caching, and is already wrong on live data: one staging gateway exposes a single Claude Opus 4.8 under four ids depending on the downstream it routes to. That same measurement is why the ToolHive sibling redirect is not taken, since those surfaces do not share an id namespace. One carve-out, on documented strictness rather than vendor: the canonical OpenAI endpoint consults the model table retentionFor already maintains, because OpenAI documents explicit breakpoints as gpt-5.6+ and states neither ignore nor reject for earlier models. Messages routing is kept for the OpenRouter pair on measured evidence: 1.44B cache-read tokens against the Responses path's zero. Relates to #1558 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
JAORMX
approved these changes
Sep 16, 2026
aponcedeleonch
force-pushed
the
plan/unified-prompt-cache-dialect
branch
from
September 16, 2026 16:09
0798398 to
8acdc3c
Compare
Both were true of an earlier draft and false of the decision that shipped. The accepted-risk bound named the per-endpoint dialect alongside --no-prompt-cache. Decision 1 detaches the breakpoint from the dialect on purpose, and cacheDialectFor only ever returns CacheDialectOpenAI for the canonical endpoint with an empty base URL, so an unclassified endpoint can never reach the suppressing branch. The flag is the only bound, which matters because this is the sentence an operator reads while a strict endpoint is rejecting every request. The sibling asymmetry claimed only one of two provider ids caches. After decision 1 both ask for a cache; what differs is quality, four breakpoints and a TTL on Messages against one breakpoint on Responses. Decision 6's own justification already says this three paragraphs earlier, so only the Consequences restatement was stale. The picker clause went with it: the marker no longer tracks that asymmetry, it tracks --no-prompt-cache. Consequences only. No decision text changes and the ADR stays Proposed, so no supersede is owed. Relates to #1558 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
jhrozek
approved these changes
Sep 17, 2026
Merged
2 tasks
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.
Summary
The acceptance contract for #1558. Some upstreams cache a prompt prefix only when the caller explicitly asks. ADR 0100 gated the Responses adapter's cache hints on a two-row allowlist of endpoint identities, so every other endpoint emitted nothing: free for an implicit cacher, roughly 10x for one that needs asking. Found in production, a budget exhausted in two hours on Claude Opus 4.8 through the ToolHive gateway with cache reads at zero.
The decision is to ask through the protocol and never consult the vendor.
prompt_cache_breakpointis a typed field in openai-go v3.61.0, and explicit breakpoints are additive to implicit caching by specification, so one marker is legal on every request. An implicit cacher gets both, an explicit-ask upstream gets the ask, an endpoint that does not implement it ignores it. A future vendor with the same semantics is covered with no code change.This revision replaced an earlier routing-only design after measuring staging. Implementation is stacked on top of this PR. Merging this PR is the approval event.
Development stage
Contract linkage
prompt_cache_breakpointdeferral, its OpenRouter-only rootcache_controlarm, and its OpenRouter TTL deferral) and extends ADR 0334 to OpenRouter.proposedInterface conformance
The exact interface contract under review:
bool prompt_cached = 7onModelInfo(numbers 1-6 unchanged; additive, an older client reads false).provider/openai— AddedWithPromptCacheBreakpoints(bool)andWithCacheKeySalt(string); Changed in thatCacheDialectOpenRouterno longer emits rootcache_control. Both new Options default off, so a consumer passing none keeps the pre-ADR-0343 wire.--no-prompt-cacheis now the breakpoint switch too. One OpenRouter credential registers bothopenrouterandopenrouter-anthropic; the new id is reserved against custom-provider collisions.net/url. The salted key removes cross-principal correlation.Issue relationship
Tracking: #1558
Type of change
Test plan
Baseline checks
task lint) — no Go changes in this PRtask test) — no Go changes in this PRgo run ./cmd/mecademo) — no runtime change in this PRtask docs) — clean, 416 documents / 3774 references, zero broken links or anchorslanded/panel-review— belongs on the implementation PRChanges
docs/adr/0346-unified-prompt-cache-dialect.mddocs/acceptance/unified-prompt-cache-dialect.mddocs/adr/README.md,docs/acceptance/README.mdUser-facing change
None in this PR. The behaviour it contracts is user-facing and lands in the stacked implementation PR.
Special notes for reviewers
Two alternatives are recorded as rejected, and both rejections are the substance of this PR.
An operator-declared dialect permission: asks an operator to assert a property of a remote, mutable routing decision, and a wrong assertion is a hard outage under
llmresilience's non-retryable-4xx rule.A vendor-family matcher on
anthropic/claude: breaks the moment a second vendor ships explicit-ask caching, and it is already wrong on live data. One staging gateway exposes a single Claude Opus 4.8 under four ids at once, depending on which downstream it routes to. That same evidence is why the ToolHive sibling redirect was dropped: those surfaces do not share an id namespace, so a provider-only switch cannot resolve.Measured, not argued. Three hours of staging usage records are in the ADR's Context: the Messages protocol pulled 1.44B cache-read tokens while the OpenRouter downstream pulled zero across 175 requests. That is why Messages routing is kept where ids are shared, and why breakpoints are the floor everywhere else.
Three advisory reviews ran against an earlier draft (adversarial, architecture, security). The architect's "premature abstraction" warning turned out to be right from a direction none of us started from: the whole declaration mechanism is gone. Two findings survived into this design: salting the prompt-cache key, and a correction I had wrong — direct mode's
directBaseURLis the one derivation of a request URL fromgateway_url, so ADR 0100's "display-only" property is proxy-mode-scoped.One open item, deliberately not resolved. OpenAI documents explicit breakpoints as gpt-5.6+ and says of earlier models only "Only implicit caching is supported" — neither ignore nor reject. Decision 2 keeps a conservative carve-out for that one endpoint. A live probe deletes or justifies it; I did not spend real money to find out.
🤖 Generated with Claude Code