Problem
When context compression is triggered (at contextPercentageThreshold), qwen-code sends a summarized conversation history to the llama-server. This summary is a different token sequence from the original, causing:
- Full cache miss — the server's LCP (longest common prefix) matching finds no reusable cached state
- Full re-prefill — the entire summarized context must be reprocessed from scratch
- Wasted compute — on long sessions (50K+ tokens), this is a significant re-prefill cost (often 100+ seconds on local hardware)
The server's prompt cache becomes useless at exactly the moment it would be most valuable.
Proposed Solution
llama.cpp server already exposes a slot state save/restore API:
POST /slots/{id_slot}/save — saves full slot state (KV cache + recurrent state) to a file
POST /slots/{id_slot}/restore — restores from that file and continues
Instead of text-based compression, qwen-code could:
- Before context limit is reached → call
/slots/0/save to snapshot the current model state
- When compression would normally trigger → call
/slots/0/restore + send only the new tokens since the snapshot
- The server resumes from the exact model state — zero re-prefill of prior context
This would replace "summarize history → resend full text" with "snapshot state → append new tokens".
Why This Is Especially Valuable for Qwen3.6-series Models
Qwen3.6-35B-A3B (and similar hybrid recurrent-transformer models) maintain a fixed-size recurrent state that already encodes a compressed representation of all past context. This state is exactly what is saved/restored by the slot API.
- The recurrent state IS a lossless (for the model's learned compression) summary of past context
- Saving and restoring it is architecturally more faithful than text summarization
- llama.cpp PR #24785 recently improved recurrent state correctness during prompt cache operations, making this approach more reliable now
Current Workaround
Users working with local llama.cpp backends currently maintain external markdown files (PROGRESS.md, QWEN.md) to manually persist context across compression boundaries — effectively a manual implementation of what MemGPT/Letta does with external memory. The slot API approach would make this unnecessary for within-session continuity.
Implementation Notes
- llama.cpp slot save path is configurable (
--slot-save-path)
- The saved state includes both KV cache and recurrent state
- State files are ~60-500 MiB depending on context length and model size
- qwen-code would need to track: (a) which slot is active, (b) the token position at snapshot time, (c) the file path of the saved state
- On reconnect or server restart, fall back to current text-based compression
Related
Problem
When context compression is triggered (at
contextPercentageThreshold), qwen-code sends a summarized conversation history to the llama-server. This summary is a different token sequence from the original, causing:The server's prompt cache becomes useless at exactly the moment it would be most valuable.
Proposed Solution
llama.cpp server already exposes a slot state save/restore API:
Instead of text-based compression, qwen-code could:
/slots/0/saveto snapshot the current model state/slots/0/restore+ send only the new tokens since the snapshotThis would replace "summarize history → resend full text" with "snapshot state → append new tokens".
Why This Is Especially Valuable for Qwen3.6-series Models
Qwen3.6-35B-A3B (and similar hybrid recurrent-transformer models) maintain a fixed-size recurrent state that already encodes a compressed representation of all past context. This state is exactly what is saved/restored by the slot API.
Current Workaround
Users working with local llama.cpp backends currently maintain external markdown files (PROGRESS.md, QWEN.md) to manually persist context across compression boundaries — effectively a manual implementation of what MemGPT/Letta does with external memory. The slot API approach would make this unnecessary for within-session continuity.
Implementation Notes
--slot-save-path)Related