Repository navigation
feat(cache-warming): Keep the prompt cache of idle Conversations warm - #2485
Draft
sentry-junior[bot] wants to merge 3 commits into
Draft
sentry-junior[bot] wants to merge 3 commits into
sentry-junior[bot] wants to merge 3 commits into
Conversation
…onversations Port the cache warmer from BYK/loreai. When a turn ends on an Anthropic model with a large cached prefix, Junior stores the request and sends a delayed queue message. Before the 5 minute TTL ends, the message replays the request with a one-token output limit, so the prefix stays cached. A reply-gap survival model with Lore's rising ROI threshold decides each next warmup. A breaker stops warmups for a model after cache misses. The feature is behind the cache-warming experimental flag. Co-Authored-By: Burak Yigit Kaya <126780+BYK@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Remove the experimental flag, so cache warming runs for every app. - Warm only anthropic/ models. OpenAI and xAI models also use the Anthropic Messages API on the gateway, but cache in other ways. - Skip models with budget thinking, because the budget adds output tokens to each one-token warmup. - Record each idle period once, also when no reply comes. A delayed horizon message records no reply after 55 minutes. Before, only replies were recorded, so the model overrated the reply chance. - Open the breaker at 3 misses in the last 20 warmups of a model. A success no longer resets it. The old reset deleted a normal key, so it did not clear the Redis list. - Delete the request snapshot when warmups stop, and keep it at most 55 minutes and 1 MB. - Skip state reads for mid-turn model calls after the first one. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com> Co-Authored-By: Burak Yigit Kaya <burak.kaya@sentry.io>
Warming stays on by default. Setting the switch to false stops Junior from storing requests and drops warmups that are already queued, so an operator can turn warming off without a revert or long cache retention. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
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.
Many prompt cache writes come from people who reply just after the 5 minute Anthropic cache TTL ends, so the next turn writes the full history again. This ports the cache warmer from BYK/loreai (
packages/gateway/src/cache-warmer.ts). It is on for every app.JUNIOR_CACHE_WARMING_ENABLED=falseis an operational kill switch, likeJUNIOR_CONVERSATION_WORK_ENABLED: it defaults totrue, stops storing requests, and drops warmups that are already queued.How it works:
stopReason: "stop") on ananthropic/model with a cached prefix of at least 50K tokens, Junior stores the exact provider context (gzip, max 1 MB) in theStateAdapterand sends two delayed, signed queue messages on a newjunior_cache_warmupstopic: the first warmup, and ahorizonmessage 55 minutes later.completeTextwithmaxTokens: 1. The cache read refreshes the TTL.k · read / (write − read), so warming stops by itself when it can no longer pay off. Warmups also stop at the 55 minute horizon.Cost guards:
anthropic/models. OpenAI and xAI models also use the Anthropic Messages API on the gateway, but cache differently.max_tokens: 1.horizonmessage records "no reply" when nobody replied in 55 minutes. Without this, only replies would be counted and the model would overrate the reply chance (Conversations that never get a reply would look like quick replies).PI_CACHE_RETENTION=longturns warming off.Not verified against the live AI Gateway: that
max_tokens: 1with Opus adaptive thinking is accepted and reads the same cache entry as the agent's request. If it does not, the breaker stops warmups after 3 misses per model. Thecache_warming.warmup.completed/.failedlogs show the outcome within the first hours.End-to-end coverage: tests that run the agent must be integration evals with Roach recordings, and the eval fixture's in-process queue does not deliver this topic. The flow (same prefix,
max_tokens: 1, stale-generation no-op, miss stops the period, horizon records no reply, breaker, OpenAI models skipped) was verified locally with a throwaway component test that is not committed.nitro.ts: the queue trigger setup was repeated for each topic, so it now uses one small helper for all four routes.via @BYK.
--
View Session [Sentry]