-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
feat: prompt cache keep-warm pings to prevent TTL expiry between turns #62475
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.issue-rating: 🌊 off-meta tidepoolIssue quality rating does not apply to this item.Issue quality rating does not apply to this item.staleMarked as stale due to inactivityMarked as stale due to inactivity
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.issue-rating: 🌊 off-meta tidepoolIssue quality rating does not apply to this item.Issue quality rating does not apply to this item.staleMarked as stale due to inactivityMarked as stale due to inactivity
Type
Fields
Priority
None yet
Problem
Anthropic prompt cache expires after ~5 min (
cacheRetention: "short") or ~1 hour (cacheRetention: "long"). Between user messages, when no API call occurs, the cache goes cold. The next turn re-caches the entire system prompt prefix + conversation history at write pricing ($3.75/MTok) instead of read pricing ($0.375/MTok) — a 10× cost multiplier on every cache miss.For sessions with moderate inter-message gaps (5–60 min), this is the dominant cost driver. A typical 84k system prompt + 80k conversation history = ~164k cached tokens. Each cache miss costs $0.62 vs a cache hit at $0.062.
Prior Art
This resurrects the core idea from #24711 (closed/stale) and addresses part of #57569 (cache pre-warming after reconnect).
Proposed Solution
A lightweight, invisible, non-turn mechanism that fires minimal API pings (
max_tokens: 1) to keep the prompt cache warm between user interactions.Key Design Decisions
TTL × 0.8(4 min for short, ~48 min for long). Not user-configurable — eliminates misconfiguration class.cache_read_input_tokensin ping response to confirm cache hit.$0.10/hr, auto-disables if exceeded.resolveAnthropicPayloadPolicy()+applyAnthropicCacheControlToSystem()to match the cache key exactly.Config
Lifecycle
PromptCacheSnapshot, start interval timerBuild-On Opportunity
PR #56575 already adds session timestamps (
lastUserMessageAt,lastAssistantMessageAt,lastCacheTouchAt) and a gateway maintenance sweep timer. This feature could be implemented as an additional mode ("ping") alongside the existing"compact"and"reset"modes, reusing the timer infrastructure.PR #62179 (exposes
runtimeContext.promptCacheto context engines) provides the cache-break detection needed for dirty flag awareness.Cost Analysis
With
cacheRetention: "long", keep-warm fires ~1 ping per gap period. Break-even at 1 avoided cache miss per session.Provider Abstraction
max_tokens: 1(no lighter endpoint exists)Upstream Dream Ask
An Anthropic
POST /cache/refreshendpoint that extends TTL without requiring a full message payload would reduce ping cost ~99%.References