Answers for LLM inference engineers

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.

Published 2026-11-25 · llama.cpp source read at master ab16df3 (b12723 + 18 commits, 2026-11-25), build history read from all b* tags; the measurements were run again on build b12733 with identical numbers · Tool version 1.0.0 (Python 3.8+, standard library only)

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.

  1. 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:
    python cachecheck.py diff DIR/<first>.txt DIR/<second>.txt --server http://127.0.0.1:8080
    It prints the shared prefix in tokens and the text around the first difference, e.g.
    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
    With saved request bodies instead (/v1/chat/completions JSON) it renders them through the server's own /apply-template, so the chat template, tools and reasoning handling are exactly the server's.
  2. Compare with what the server reused. Every llama-server response carries timings.cache_n (tokens taken from the cache) and timings.prompt_n (tokens processed). cachecheck.py live turn1.json turn2.json sends both requests and prints a verdict (below). If the shared prefix equals turn 1 and cache_n is still 0, the problem is on the server side.
  3. Know the model's memory. python cachecheck.py gguf model.gguf reads the GGUF header: full attention, SWA (with the window size), recurrent or hybrid. The server's startup log says the same in print_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 2Shared prefixFull attention (Llama)SWA, window 64 (Gemma 2)SWA + --swa-fullRecurrent (Mamba)Recurrent, --ctx-checkpoints 0
Nothing (appends reply + new message)1,647212 / 1,859160 / 1,822160 / 1,822210 / 1,8531,853 / 1,853
Rewrote the previous assistant reply1,647183 / 1,830183 / 1,830183 / 1,830187 / 1,8301,830 / 1,830
Edited a word 243 tokens before the end of turn 11,404455 / 1,859418 / 1,822418 / 1,822722 / 1,8531,853 / 1,853
Edited a word in an early message (token 898)898960 / 1,8581,821 / 1,821923 / 1,8211,852 / 1,8521,852 / 1,852
Changed the system prompt (a timestamp, token 45)451,814 / 1,8591,822 / 1,8221,777 / 1,8221,853 / 1,8531,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:

Causes and fixes

cachecheck verdictCauseFix
CLIENT CHANGED THE PREFIX, earlySomething 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 historyThe 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 SLOTWith -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, smallThe 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 b12723What it doesSince
--swa-full (LLAMA_ARG_SWA_FULL)offFull-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 slotMaximum 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 tokensMinimum 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 MiBHost-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-slotsonSave 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 N34 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 DIRoffWrites each rendered prompt to DIR/<ms>.txt; input for cachecheck.py diff.b9577 (2026-06-09, #22031)
LLAMA_SERVER_SLOTS_DEBUG=1 (env)unsetPrints 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)PRChange
b5429 (2025-05-20)#13194SWA KV cache; the “forcing full prompt re-processing” message and --swa-full appear.
b6173 (2025-08-15)#15293SWA checkpoints.
b6685 (2025-10-03)#16382Context checkpoints for hybrid and recurrent models.
b6724 (2025-10-09)#16391Host-memory prompt cache (--cache-ram).
b9310 (2026-05-25)#22929Fix checkpoint creation; --checkpoint-min-step replaces --checkpoint-every-n-tokens (in b8218–b9309).
b9509 (2026-06-04)#24110Avoid an unnecessary checkpoint restore when new tokens are present.
b9594 (2026-06-11)#24411Skip checkpoints beyond the resume position.
b9765 (2026-06-23)#24176Better user-message detection; a checkpoint at every user message.
b9829 (2026-06-28)#25078Cache messages become trace level (need -lv 4).
b9908 (2026-07-07)#25070Prompt cache RAM limit enforced.
b9978 (2026-07-12)#25472Evict checkpoints within min-step of each other.
b10864 (2026-09-08)#28302…only when the checkpoint list is full.
b11669 (2026-10-15)#30580Off-by-two in the SWA reuse threshold.
b11738 (2026-10-19)#30666SWA checkpoint invalidation logic.
b12498 (2026-11-18)#32434Reuse threshold for hybrid and recurrent models fixed (their window is treated as 0).
b12675 – b12699 (2026-11-23/24)#32828, #28992, #30997Prompt-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 read timings.cache_n in the response.
Does --swa-full fix 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 run cachecheck.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-reuse help?
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

Sources