Skip to content

Frequent KV cache invalidation and forced full prompt re-processing (github.copilot-chat, insider)) #298554

Closed as duplicate

Description

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.110.0-insider (user setup)

  • Extension: github.copilot-chat

  • Extension Version: 0.38.2026022801

  • OS Version: Windows 11 x64 (10.0.26200)


Description

When using GitHub Copilot Chat with a locally hosted llama.cpp server (llama-b8183-bin-win-cuda-13.1-x64, Qwen3-Coder-Next-GGUF), I am observing frequent KV cache invalidation and forced full prompt re-processing on the server side.

This happens especially during larger reading / review workflows (multi-step reasoning, MCP-style interactions, larger file context). It appears that the extension repeatedly resends large rolling context, which leads to server-side checkpoint invalidation.

Server logs frequently show:

  • forcing full prompt re-processing due to lack of cache data
  • Erasing all context checkpoints
  • Full prompt re-evaluation (~40k–50k tokens)
  • Significant performance degradation

This makes iterative review workflows noticeably slower.


Server Setup

Running:

lama-b8183-bin-win-cuda-13.1-x64

Startup script:

@echo off
"D:\llama_ai\llama-b8183-bin-win-cuda-13.1-x64\llama-server.exe" ^
  -m "C:\Users\chris\AppData\Local\llama.cpp\unsloth_Qwen3-Coder-Next-GGUF_UD-Q6_K_XL_Qwen3-Coder-Next-UD-Q6_K_XL-00001-of-00003.gguf" ^
  --alias "Qwen3-Coder-Next-GGUF:UD-Q6_K_XL" ^
  --gpu-layers all ^
  -ot "\.(1[9-9]|[2-9][0-9]|[0-9][0-9][0-9])\.ffn_(gate|up|down)_exps.=CPU" ^
  --flash-attn on ^
  --cache-type-k q8_0 ^
  --cache-type-v q8_0 ^
  --cache-ram 28384 ^
  --cache-reuse 956 ^
  --ctx-size 81536 ^
  --batch-size 1024 ^
  --ubatch-size 512 ^
  --threads 8 ^
  --kv-offload ^
  --op-offload ^
  --fit off ^
  --parallel 1 ^
  --host 0.0.0.0 ^
  --port 11434 ^
  --seed 3407 ^
  --temp 1.0 ^
  --top-p 0.9 ^
  --min-p 0.01 ^
  --top-k 40 ^
  --jinja

pause

Steps to Reproduce

  1. Connect Copilot Chat to the local llama.cpp server (compatible openai)
  2. Open a larger file or perform multi-step reasoning / review.
  3. Let Copilot perform read → analyze → follow-up steps.
  4. Observe repeated full prompt re-processing in server logs.

Expected Behavior

  • Incremental requests should reuse prior context efficiently.
  • No repeated full re-evaluation of ~40k–50k tokens for small incremental steps.
  • Stable server-side checkpoint reuse.

Actual Behavior

  • Frequent cache invalidation.
  • All checkpoints erased.
  • Full prompt re-processing.
  • Large latency spikes during review workflows.

Logs

The issue appears more related to conversation/session handling than to raw model performance (although I hear swa issues recently)

Example logs

slot update_slots: id  0 | task 3487 | prompt done, n_tokens = 50966, batch.n_tokens = 54
slot init_sampler: id  0 | task 3487 | init sampler, took 4.03 ms, tokens: text = 50966, total = 50966
slot update_slots: id  0 | task 3487 | erasing old context checkpoint (pos_min = 47392, pos_max = 47392, size = 75.376 MiB)
slot update_slots: id  0 | task 3487 | created context checkpoint 8 of 8 (pos_min = 50911, pos_max = 50911, size = 75.376 MiB)
slot print_timing: id  0 | task 3487 |
prompt eval time =     599.17 ms /    54 tokens (   11.10 ms per token,    90.12 tokens per second)
       eval time =   12570.80 ms /   371 tokens (   33.88 ms per token,    29.51 tokens per second)
      total time =   13169.98 ms /   425 tokens
slot      release: id  0 | task 3487 | stop processing: n_tokens = 51336, truncated = 0
srv  update_slots: all slots are idle
srv  log_server_r: done request: POST /v1/chat/completions 192.168.1.247 200
srv  params_from_: Chat format: Qwen3 Coder
slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.485 (> 0.100 thold), f_keep = 0.500
srv  get_availabl: updating prompt cache
srv   prompt_save:  - saving prompt with length 51336, total state size = 715.157 MiB
srv          load:  - looking for better prompt, base f_keep = 0.500, sim = 0.485
srv        update:  - cache state: 1 prompts, 1318.164 MiB (limits: 28384.000 MiB, 95744 tokens, 1105417 est)
srv        update:    - prompt 000002315DFAB240:   51336 tokens, checkpoints:  8,  1318.164 MiB
srv  get_availabl: prompt cache update took 141.75 ms
slot launch_slot_: id  0 | task -1 | sampler chain: logits -> ?penalties -> ?dry -> ?top-n-sigma -> top-k -> ?typical -> ?top-p -> min-p -> ?xtc -> temp-ext -> dist
slot launch_slot_: id  0 | task 3859 | processing task, is_child = 0
slot update_slots: id  0 | task 3859 | new prompt, n_ctx_slot = 95744, n_keep = 0, task.n_tokens = 52970
slot update_slots: id  0 | task 3859 | n_past = 25665, slot.prompt.tokens.size() = 51336, seq_id = 0, pos_min = 51335, n_swa = 1
slot update_slots: id  0 | task 3859 | forcing full prompt re-processing due to lack of cache data (likely due to SWA or hybrid/recurrent memory, see https://github.com/ggml-org/llama.cpp/pull/13194#issuecomment-2868343055)
slot update_slots: id  0 | task 3859 | erased invalidated context checkpoint (pos_min = 47955, pos_max = 47955, n_swa = 1, size = 75.376 MiB)
slot update_slots: id  0 | task 3859 | erased invalidated context checkpoint (pos_min = 48633, pos_max = 48633, n_swa = 1, size = 75.376 MiB)
slot update_slots: id  0 | task 3859 | erased invalidated context checkpoint (pos_min = 48938, pos_max = 48938, n_swa = 1, size = 75.376 MiB)
slot update_slots: id  0 | task 3859 | erased invalidated context checkpoint (pos_min = 49247, pos_max = 49247, n_swa = 1, size = 75.376 MiB)
slot update_slots: id  0 | task 3859 | erased invalidated context checkpoint (pos_min = 49820, pos_max = 49820, n_swa = 1, size = 75.376 MiB)
slot update_slots: id  0 | task 3859 | erased invalidated context checkpoint (pos_min = 50122, pos_max = 50122, n_swa = 1, size = 75.376 MiB)
slot update_slots: id  0 | task 3859 | erased invalidated context checkpoint (pos_min = 50505, pos_max = 50505, n_swa = 1, size = 75.376 MiB)
slot update_slots: id  0 | task 3859 | erased invalidated context checkpoint (pos_min = 50911, pos_max = 50911, n_swa = 1, size = 75.376 MiB)
slot update_slots: id  0 | task 3859 | n_tokens = 0, memory_seq_rm [0, end)
slot update_slots: id  0 | task 3859 | prompt processing progress, n_tokens = 1024, batch.n_tokens = 1024, progress = 0.019332
slot update_slots: id  0 | task 3859 | n_tokens = 1024, memory_seq_rm [1024, end)

Activity

  1. changed the title [-]Frequent KV cache invalidation and forced full prompt re-processing (seems a prompt issue)[/-] [+]Frequent KV cache invalidation and forced full prompt re-processing (github.copilot-chat, insider))[/+] on Mar 1, 2026
  2. chrisoutwright commented on Mar 1, 2026

    @chrisoutwright
    Author

    Don't tell me this is about tool ordering in the request (or dynamic mcp tool definitions?, i use standard only) or injected small variables per specific turns, that would break most prefix based caching, i don't want to write a proxy for that to check ...

  3. roblourens commented on Mar 1, 2026

    @roblourens
    Member

    Can you check the requests to see why the cache is being invalidated? We pay attention to this metric and I'm pretty sure we don't randomly invalidate it in typical cases for other models.

    https://github.com/microsoft/vscode/wiki/Copilot-Issues#language-model-requests-and-responses

  4. added
    info-needed
    on Mar 1, 2026
  5. chrisoutwright commented on Mar 2, 2026

    @chrisoutwright
    Author

    Can you check the requests to see why the cache is being invalidated? We pay attention to this metric and I'm pretty sure we don't randomly invalidate it in typical cases for other models.

    https://github.com/microsoft/vscode/wiki/Copilot-Issues#language-model-requests-and-responses

    I can do that, will try it during the weekdays, .. will I need to use "--swa-full true" better? I could do a faster non-replication as test probably .. I am confused if the model is the issue with automatically deciding to influence the attention of if this is prompt issue .. for a prompt issue, I would rather want to write a script as proxy that will do the diffing for me. Any available tool that can save the effort I can run?

  6. chrisoutwright commented on Mar 8, 2026

    @chrisoutwright
    Author

    Can you check the requests to see why the cache is being invalidated? We pay attention to this metric and I'm pretty sure we don't randomly invalidate it in typical cases for other models.

    https://github.com/microsoft/vscode/wiki/Copilot-Issues#language-model-requests-and-responses

    Proxy Evidence: Tool definition changes between requests cause prefix cache invalidation

    I wrote an intercepting proxy that sits between Copilot and the llama.cpp backend, logging every request and structurally diffing tool definitions, system prompts, and message content across successive requests. Here are the findings:

    1. Tool definitions change between consecutive requests

    Across 22 requests in a single session:

    Requests Tool count Tool list hash
    req-002 → req-009 65 tools f6f35a44 (stable)
    req-010 64 tools 016a6ab1 (changed)
    req-011 → req-022 65 tools a23401dc (changed again)

    Between req-009 and req-010, the tool vscode_listCodeUsages was removed, and 39 out of 64 tools shifted position in the array (everything after index 25 slid up by one). Between req-010 and req-011, it was added back — again shifting 39 positions.

    Additionally, tool parameter schemas changed between these requests — required arrays were reordered, properties like newName, packageList, pythonEnvironment were added/removed, and renderMermaidDiagram was removed and re-added.

    These are not just ordering changes — the actual JSON content of tool schemas changes, meaning every token after the first divergence in the serialized prompt is different, invalidating prefix-based KV cache.

    2. System prompt swaps entirely on context compaction

    Request req-001 used a "conversation summarizer" system prompt (for context compaction). Request req-002 switched to the standard coding assistant prompt. This is a complete system prompt replacement — every token changes. Since the system prompt sits at the very beginning of the token sequence, this invalidates the entire KV cache prefix.

    3. Summary

    Cache-busting cause Frequency Impact
    Tool added/removed mid-session (vscode_listCodeUsages) At least 2× per session Full re-eval of ~50k tokens (~39 tool positions shift)
    Tool parameter schema changes (required arrays, properties) Same transitions Compounds the above
    System prompt swap (summarizer ↔ agent) 1× per compaction Invalidates entire prefix

    Reproduction

    I used a transparent async Python proxy that:

    • Relays all requests to the backend unchanged
    • Structurally diffs tool definitions, system prompts, and tool calls across successive requests using DeepDiff
    • Logs full raw JSONL for forensics

    The tool definition shuffling alone is enough to explain the forced full prompt re-processing I reported. For servers that use prefix-based KV caching (llama.cpp, vLLM, etc.), any change in the token sequence before the divergence point invalidates the entire cache from that point forward.

    Suggested fix

    Stabilize the tool list sent to the model:

    • Sort tools deterministically (e.g., alphabetically by function name)
    • Don't add/remove tools mid-session unless explicitly triggered by the user
    • Keep required arrays in a stable order
    • Avoid schema property additions/removals between turns when the tool hasn't functionally changed

    proxy_diffs.log

  7. chrisoutwright commented on Mar 8, 2026

    @chrisoutwright
    Author

    so the problem is: vscode_listCodeUsages

    captured version from this session's log said "Currently supported for: python, rust" but the live version now lists many more languages -> which means the extension updates this tool's description dynamically based on installed language extensions, and that alone could cause token-level changes between requests.

    Can this be done differently? it causes the issue as explained in this ticket.

  8. chrisoutwright commented on Mar 15, 2026

    @chrisoutwright
    Author

    I think I found the issue (took me to write a whole UI on that .. .):

    Image

    the copilot is hiding lines and some point (injection/reduce in former messages), very hard to pick up

    can this be prevented with some parameter?

  9. Foxtr0t1337 commented on Mar 15, 2026

    @Foxtr0t1337

    VS Code Version: 1.111.0 (Universal)
    Plugin version 0.39.1

    I've met the same problem - almost every long tool result invalidates the whole cache for LM Studio (unsloth/Qwen3.5-35B-A3B-GGUF) via johnny-zhao.oai-compatible-copilot, making it increasingly difficult to work with.

  10. ODtian commented on Mar 18, 2026

    @ODtian

    I'm using a plugin to integrate my own API endpoint and have encountered a similar situation: when making requests using Copilot, the cache only hits occasionally, while using VS Code Codex results in a 100% cache hit rate. This would explain the issue if it were a tool-related problem, since both the local key-value cache and the remote API cache are prefix-based.

  11. roblourens commented on May 3, 2026

    @roblourens
    Member

    Sorry for the slow response, thanks for the investigation. I believe we actually just fixed this here: #312568

  12. added
    *duplicate
    on May 3, 2026
  13. added this to the 1.119.0 milestone on May 3, 2026
  14. locked and limited conversation to collaborators on Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

*duplicateinfo-needed

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions