Skip to content

Disk KV cache: cold/evict checkpoints get no eviction-score advantage over continued #176

@unsaltedbutter-ai

Description

@unsaltedbutter-ai

TL;DR

kv_entry_eviction_score is (hits+1) * tokens / size regardless of reason. A freshly written cold or evict checkpoint loses the eviction race to a competing workload's fresh continued snapshots on density alone. In production a 1.3 GiB live-state save died within ~5 min while a second conversation prefilled.

How it fails today

When conversation B writes a continued, A will have a cold, an evict, & a continued on disk.
The score function gives all three the same weight, so the victim depends on incidental density differences and not on intent. If cold & evict were boosted, the continued would be the consistent target.
Then if conversation A resumes right where it left off the evict would cache hit and a significant amount of prefill time would be avoided.

In a production case the live-state evict was 1.3 GiB and got unlinked after 5m 19s while B prefilled.

Proposed fix

Bump the base from 1.0 to 4.0 for KV_REASON_COLD | EVICT | SHUTDOWN in kv_entry_eviction_score. Continued and unknown stay at 1.0. A continued must serve three real hits before outranking a fresh same-shape checkpoint. Existing hit decay still applies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions