fix: prevent post-idle compaction from busting /keep sessions on 5m TTL#266
Merged
Conversation
isCacheWarm() now returns true unconditionally for /keep sessions that have received at least one warmup, preventing post-idle compaction from firing and busting the warmed cache prefix. shouldWarm() double-warm guard now uses a tighter cooldown (ttlMs - warmupMarginMs) in forced-keep mode so warmups fire every ~5m instead of ~10m on a 5m TTL, eliminating the dead zone where the conversation cache expired between warmups.
Prevent isCacheWarm from returning true indefinitely if the warmer stops (circuit breaker trip, process failure). Now checks lastWarmupAt is within 2x TTL instead of unconditional true. Also add Math.max guard on cooldownMs.
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
isCacheWarm()now returnstrueunconditionally for/keepsessions that have received at least one warmup, preventing post-idle compaction from firing and busting the warmed cache prefixshouldWarm()double-warm guard now uses a tighter cooldown (ttlMs - warmupMarginMs) in forced-keep mode, so warmups fire every ~5m instead of ~10m on a 5m TTL — eliminates the dead zone where the conversation cache expired between warmups/keepcooldown and verifying non-forced mode still uses the full TTL cooldownRoot Cause
Session
0IZRCvwuhvQcRgZWhad/keepactivated but was on 5-minute conversation TTL (only ~8 turns). Two compounding bugs:isCacheWarm()didn't account for/keep— it checked(now - lastWarmupAt) < ttlMs. Last warmup was 6.5 min before the user returned, exceeding the 5m TTL window, so it returnedfalseeven though the warmer was actively maintaining the session.Warmup cadence was 2x TTL — the double-warm guard blocked for a full
ttlMs(5m) after each warmup, but the margin window didn't align again until ~10 min later. The cache expired for ~5 min every cycle (confirmed by logs showing 42% hit rate on every warmup after the first).Result: user returned after 51 min idle →
isCacheWarmreturnedfalse→skipCompact=false→ post-idle compaction fired → cache busted → first turn after resume was only 40% cache hit.