Skip to content

plan: ask for the prompt cache through the protocol, not the vendor (ADR 0346) - #1572

Merged
aponcedeleonch merged 2 commits into
mainfrom
plan/unified-prompt-cache-dialect
Sep 17, 2026
Merged

aponcedeleonch merged 2 commits into
mainfrom
plan/unified-prompt-cache-dialect

Conversation

@aponcedeleonch

@aponcedeleonch aponcedeleonch commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

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_breakpoint is 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

  • Plan / Interface — Bounded/Architectural behavioral and exact-interface contract; no implementation
  • Implementation — based on an approved, merged Plan / Interface PR
  • Combined — compact one-task Bounded/Architectural exception
  • Spike / Routine — acceptance-plan spine exempt

Contract linkage

  • Work classification: Architectural
  • Classification rationale: adds a wire-stable provider identity, changes default-provider precedence, alters what identifying material mecatl transmits to third-party endpoints, and retires one ADR 0100 deferral.
  • Decision record: ADR 0346 — supersedes three ADR 0100 decisions (its prompt_cache_breakpoint deferral, its OpenRouter-only root cache_control arm, and its OpenRouter TTL deferral) and extends ADR 0334 to OpenRouter.
  • Human waiver of spine: No
  • Acceptance plan: docs/acceptance/unified-prompt-cache-dialect.md — proposed
  • Human decisions resolved and recorded: Yes, all six, recorded inline with their outcomes
  • Plan / Interface PR: this PR
  • Approved commit baseline: N/A for a plan PR
  • Combined/exemption rationale: N/A — Split

Interface conformance

The exact interface contract under review:

  • gRPC / protobuf: one added field, bool prompt_cached = 7 on ModelInfo (numbers 1-6 unchanged; additive, an older client reads false).
  • Exported Go APIs: provider/openai — Added WithPromptCacheBreakpoints(bool) and WithCacheKeySalt(string); Changed in that CacheDialectOpenRouter no longer emits root cache_control. Both new Options default off, so a consumer passing none keeps the pre-ADR-0343 wire.
  • CLI / config: no new flag or key. --no-prompt-cache is now the breakpoint switch too. One OpenRouter credential registers both openrouter and openrouter-anthropic; the new id is reserved against custom-provider collisions.
  • Events / persistence: none. The cache-key salt is process-local and never persisted.
  • Security / authority: the breakpoint is a fixed protocol constant carrying no user, model, or config value, so it opens no injection surface. The derived Anthropic base is built with net/url. The salted key removes cross-principal correlation.
  • Tool schemas: none.
  • Compatibility / migration: the emitted Responses body changes for every request, shifting the cached prefix once.

Issue relationship

Tracking: #1558

Type of change

  • Behavioral/interface plan
  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation/process
  • Other (describe):

Test plan

Baseline checks

  • Acceptance-plan checker — passes, plus its regression fixtures
  • Linting (task lint) — no Go changes in this PR
  • Offline test suite (task test) — no Go changes in this PR
  • Offline demo (go run ./cmd/mecademo) — no runtime change in this PR
  • Markdown changed: docs generation/link checks (task docs) — clean, 416 documents / 3774 references, zero broken links or anchors
  • User docs/user-facing behavior changed: site build — user-docs change ships in the implementation PR
  • Guarded engine API affected: compatibility check — no engine API change
  • Intentional engine API change
  • Landed plan: strict acceptance trace — not landed
  • Final implementation review: /panel-review — belongs on the implementation PR

Changes

File Change
docs/adr/0346-unified-prompt-cache-dialect.md New. The durable decision, plus the rejected alternative and why
docs/acceptance/unified-prompt-cache-dialect.md New. 5 scenarios, 22 ACs with named proofs, all seven interface categories
docs/adr/README.md, docs/acceptance/README.md Index entries

User-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 directBaseURL is the one derivation of a request URL from gateway_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

@aponcedeleonch aponcedeleonch changed the title plan/unified prompt cache dialect plan: Claude prompt caching via native Messages routing (ADR 0343) Sep 15, 2026
@aponcedeleonch
aponcedeleonch marked this pull request as ready for review September 15, 2026 16:08
@aponcedeleonch aponcedeleonch changed the title plan: Claude prompt caching via native Messages routing (ADR 0343) plan: ask for the prompt cache through the protocol, not the vendor (ADR 0343) Sep 16, 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]>
@aponcedeleonch
aponcedeleonch force-pushed the plan/unified-prompt-cache-dialect branch from 0798398 to 8acdc3c Compare September 16, 2026 16:09
@aponcedeleonch aponcedeleonch changed the title plan: ask for the prompt cache through the protocol, not the vendor (ADR 0343) plan: ask for the prompt cache through the protocol, not the vendor (ADR 0346) Sep 16, 2026
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]>
@aponcedeleonch
aponcedeleonch merged commit a8dc61e into main Sep 17, 2026
29 checks passed
@aponcedeleonch
aponcedeleonch deleted the plan/unified-prompt-cache-dialect branch September 17, 2026 11:44
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Sep 21, 2026
2 tasks
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.

3 participants