llama-server “forcing full prompt re-processing due to lack of cache data”: why the whole prompt is processed again, and how to find the cause
The message means the new prompt is not a pure continuation of the cached one, and the model's memory cannot be rolled back to the first changed token. A full-attention model (Llama, dense Qwen3) then re-processes only the tokens after the change. A sliding-window (SWA) model such as Gemma keeps only the last window of KV, and a hybrid or recurrent model (Qwen3.5, Qwen3-Next, Nemotron-H, Granite hybrid, LFM2, Mamba, RWKV) keeps one state at the end. Without a context checkpoint before the change, llama-server starts again from token 0. In our tests the same early edit cost 960 tokens on a full-attention model and the whole 1,821 to 1,852-token prompt on SWA and recurrent models. So the first question is not which flag to set but where the prompt changed. cachecheck.py answers that from two requests or from the server's own prompt log.
Corrected on 2026-12-05: the date of build b6173 (where --swa-checkpoints first appears) was given as 2025-08-14; the commit of the b6173 tag is dated 2025-08-15 (UTC).
How do I find out why llama-server reprocesses the whole prompt?
Check three numbers: where two consecutive prompts stop sharing tokens, how many tokens the server reused (timings.cache_n), and what kind of memory the model has.
- Find the first changed token. Start the server with
--log-prompts-dir DIR(build b9577 and later; it writes every rendered prompt as a.txt), make two turns in your client, then:
It prints the shared prefix in tokens and the text around the first difference, e.g.python cachecheck.py diff DIR/<first>.txt DIR/<second>.txt --server http://127.0.0.1:8080
With saved request bodies instead (turn 1: 1647 tokens turn 2: 1821 tokens shared prefix: 898 tokens PREFIX CHANGED at token 898 of 1647 (55% into turn 1). turn 1: ... united in ┃ while firs turn 2: ... united in ┃ error first/v1/chat/completionsJSON) it renders them through the server's own/apply-template, so the chat template, tools and reasoning handling are exactly the server's. - Compare with what the server reused. Every llama-server response carries
timings.cache_n(tokens taken from the cache) andtimings.prompt_n(tokens processed).cachecheck.py live turn1.json turn2.jsonsends both requests and prints a verdict (below). If the shared prefix equals turn 1 andcache_nis still 0, the problem is on the server side. - Know the model's memory.
python cachecheck.py gguf model.ggufreads the GGUF header: full attention, SWA (with the window size), recurrent or hybrid. The server's startup log says the same inprint_info: n_swa = ....
To read the server's own reasoning, restart it with -lv 4 and run python cachecheck.py log server.log. Since build b9829 (2026-06-28, PR #25078) “forcing full prompt re-processing” and all checkpoint lines are trace level, so at the default -lv 3 the log shows nothing (checked: 0 lines at -lv 3, 1 line at -lv 4 for the same request).
How much is re-processed on each kind of model?
A change inside the conversation costs the tokens after it on full attention, but the whole prompt on SWA and recurrent models when it lies before the last usable checkpoint. Two-turn chat, turn 1 = 1,647 tokens, turn 2 = turn 1 + the model's reply + a new user message. Each cell: tokens processed for turn 2 (prompt_n) / prompt length. Fresh server per cell, -c 4096 -np 1, everything else default.
| What the client changed in turn 2 | Shared prefix | Full attention (Llama) | SWA, window 64 (Gemma 2) | SWA + --swa-full | Recurrent (Mamba) | Recurrent, --ctx-checkpoints 0 |
|---|---|---|---|---|---|---|
| Nothing (appends reply + new message) | 1,647 | 212 / 1,859 | 160 / 1,822 | 160 / 1,822 | 210 / 1,853 | 1,853 / 1,853 |
| Rewrote the previous assistant reply | 1,647 | 183 / 1,830 | 183 / 1,830 | 183 / 1,830 | 187 / 1,830 | 1,830 / 1,830 |
| Edited a word 243 tokens before the end of turn 1 | 1,404 | 455 / 1,859 | 418 / 1,822 | 418 / 1,822 | 722 / 1,853 | 1,853 / 1,853 |
| Edited a word in an early message (token 898) | 898 | 960 / 1,858 | 1,821 / 1,821 | 923 / 1,821 | 1,852 / 1,852 | 1,852 / 1,852 |
| Changed the system prompt (a timestamp, token 45) | 45 | 1,814 / 1,859 | 1,822 / 1,822 | 1,777 / 1,822 | 1,853 / 1,853 | 1,853 / 1,853 |
Random-weight F32 models built with make_toy_models.py (4 layers, width 128) and run on CPU, so only the cache behaviour is meaningful, not speed. Turn-2 lengths differ by column because each model generated a different 16-token reply. The runner is repro/run_matrix.sh, the requests are in repro/cases/ and the raw numbers in repro/results.jsonl. A real hybrid model (attention + recurrent layers) was not run; its reuse rule in the source is the recurrent one.
What the table shows:
- Normal multi-turn chat is fine on every kind of model with default settings, because llama-server saves a checkpoint a few tokens before the end of each prompt (4 and 4 +
n_ubatchtokens before it, PR #20288). The recurrent model rolled back 4 tokens. With checkpoints off, every turn was a full re-process even though the client changed nothing. - The SWA model reused up to 1,404 tokens although its window is 64. The SWA part of the KV cache is
n_swa + n_ubatchcells rounded up to 256 (here 64 + 512 → 768,src/llama-kv-cache-iswa.cpp), so a change in roughly the lastn_swa + n_ubatchtokens is still cheap. Further back it needs a checkpoint, and there was none before token 898. - An early change is the expensive one everywhere. On full attention it costs everything after the change; on SWA and recurrent models it usually costs everything.
--swa-fullturned the SWA model into the full-attention case (923 instead of 1,821) and did not help the system-prompt change, because nothing after token 45 can be reused on any model.
Causes and fixes
| cachecheck verdict | Cause | Fix |
|---|---|---|
| CLIENT CHANGED THE PREFIX, early | Something near the start differs every request: a timestamp, request id or token count in the system prompt, a tool list in a different order, a client that rewrites its header per request. | Make the system prompt and the tool list byte-identical between turns; put changing data at the end of the last user message. No server flag can reuse tokens after a change. |
| CLIENT CHANGED THE PREFIX, inside the history | The client trims or summarises old tool output, drops old turns to fit the context, or re-serialises earlier tool calls differently. | On full attention this costs only the tail. On SWA models --swa-full limits it to the same tail (more memory). On hybrid/recurrent models only a checkpoint before the change helps: avoid rewriting old messages, or trim in large, rare steps. |
FULL RE-PROCESSING ON THE SERVER SIDE (turn 2 extends turn 1, cache_n 0) | No usable checkpoint: --ctx-checkpoints 0, a build older than b6685 for a hybrid or recurrent model (checkpoints were SWA-only before), or the cached prompt was evicted. | Keep the default --ctx-checkpoints 32; update the build (several checkpoint fixes landed in b9310–b12699, table below); keep --cache-ram on. |
| DIFFERENT SLOT | With -np > 1, the next turn went to another slot (another conversation took the slot, or the prompt similarity was below --slot-prompt-similarity, default 0.1). | Send "id_slot" in the request, run -np 1 for a single agent, keep --cache-ram (default 8192 MiB) so a slot's prompt can be restored from host memory. |
| PARTIAL REUSE, small | The server rolled back to the checkpoint a few tokens before the old prompt's end. | Nothing to fix. |
What about --cache-reuse N? The server disables it at load when the memory cannot be shifted; for SWA models that is the case unless --swa-full is set, because the SWA and full KV caches differ in size (logged as cache_reuse is not supported by this context, it will be disabled; seen with the SWA model). Recurrent memory accepts it. Where it runs, it moves cached chunks of at least N tokens that follow the change, but its loop only skips cached tokens, so it recovers text after a deletion and nothing after an insertion or a replaced word. Measured with --cache-reuse 256: 4 deleted words → cache_n 1,616 instead of 895; 1 replaced word → 898 either way (results_cache_reuse.txt). The shifted chunks keep KV that was computed with the deleted text in front of them, so their output is not identical to a fresh run.
The flags that matter, with defaults and the build that added them
| Flag (env) | Default at b12723 | What it does | Since |
|---|---|---|---|
--swa-full (LLAMA_ARG_SWA_FULL) | off | Full-size KV for the SWA layers; reuse then works like full attention. Ignored with a warning on models without SWA, and no help for hybrid/recurrent. | b5429 (2025-05-20, #13194) |
-ctxcp, --ctx-checkpoints, --swa-checkpoints (LLAMA_ARG_CTX_CHECKPOINTS) | 32 per slot | Maximum number of saved partial states per slot. 0 disables them. | b6173 as --swa-checkpoints (2025-08-15, #15293, default 3); hybrid/recurrent from b6685 (2025-10-03, #16382); default 8 at b6724, 32 from b8218 (2026-03-06) |
-cms, --checkpoint-min-step (LLAMA_ARG_CHECKPOINT_MIN_SPACING_NT) | 8192 tokens | Minimum spacing between checkpoints; checkpoints closer than this are evicted only when the list is full (b10864, #28302). The last user message and the prompt end are exempt. | b9310 (2026-05-25, #22929, default 256); 8192 from b9765 (2026-06-23, #24176) |
-cram, --cache-ram (LLAMA_ARG_CACHE_RAM) | 8192 MiB | Host-memory prompt cache: idle slots' prompts are saved and restored. A state bigger than the limit is skipped (exceeds cache size limit). -1 = no limit, 0 = off. | b6724 (2025-10-09, #16391) |
--cache-idle-slots | on | Save idle slots to the prompt cache when a new task starts (needs --cache-ram). | b8852 (2026-04-20, renamed from --clear-idle, #21741) |
--cache-reuse N (LLAMA_ARG_CACHE_REUSE) | 0 (off) | KV shifting of chunks ≥ N tokens after a deletion; disabled for SWA models without --swa-full (see above). | b3914 or earlier |
-lv, --verbosity N | 3 | 4 shows the trace lines: “forcing full prompt re-processing”, “created / restored / erased invalidated context checkpoint”. | trace level since b9829 (2026-06-28, #25078); before it the message was a warning |
--log-prompts-dir DIR | off | Writes each rendered prompt to DIR/<ms>.txt; input for cachecheck.py diff. | b9577 (2026-06-09, #22031) |
LLAMA_SERVER_SLOTS_DEBUG=1 (env) | unset | Prints the old and new tokens around the first mismatch in the log (width set by LLAMA_SERVER_SLOTS_N_DIFF), and puts prompt text in /slots. | b6724 (2025-10-09) |
“Since” is the first b* tag whose source contains the flag or default, found by bisecting all 8,792 tags of ggml-org/llama.cpp; the PR is the commit that introduced it.
Checkpoint and prompt-cache fixes by build
If you run a build from before mid-2026, update before tuning flags: the reuse logic changed many times.
| Build (date) | PR | Change |
|---|---|---|
| b5429 (2025-05-20) | #13194 | SWA KV cache; the “forcing full prompt re-processing” message and --swa-full appear. |
| b6173 (2025-08-15) | #15293 | SWA checkpoints. |
| b6685 (2025-10-03) | #16382 | Context checkpoints for hybrid and recurrent models. |
| b6724 (2025-10-09) | #16391 | Host-memory prompt cache (--cache-ram). |
| b9310 (2026-05-25) | #22929 | Fix checkpoint creation; --checkpoint-min-step replaces --checkpoint-every-n-tokens (in b8218–b9309). |
| b9509 (2026-06-04) | #24110 | Avoid an unnecessary checkpoint restore when new tokens are present. |
| b9594 (2026-06-11) | #24411 | Skip checkpoints beyond the resume position. |
| b9765 (2026-06-23) | #24176 | Better user-message detection; a checkpoint at every user message. |
| b9829 (2026-06-28) | #25078 | Cache messages become trace level (need -lv 4). |
| b9908 (2026-07-07) | #25070 | Prompt cache RAM limit enforced. |
| b9978 (2026-07-12) | #25472 | Evict checkpoints within min-step of each other. |
| b10864 (2026-09-08) | #28302 | …only when the checkpoint list is full. |
| b11669 (2026-10-15) | #30580 | Off-by-two in the SWA reuse threshold. |
| b11738 (2026-10-19) | #30666 | SWA checkpoint invalidation logic. |
| b12498 (2026-11-18) | #32434 | Reuse threshold for hybrid and recurrent models fixed (their window is treated as 0). |
| b12675 – b12699 (2026-11-23/24) | #32828, #28992, #30997 | Prompt-cache restore fixes (keep an entry until the restore succeeds, skipped lookups, retry after clearing idle slots). |
The rule llama-server applies
It reuses the cached tokens up to the first difference only if the memory still holds the state for that position. In server_prompt::get_reuse() (tools/server/server-slot-sched.cpp): let p be the position of the first token to evaluate. The live memory is usable when its smallest kept position is below p (recurrent, hybrid, full attention) or below p − n_swa + 2 (SWA). Otherwise the server looks for the newest checkpoint that ends at or before p and starts early enough, restores it and re-processes from there. If none qualifies, n_past becomes 0 and the message is logged. Checkpoints that cover tokens the new prompt does not share are then erased (“erased invalidated context checkpoint”), which is why one early change also throws away the checkpoints that later turns could have used.
Checkpoints are created before decoding a batch: near the end of each prompt and at batches that start a user message, spaced at least --checkpoint-min-step tokens apart except for the last user message and the prompt end.
cachecheck.py
Download cachecheck.py (MIT, one file, standard library only, ~400 lines). Four commands:
python cachecheck.py diff A B --server URL # A, B: request JSON or --log-prompts-dir .txt; --offline compares characters
python cachecheck.py live turn1.json turn2.json --server URL # "{{REPLY}}" in turn2 = turn 1's answer
python cachecheck.py log server.log # explains cache lines; start the server with -lv 4
python cachecheck.py gguf model.gguf # full attention / SWA / recurrent / hybrid
live exits 0 when the reuse was as good as possible, 1 when the client changed the prefix, 3 for a different slot, 4 for a full server-side re-process and 5 for a large rollback, so it can run in CI against a pinned build.
FAQ
- Is “forcing full prompt re-processing due to lack of cache data” a bug?
- Usually not. It means the new prompt differs from the cached one at a position the server cannot roll back to and no checkpoint is earlier. In issue #24714 (build 9642) one commenter calls it expected behaviour and others report it as a bug; no maintainer had answered when we read the thread. Find the changed token first.
- Why can't I see the message any more?
- Since b9829 it is trace level. Use
-lv 4, or readtimings.cache_nin the response. - Does
--swa-fullfix it? - For SWA models only, at the cost of a full-size KV cache for the sliding-window layers. It does nothing for hybrid or recurrent models.
- My agent (Claude Code, Qwen Code, OpenCode...) triggers it every turn.
- Run the server with
--log-prompts-dir, take two consecutive prompts and runcachecheck.py diff. If the shared prefix is small, the client puts something variable near the start; if it covers the old prompt, look at slots and checkpoints instead. - Does
--cache-reusehelp? - Rarely. It is disabled for SWA models without
--swa-full, and where it runs it recovers text after a deletion only, not after an insertion or a replaced word.
Limitations
- Measured on random-weight toy models on CPU at master
ab16df3and build b12733. A real hybrid model (attention + recurrent layers) and real GPU runs were not measured; the hybrid behaviour above is from the source. - The DIFFERENT SLOT verdict is covered by unit tests only (test_classify.py); we did not reproduce slot switching with several clients.
cachecheck.pyreads/slotsto see which slot served a turn; with--no-slotsthat verdict is not available.- Multimodal prompts are not handled by
diff(images are not text).
Related
- llama-server and llama-cli arguments removed by build (if a flag above is rejected by your build)
- What each engine returns when the prompt exceeds the context
- How many sequences fit in vLLM's KV cache