Repository navigation
server: fix checkpoint handling for hybrid memory models - #24797
AntmanLFEz wants to merge 1 commit into
Conversation
|
I can confirm from my testing that this has resolved most of the cache invalidation issue I've had with qwen3.6 35B. I'm seeing zero full 'cache re-processing' messages, though I am still seeing occasional large prompts being processed (70%+), maybe just expected with openclaw. I don't understand why this is or what cases cause this, but it's rare enough (1/15 messages or less) I'm no longer concerned. Previously I'd expect at a certain point that every message is fully reprocessing the prompt. I have run initial tests within the following environments: Environment:
Software stack:
Run command:
NOTE: Some important command line arguments were initially tested and then removed: I had single sessions running contexts up to 80k tokens, and multiple parallel sessions running between 40k and 70k tokens each, some misses when running many parallel sessions which seemed to show the message Note I haven't reviewed the code in detail and can't claim to understand it, though I'm willing to validate against various models on my setup as described above. |
|
This change is obviously wrong - the recurrent state is valid only for the latest position and using it with any other position is incorrect. |
Overview
This PR fixes prompt cache invalidation on hybrid models (such as Qwen3.5/Qwen3.6) where any minor prompt variation (thinking content stripped, injected timestamp, etc.) caused a full prompt re-processing to occur, effectively disabling prompt caching.
Thee server logs would consistently show the following with most agent harness's between turns:
Related issues: #21831, #23013, #22746, #24714, #24055
Additional information
Hybrid memory consists of two independent cache subsystems with fundamentally different positional semantics:
pos_min= earliest cached KV positionpos_min= current state position (one cell per sequence), sopos_min == pos_max == current_position(always the latest)The previous
seq_pos_min()implementation tookstd::max()of both caches' min positions, which conflated these semantics. This inflatedpos_minto the latest position, making it appear as though no prefix was cached and forcing full prompt re-processing on any minor variation.Solution
pos_min, matching non-hybrid memory semantics.seq_pos_maxstill retains intersection semantics because it bounds valid attention entries by where the recurrent state has advanced.Additional hardening:
n_rs_seq, the recurrent cache now falls through to normal cell removal instead of returningfalse. This prevents hybridseq_rmfrom failing and leaving the attention cache with stale entries. The trade-off is the recurrent state loses precise snapshot restoration, but the KV cache is correctly trimmed. The model re-processes from the last valid checkpoint, producing correct results with slightly higher latency during speculative decoding only.Note that other hybrid types with recurrent memory would likely benefit from the same
seq_pos_min()change, though I have not explicitly tested those models yet.Requirements