Repository navigation
feat(app): default Anthropic prompt-cache TTL to 1h - #2102
Merged
Merged
Conversation
The built-in Anthropic Messages providers (anthropic, openrouter-anthropic, toolhive-anthropic) now share one rule in anthropicCacheTTLFor: with --anthropic-cache-ttl unset they stamp "ttl":"1h" on every cache_control marker, the longest lifetime Anthropic accepts. --anthropic-cache-ttl=5m restores the shorter, cheaper-to-write lifetime. Custom anthropic-messages providers keep the API default unless the flag is set, and --no-prompt-cache still emits no ttl so it reproduces the pre-ADR-0100 wire. OpenAI needs no change: pre-GPT-5.6 models already receive prompt_cache_retention=24h, and GPT-5.6+ accept only the 30m TTL, which is their default. Co-authored-by: Mecatl <[email protected]>
JAORMX
approved these changes
Oct 5, 2026
The flag table already states the default. Co-authored-by: Mecatl <[email protected]>
JAORMX
approved these changes
Oct 5, 2026
Merged
2 tasks
This branch was successfully deployed
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
1h, instead of the API default of5m. Sessions with gaps longer than 5 minutes between requests no longer lose their cached prefix.anthropic,openrouter-anthropicandtoolhive-anthropic— get the TTL from one rule,anthropicCacheTTLForininternal/app/promptcache.go, so they cannot diverge. The rule depends on the provider ID only, so a base-URL override does not change it.--anthropic-cache-ttlflag is the knob for going back:--anthropic-cache-ttl=5mrestores the shorter, cheaper-to-write lifetime. An operator value applies to every Anthropic Messages provider, as before.anthropic-messagesproviders keep the API default unless the flag is set, because an unknown compatible endpoint may rejectttl.--no-prompt-cachestill emits nottl, so it keeps reproducing the pre-ADR-0100 wire byte-for-byte.prompt_cache_retention: "24h"(provider/openai/cache.go), and GPT-5.6+ accept only the30mTTL, which is their default. OpenRouter's Responses surface cannot express a TTL.Provider documentation checked:
ttlis5m(default) or1h. The 1-hour TTL is generally available and needs only thettlfield, with noanthropic-betaheader. 1h writes cost 2× base input, against 1.25× for 5m; reads cost the same."ttl": "1h".24hretention before GPT-5.6;30mis the only value from GPT-5.6 on.Development stage
and the in-PR plan declares
**Expected tasks:** 1, a non-placeholder**Combined rationale:**, and no runtime/public/operator/persistence/trust-boundaryinterface change (
None — rationale; workflow-only meta-changes may review processdocs/skills here)
Contract linkage
--anthropic-cache-ttl=5m. However, ADR 0100 records "default = API default" for this TTL and the default changes cost behavior, so a reviewer may classify it Bounded/Architectural. See the reviewer notes.anthropic,openrouter-anthropicandtoolhive-anthropic, with one shared ruleInterface conformance
--anthropic-cache-ttlkeeps its accepted values (5m,1h); only the meaning of the unset value changes for the three built-in Anthropic Messages providers.Issue relationship
None.
Type of change
Test plan
Baseline checks
task lint) — timed out locally at 10 minutes; relying on CI.go vetandgofmtare clean on the touched packages.task test) — not run in full. The prompt-cache, ToolHive and OpenRouter-Anthropic tests ininternal/apppass. Three otherinternal/appfailures reproduce identically with this change stashed (TestYoloRelativeEscapeTools,TestYoloRelativeEscapeAuthorityUsesPhysicalTarget,TestCanonicalConfiguredDir_AllowsMissingDefaultParents), as do twocmd/mecatuiexit-handoff tests that fail because the worktree path is too long for a Unix socket.task test:race) — not run locallygo run ./cmd/mecademo)task docs)task site:build) — not run locallytask api:check) — N/A, no engine changetask api:update+engine/CHANGELOG.md— N/Atask ac-trace-strict) — N/A/panel-reviewNew and updated tests:
TestAnthropicCacheTTLDefault: runs identical cases against all three built-in providers (unset →1h, operator5m/1hwins,--no-prompt-cache→ nottl), and checks that custom providers keep the API default.TestAnthropicCacheTTLDefaultsToOneHourOnBuiltinProviders: builds each real provider against a local server and checks that everycache_controlmarker in the body carries1h(unset) or5m(flag).TestADR_0346_AnthropicCacheTTLStampedOnOpenRouterAnthropic: now expects1hwhen the flag is unset.A temporary wire capture (not committed) confirmed that all three providers send
POST /v1/messageswithanthropic-version: 2023-06-01, noanthropic-betaheader, and{"type":"ephemeral","ttl":"1h"}on every marker.Changes
internal/app/promptcache.goanthropicCacheTTLFor: the one shared TTL ruleinternal/app/registry.gointernal/app/build.goAnthropicCacheTTLdoc commentinternal/app/promptcache_test.go,promptcache_breakpoint_e2e_test.gocmd/mecated/main.go,cmd/mecak8s/flags.go,cmd/mecatui/config.gouser-docs/building/what-you-get/observability.mduser-docs/building/deployment/mecated.md,user-docs/features/choose-models.mdUser-facing change
With
--anthropic-cache-ttlunset, sessions onanthropic,openrouter-anthropicandtoolhive-anthropicnow cache prompts for 1 hour instead of 5 minutes. Cache writes cost 2× base input instead of 1.25×; reads are unchanged. Set--anthropic-cache-ttl=5mfor the previous behavior.Special notes for reviewers
ttlfield is omitted. This PR changes that default for the built-in providers. Please decide whether this needs a superseding ADR (Bounded/Architectural) or whether Routine is acceptable.anthropicandopenrouter-anthropicwith an overridden base URL now also send1h. This matchestoolhive-anthropic, whose base URL is always derived. Customanthropic-messagesproviders are excluded.