Protect incoming KV prefix during live miss#448
Open
JordiPosthumus wants to merge 1 commit into
Open
Conversation
Contributor
|
Can you please fix your PR text? It's garbled. There are still humans reading PRs... (maybe not for long, though) |
Author
|
ok, I spoke to my people ! Better? :-D |
srinathh
added a commit
to srinathh/ds4
that referenced
this pull request
Jul 4, 2026
Reduce --kv-disk-space-mb 409600 -> 4096. 2 GiB was too tight (a single 1.9 GiB heartbeat-context checkpoint filled the budget, leaving no room for antirez#448/recency to protect prefixes). 4 GiB holds the heartbeat checkpoint plus a working set of ~35k conversation prefix chains, so eviction pressure comes from accumulation while leaving headroom for the fixes. Revert before prod/ tag. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
srinathh
added a commit
to srinathh/ds4
that referenced
this pull request
Jul 4, 2026
The eviction score (hits+1)*tokens/file_size has no recency reward, so a just-written prefix waypoint scores ~the same as a stale one and loses to larger files on density. Under budget pressure the small, recent waypoints the next turn will reuse are evicted first, and a later live miss cold-reprefills even though a valid disk prefix existed moments earlier (antirez#444). Add a recency gate in ds4_kvstore_entry_eviction_score, reusing the existing used_at (last_used or created_at) and hit half-life, no new persistent state: - a decaying recency boost (1 + K*2^(-age/halflife)) so recent waypoints outscore stale entries of the same density; - gate the ec6a82a superseded-continued devaluation on !recent, so a recent waypoint the next turn may still need is not devalued mid-conversation. Complements PR antirez#448: antirez#448 protects the incoming prompt's prefix during the pre-fallback store; the recency gate protects recent prefixes during the prefill continued-stores too. Adds test_kv_cache_eviction_keeps_recent_over_stale. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
srinathh
added a commit
to srinathh/ds4
that referenced
this pull request
Jul 4, 2026
Down from 400 GB. The recency gate (previous commit) keeps recent shared prefixes alive under eviction pressure, so a leaner budget is viable. Ships the recency gate to production; upstream PR antirez#448 intentionally NOT included. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Why
On a live-cache miss, ds4-server stores the old live checkpoint before trying to load a disk fallback. Under disk pressure, that store can evict a checkpoint that prefixes the incoming prompt. When that happens, ds4 has to cold-prefill even though a valid disk fallback existed.
This change gives those incoming-prompt prefix checkpoints a very high eviction score during the pre-fallback store, so unrelated cache entries are evicted first.
Test