fix(cache-warmer): tighten warming heuristics to reduce net negative spend#429
Merged
Conversation
…spend Cache warming was net negative ($11.18 spent, $5.52 saved). Five targeted fixes to the decision heuristics: 1. Raise initial commitment threshold floor to 30% P(returns), up from the break-even ratio of 4-9% which was trivially exceeded by nearly every session. 2. Cap tool-call warming at 2 cycles (was unlimited up to 30 min). Most tool calls complete in <5 minutes; also reduce MAX_TOOL_CALL_WARMING_MS from 30 to 10 minutes. 3. Raise MIN_TURNS_FOR_WARMING from 3 to 5. Sessions with <5 turns have insufficient survival model data and are more likely one-shots. 4. Add MIN_INPUT_TOKENS_FOR_WARMING (50K). Below this threshold, absolute savings per hit are too small to justify the risk of wasted warmups. 5. Tighten session-level ROI check: kick in at 5 warmups (was 10) and require 25% hit rate (was 20%).
902406b to
f061d38
Compare
This was referenced May 21, 2026
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.
Problem
Cache warming was net negative: $11.18 spent on warmup pings but only $5.52 saved from cache hits (net loss: $5.66). The system was too eager — warming sessions that don't return, warming too many cycles during tool calls, and accepting trivially low return probabilities.
Root Causes (from live dashboard data)
Fixes
1. Initial commitment threshold floor (HIGHEST IMPACT)
P(returns)must now exceed 30% (was 4-9% break-even ratio). Prevents cascading continuation chains on marginal sessions.2. Tool-call warming cap
TOOL_CALL_MAX_CYCLES = 2(was unlimited up to break-even)MAX_TOOL_CALL_WARMING_MS: 30min -> 10min3. Higher minimum turn count
MIN_TURNS_FOR_WARMING: 3 -> 5 (requires 10 messages). Ensures sufficient survival model data.4. Minimum context size gate
New
MIN_INPUT_TOKENS_FOR_WARMING = 50,000. Below this, absolute savings per hit are too small to justify risk. Force-keep path is exempt.5. Tighter session-level ROI check
MIN_WARMUPS_FOR_ROI_CHECK: 10 -> 5 (kicks in sooner)MIN_SESSION_HIT_RATE: 20% -> 25% (stricter bar)Files Changed
packages/gateway/src/cache-warmer.ts— 5 constant changes, 3 new gates inshouldWarm(), dashboard reason stringspackages/gateway/src/idle.ts— context size early-exit + importpackages/gateway/test/cache-warmer.test.ts— 3 existing tests updated, 10 new testspackages/gateway/test/helpers/idle-worker.ts— mock updated for new exportsExpected Impact
Estimated ~37-49 fewer wasted warmups per cycle, saving $3.70-4.90 against the $5.66 net loss. Should flip warming to net positive as only profitable sessions get warmed.
What we're NOT changing
pSessionFinished()base rate — the 30% threshold floor addresses the same problem more directly