Skip to content

Eval bug: [Bug] Qwen3-Coder-Next (Hybrid) Prompt Cache forces full re-processing due to 'invalidated context checkpoint' despite --swa-full #19794

Closed as not planned

Description

@tech112233445566

Name and Version

(base) root@user1-ASUS-D500TC-S501MC:~/data/AI/llama.cpp# ./build/bin/llama-server --version
ggml_cuda_init: found 1 CUDA devices:

slot update_slots: ... forcing full prompt re-processing due to lack of cache data (likely due to SWA or hybrid/recurrent memory)
slot update_slots: ... erased invalidated context checkpoint (pos_min = 19255, pos_max = 19255, n_swa = 1, size = 75.376 MiB)
slot update_slots: ... n_tokens = 0, memory_seq_rm [0, end)

开启命令:
CUDA_VISIBLE_DEVICES=0 nice -n -10 ./build/bin/llama-server --model /root/Qwen3-Coder-Next-UD-TQ1_0.gguf --ctx_size 128000 --cache-type-k q4_0 --cache-type-v q4_0 --flash-attn on --port 8001 --api-key chat --batch-size 2048 --ubatch-size 512 --parallel 1 --mlock --no-mmap --threads 8 --cache-ram -1 --ctx-checkpoints 32 --host 0.0.0.0 --slot-save-path /tmp/qwen_slots

Operating systems

Linux

GGML backends

CUDA

Hardware

Device 0: NVIDIA GeForce RTX 3060, compute capability 8.6, VMM: yes
version: 8124 (3571565)
built with GNU 11.4.0 for Linux x86_64

(base) root@user1-ASUS-D500TC-S501MC:~/data/AI/llama.cpp# lscpu
架构: x86_64
CPU 运行模式: 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
字节序: Little Endian
CPU: 16
在线 CPU 列表: 0-15
厂商 ID: GenuineIntel
型号名称: 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz
CPU 系列: 6
型号: 167
每个核的线程数: 2
每个座的核数: 8
座: 1
步进: 1
CPU 最大 MHz: 4900.0000
CPU 最小 MHz: 800.0000
BogoMIPS: 4992.00
标记: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon
pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2
x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ep
t_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap avx512ifma clflushopt intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xg
etbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg
avx512_vpopcntdq rdpid fsrm md_clear flush_l1d arch_capabilities
Virtualization features:
虚拟化: VT-x
Caches (sum of all):
L1d: 384 KiB (8 instances)
L1i: 256 KiB (8 instances)
L2: 4 MiB (8 instances)
L3: 16 MiB (1 instance)
NUMA:
NUMA 节点: 1
NUMA 节点0 CPU: 0-15
Vulnerabilities:
Gather data sampling: Mitigation; Microcode
Itlb multihit: Not affected
L1tf: Not affected
Mds: Not affected
Meltdown: Not affected
Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Reg file data sampling: Not affected
Retbleed: Mitigation; Enhanced IBRS
Spec rstack overflow: Not affected
Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Srbds: Not affected
Tsx async abort: Not affected

Models

https://www.modelscope.cn/models/unsloth/Qwen3-Coder-Next-GGUF/resolve/master/Qwen3-Coder-Next-UD-TQ1_0.gguf

Problem description & steps to reproduce

每次推理都会有forcing full prompt re-processing due to lack of cache data (likely due to SWA or hybrid/recurrent memory)这个错误,我在使用openclaw时发现了这个问题

First Bad Commit

No response

Relevant log output

执行片段
srv init: init: chat template, thinking = 0 main: model loaded main: server is listening on http://0.0.0.0:8001 main: starting the main loop... srv update_slots: all slots are idle srv params_from_: Chat format: peg-constructed slot get_availabl: id 0 | task -1 | selected slot by LRU, t_last = -1 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 0 | processing task, is_child = 0 slot update_slots: id 0 | task 0 | new prompt, n_ctx_slot = 128000, n_keep = 0, task.n_tokens = 19892 slot update_slots: id 0 | task 0 | n_tokens = 0, memory_seq_rm [0, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 2048, batch.n_tokens = 2048, progress = 0.102956 slot update_slots: id 0 | task 0 | n_tokens = 2048, memory_seq_rm [2048, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 4096, batch.n_tokens = 2048, progress = 0.205912 slot update_slots: id 0 | task 0 | n_tokens = 4096, memory_seq_rm [4096, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 6144, batch.n_tokens = 2048, progress = 0.308868 slot update_slots: id 0 | task 0 | n_tokens = 6144, memory_seq_rm [6144, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 8192, batch.n_tokens = 2048, progress = 0.411824 slot update_slots: id 0 | task 0 | n_tokens = 8192, memory_seq_rm [8192, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 10240, batch.n_tokens = 2048, progress = 0.514780 slot update_slots: id 0 | task 0 | n_tokens = 10240, memory_seq_rm [10240, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 12288, batch.n_tokens = 2048, progress = 0.617736 slot update_slots: id 0 | task 0 | n_tokens = 12288, memory_seq_rm [12288, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 14336, batch.n_tokens = 2048, progress = 0.720692 slot update_slots: id 0 | task 0 | n_tokens = 14336, memory_seq_rm [14336, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 16384, batch.n_tokens = 2048, progress = 0.823648 slot update_slots: id 0 | task 0 | n_tokens = 16384, memory_seq_rm [16384, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 18432, batch.n_tokens = 2048, progress = 0.926604 slot update_slots: id 0 | task 0 | n_tokens = 18432, memory_seq_rm [18432, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 19380, batch.n_tokens = 948, progress = 0.974261 slot update_slots: id 0 | task 0 | n_tokens = 19380, memory_seq_rm [19380, end) slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 19892, batch.n_tokens = 512, progress = 1.000000 slot update_slots: id 0 | task 0 | prompt done, n_tokens = 19892, batch.n_tokens = 512 slot init_sampler: id 0 | task 0 | init sampler, took 1.57 ms, tokens: text = 19892, total = 19892 slot update_slots: id 0 | task 0 | created context checkpoint 1 of 32 (pos_min = 19379, pos_max = 19379, size = 75.376 MiB) slot print_timing: id 0 | task 0 | prompt eval time = 90234.73 ms / 19892 tokens ( 4.54 ms per token, 220.45 tokens per second) eval time = 480.39 ms / 15 tokens ( 32.03 ms per token, 31.22 tokens per second) total time = 90715.12 ms / 19907 tokens slot release: id 0 | task 0 | stop processing: n_tokens = 19906, truncated = 0 srv update_slots: all slots are idle srv log_server_r: done request: POST /chat/completions 192.168.0.3 200 srv params_from_: Chat format: peg-constructed slot get_availabl: id 0 | task -1 | selected slot by LCP similarity, sim_best = 0.155 (> 0.100 thold), f_keep = 0.154 srv get_availabl: updating prompt cache srv prompt_save: - saving prompt with length 19906, total state size = 206.820 MiB srv load: - looking for better prompt, base f_keep = 0.154, sim = 0.155 srv update: - cache state: 1 prompts, 282.196 MiB (limits: 0.000 MiB, 128000 tokens, 128000 est) srv update: - prompt 0x55d0940067c0: 19906 tokens, checkpoints: 1, 282.196 MiB srv get_availabl: prompt cache update took 113.76 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 26 | processing task, is_child = 0 slot update_slots: id 0 | task 26 | new prompt, n_ctx_slot = 128000, n_keep = 0, task.n_tokens = 19768 slot update_slots: id 0 | task 26 | n_past = 3069, slot.prompt.tokens.size() = 19906, seq_id = 0, pos_min = 19905, n_swa = 1 slot update_slots: id 0 | task 26 | 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 26 | erased invalidated context checkpoint (pos_min = 19379, pos_max = 19379, n_swa = 1, size = 75.376 MiB) slot update_slots: id 0 | task 26 | n_tokens = 0, memory_seq_rm [0, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 2048, batch.n_tokens = 2048, progress = 0.103602 slot update_slots: id 0 | task 26 | n_tokens = 2048, memory_seq_rm [2048, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 4096, batch.n_tokens = 2048, progress = 0.207204 slot update_slots: id 0 | task 26 | n_tokens = 4096, memory_seq_rm [4096, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 6144, batch.n_tokens = 2048, progress = 0.310805 slot update_slots: id 0 | task 26 | n_tokens = 6144, memory_seq_rm [6144, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 8192, batch.n_tokens = 2048, progress = 0.414407 slot update_slots: id 0 | task 26 | n_tokens = 8192, memory_seq_rm [8192, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 10240, batch.n_tokens = 2048, progress = 0.518009 slot update_slots: id 0 | task 26 | n_tokens = 10240, memory_seq_rm [10240, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 12288, batch.n_tokens = 2048, progress = 0.621611 slot update_slots: id 0 | task 26 | n_tokens = 12288, memory_seq_rm [12288, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 14336, batch.n_tokens = 2048, progress = 0.725212 slot update_slots: id 0 | task 26 | n_tokens = 14336, memory_seq_rm [14336, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 16384, batch.n_tokens = 2048, progress = 0.828814 slot update_slots: id 0 | task 26 | n_tokens = 16384, memory_seq_rm [16384, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 18432, batch.n_tokens = 2048, progress = 0.932416 slot update_slots: id 0 | task 26 | n_tokens = 18432, memory_seq_rm [18432, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 19256, batch.n_tokens = 824, progress = 0.974100 slot update_slots: id 0 | task 26 | n_tokens = 19256, memory_seq_rm [19256, end) slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 19768, batch.n_tokens = 512, progress = 1.000000 slot update_slots: id 0 | task 26 | prompt done, n_tokens = 19768, batch.n_tokens = 512 slot init_sampler: id 0 | task 26 | init sampler, took 1.52 ms, tokens: text = 19768, total = 19768 slot update_slots: id 0 | task 26 | created context checkpoint 1 of 32 (pos_min = 19255, pos_max = 19255, size = 75.376 MiB) slot print_timing: id 0 | task 26 | prompt eval time = 90244.75 ms / 19768 tokens ( 4.57 ms per token, 219.05 tokens per second) eval time = 3481.50 ms / 93 tokens ( 37.44 ms per token, 26.71 tokens per second) total time = 93726.25 ms / 19861 tokens slot release: id 0 | task 26 | stop processing: n_tokens = 19860, truncated = 0

Activity

  1. tech112233445566 commented on Feb 22, 2026

    @tech112233445566
    Author

    执行片段

    srv init: init: chat template, thinking = 0
    main: model loaded
    main: server is listening on http://0.0.0.0:8001
    main: starting the main loop...
    srv update_slots: all slots are idle
    srv params_from_: Chat format: peg-constructed
    slot get_availabl: id 0 | task -1 | selected slot by LRU, t_last = -1
    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 0 | processing task, is_child = 0
    slot update_slots: id 0 | task 0 | new prompt, n_ctx_slot = 128000, n_keep = 0, task.n_tokens = 19892
    slot update_slots: id 0 | task 0 | n_tokens = 0, memory_seq_rm [0, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 2048, batch.n_tokens = 2048, progress = 0.102956
    slot update_slots: id 0 | task 0 | n_tokens = 2048, memory_seq_rm [2048, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 4096, batch.n_tokens = 2048, progress = 0.205912
    slot update_slots: id 0 | task 0 | n_tokens = 4096, memory_seq_rm [4096, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 6144, batch.n_tokens = 2048, progress = 0.308868
    slot update_slots: id 0 | task 0 | n_tokens = 6144, memory_seq_rm [6144, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 8192, batch.n_tokens = 2048, progress = 0.411824
    slot update_slots: id 0 | task 0 | n_tokens = 8192, memory_seq_rm [8192, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 10240, batch.n_tokens = 2048, progress = 0.514780
    slot update_slots: id 0 | task 0 | n_tokens = 10240, memory_seq_rm [10240, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 12288, batch.n_tokens = 2048, progress = 0.617736
    slot update_slots: id 0 | task 0 | n_tokens = 12288, memory_seq_rm [12288, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 14336, batch.n_tokens = 2048, progress = 0.720692
    slot update_slots: id 0 | task 0 | n_tokens = 14336, memory_seq_rm [14336, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 16384, batch.n_tokens = 2048, progress = 0.823648
    slot update_slots: id 0 | task 0 | n_tokens = 16384, memory_seq_rm [16384, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 18432, batch.n_tokens = 2048, progress = 0.926604
    slot update_slots: id 0 | task 0 | n_tokens = 18432, memory_seq_rm [18432, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 19380, batch.n_tokens = 948, progress = 0.974261
    slot update_slots: id 0 | task 0 | n_tokens = 19380, memory_seq_rm [19380, end)
    slot update_slots: id 0 | task 0 | prompt processing progress, n_tokens = 19892, batch.n_tokens = 512, progress = 1.000000
    slot update_slots: id 0 | task 0 | prompt done, n_tokens = 19892, batch.n_tokens = 512
    slot init_sampler: id 0 | task 0 | init sampler, took 1.57 ms, tokens: text = 19892, total = 19892
    slot update_slots: id 0 | task 0 | created context checkpoint 1 of 32 (pos_min = 19379, pos_max = 19379, size = 75.376 MiB)
    slot print_timing: id 0 | task 0 |
    prompt eval time = 90234.73 ms / 19892 tokens ( 4.54 ms per token, 220.45 tokens per second)
    eval time = 480.39 ms / 15 tokens ( 32.03 ms per token, 31.22 tokens per second)
    total time = 90715.12 ms / 19907 tokens
    slot release: id 0 | task 0 | stop processing: n_tokens = 19906, truncated = 0
    srv update_slots: all slots are idle
    srv log_server_r: done request: POST /chat/completions 192.168.0.3 200
    srv params_from_: Chat format: peg-constructed
    slot get_availabl: id 0 | task -1 | selected slot by LCP similarity, sim_best = 0.155 (> 0.100 thold), f_keep = 0.154
    srv get_availabl: updating prompt cache
    srv prompt_save: - saving prompt with length 19906, total state size = 206.820 MiB
    srv load: - looking for better prompt, base f_keep = 0.154, sim = 0.155
    srv update: - cache state: 1 prompts, 282.196 MiB (limits: 0.000 MiB, 128000 tokens, 128000 est)
    srv update: - prompt 0x55d0940067c0: 19906 tokens, checkpoints: 1, 282.196 MiB
    srv get_availabl: prompt cache update took 113.76 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 26 | processing task, is_child = 0
    slot update_slots: id 0 | task 26 | new prompt, n_ctx_slot = 128000, n_keep = 0, task.n_tokens = 19768
    slot update_slots: id 0 | task 26 | n_past = 3069, slot.prompt.tokens.size() = 19906, seq_id = 0, pos_min = 19905, n_swa = 1
    slot update_slots: id 0 | task 26 | forcing full prompt re-processing due to lack of cache data (likely due to SWA or hybrid/recurrent memory, see https://github.com//pull/13194#issuecomment-2868343055)
    slot update_slots: id 0 | task 26 | erased invalidated context checkpoint (pos_min = 19379, pos_max = 19379, n_swa = 1, size = 75.376 MiB)
    slot update_slots: id 0 | task 26 | n_tokens = 0, memory_seq_rm [0, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 2048, batch.n_tokens = 2048, progress = 0.103602
    slot update_slots: id 0 | task 26 | n_tokens = 2048, memory_seq_rm [2048, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 4096, batch.n_tokens = 2048, progress = 0.207204
    slot update_slots: id 0 | task 26 | n_tokens = 4096, memory_seq_rm [4096, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 6144, batch.n_tokens = 2048, progress = 0.310805
    slot update_slots: id 0 | task 26 | n_tokens = 6144, memory_seq_rm [6144, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 8192, batch.n_tokens = 2048, progress = 0.414407
    slot update_slots: id 0 | task 26 | n_tokens = 8192, memory_seq_rm [8192, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 10240, batch.n_tokens = 2048, progress = 0.518009
    slot update_slots: id 0 | task 26 | n_tokens = 10240, memory_seq_rm [10240, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 12288, batch.n_tokens = 2048, progress = 0.621611
    slot update_slots: id 0 | task 26 | n_tokens = 12288, memory_seq_rm [12288, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 14336, batch.n_tokens = 2048, progress = 0.725212
    slot update_slots: id 0 | task 26 | n_tokens = 14336, memory_seq_rm [14336, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 16384, batch.n_tokens = 2048, progress = 0.828814
    slot update_slots: id 0 | task 26 | n_tokens = 16384, memory_seq_rm [16384, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 18432, batch.n_tokens = 2048, progress = 0.932416
    slot update_slots: id 0 | task 26 | n_tokens = 18432, memory_seq_rm [18432, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 19256, batch.n_tokens = 824, progress = 0.974100
    slot update_slots: id 0 | task 26 | n_tokens = 19256, memory_seq_rm [19256, end)
    slot update_slots: id 0 | task 26 | prompt processing progress, n_tokens = 19768, batch.n_tokens = 512, progress = 1.000000
    slot update_slots: id 0 | task 26 | prompt done, n_tokens = 19768, batch.n_tokens = 512
    slot init_sampler: id 0 | task 26 | init sampler, took 1.52 ms, tokens: text = 19768, total = 19768
    slot update_slots: id 0 | task 26 | created context checkpoint 1 of 32 (pos_min = 19255, pos_max = 19255, size = 75.376 MiB)
    slot print_timing: id 0 | task 26 |
    prompt eval time = 90244.75 ms / 19768 tokens ( 4.57 ms per token, 219.05 tokens per second)
    eval time = 3481.50 ms / 93 tokens ( 37.44 ms per token, 26.71 tokens per second)
    total time = 93726.25 ms / 19861 tokens

  2. yamikumo-DSD commented on Feb 22, 2026

    @yamikumo-DSD

    I'm using Qwen3 Coder Next via llama-cpp-python and encountering same type of issue, where it seems to fail memory_seq_rm falling back to clearing KV cache entirely.
    Don't you experience the problem with Nemotron 3 Nano too?
    In my environment, these two models (and maybe Qwen3.5) cause the failure.

  3. pwilkin commented on Feb 22, 2026

    @pwilkin
    Member

    Please make sure that your tool doesn't change the prompt every time (eg. by embedding current time within the prompt). The message here says:

     slot update_slots: id 0 | task 26 | n_past = 3069, slot.prompt.tokens.size() = 19906, seq_id = 0, pos_min = 19905, n_swa = 1
    

    That means only a prefix of size 3069 from the entire prompt of 19906 was found to be usable - this suggests a changing system message.

  4. tech112233445566 commented on Feb 22, 2026

    @tech112233445566
    Author

    看来openclaw在连续对话的时候,重用的token过少导致了这个问题,谢谢,稍后我看一下我的openclaw是不是工具调用的时候,是不是更改信息量较大

  5. guillaumevds commented on Feb 23, 2026

    @guillaumevds

    Same issue here with the same model and the OpenClaw use case : complete reprocessing at each round.

    Same test and use case with glm4.7-flash, does NOT trigger full reprocessing.

  6. hsinyu-chen commented on Feb 23, 2026

    @hsinyu-chen

    keep n seems not work , my message is [fixed parts ] + [ dynamic parts] , it always force full pp every time , seems that cache only works for append only scenario

  7. WinPooh32 commented on Feb 24, 2026

    @WinPooh32

    It works well on build 8123 (f75c4e8). I had same issues running on older versions. Cache is not invalidated even on last checkpoint is reached. If invalidation happens, check that nothing is changed in the middle of your prompts. For example, I run Claude Code cli and it requires to set env CLAUDE_CODE_ATTRIBUTION_HEADER=0.

    My config (llama-swap):

    healthCheckTimeout: 300
    logRequests: true
    metricsMaxInMemory: 1000
    
    macros:
      llama-server: >
          "/run/host/run/media/system/Data/aivibe/llama.cpp/build/bin/llama-server"
          --parallel 1
          --port ${PORT}
          --offline
          --flash-attn on
          --jinja
          --timeout 2200
          --ctx-checkpoints 4
          --cache-ram 4096
          --kv-unified
          --cache-reuse 256
    
    models:
      "qwen3-coder-next-3bit":
        cmd: >
          ${llama-server}
          --threads 8
          --context-shift --ctx-size 200000 --fit-ctx 200000
          --fit-target 1024
          -ub 4096 -b 4096
          -ctk q8_0 -ctv q8_0
          --temp 1.0
          --top-p 0.95
          --top-k 40
          --min-p 0.01
          --repeat-penalty 1.0
          -m "${models}/Qwen3-Coder-Next-UD-IQ3_XXS.gguf"
  8. GavinAstk commented on Feb 24, 2026

    @GavinAstk

    I encountered the same issue when deploying Claude Code with llama.cpp and the unsloth/Qwen3-Coder-Next-GGUF:UD-Q8_K_XL model on my Strix Halo mini PC. After reading through PR #13194 and numerous discussions, it became clear that many people are facing this problem, but no solution had been found yet.

    To verify whether the cache-miss issue was truly caused by an incompatibility between Qwen3-Coder-Next and llama.cpp, I wrote a small test script to examine cache behavior:

    #!/bin/bash
    
    # Configure server address
    API_URL="http://localhost:8080/v1/chat/completions"
    
    echo "======================================================"
    echo "Qwen3 Cache Full Path Test (Three-Phase Verification)"
    echo "1. Cold Start | 2. Exact Match | 3. Prefix Match"
    echo "======================================================"
    
    # Generate three strictly controlled test files using Python
    python3 -c '
    import json
    # Construct a long code block of about 8000 tokens
    stable_code = "\n".join([f"function handle_event_type_{i}() {{ return \"result_{i}\"; }}" for i in range(1, 800)])
    
    def save_json(filename, task):
        data = {
            "model": "qwen3-coder",
            "messages": [
                {"role": "system", "content": "You are a Qwen3 Expert."},
                {"role": "user", "content": f"Context:\n{stable_code}\n\nTask: {task}"}
            ],
            "temperature": 0.0,
            "seed": 3407,
            "stream": False
        }
        with open(filename, "w", encoding="utf-8") as f:
            json.dump(data, f)
    
    # V1: Initial request
    save_json("test_v1.json", "Analyze the architecture.")
    # V2: Identical request
    save_json("test_v2.json", "Analyze the architecture.")
    # V3: Same prefix, only the final instruction changes (test prefix caching)
    save_json("test_v3.json", "Now refactor it to use classes.")
    '
    
    # --- Start testing ---
    
    echo -e "\n[TEST 1] Cold start (first load context)..."
    time curl -s -X POST $API_URL -H "Content-Type: application/json" -d @test_v1.json > /dev/null
    echo "Result: First calculation completed."
    
    echo -e "\n------------------------------------------------------"
    echo "[TEST 2] Exact match (verify full hash cache)..."
    echo "Expected: < 1s, logs should not show progress bar."
    time curl -s -X POST $API_URL -H "Content-Type: application/json" -d @test_v2.json > /dev/null
    
    echo -e "\n------------------------------------------------------"
    echo "[TEST 3] Prefix match (verify prefix caching)..."
    echo "Expected: < 2s (prefill should be skipped instantly, only inference time remains)."
    time curl -s -X POST $API_URL -H "Content-Type: application/json" -d @test_v3.json > /dev/null
    
    echo -e "\n======================================================"
    echo "Test finished. Observe the n_past value in the logs."
    rm test_v1.json test_v2.json test_v3.json

    The logs I obtained showed:

    srv  params_from_: Chat format: peg-constructed                                                                                                                                                         
    slot get_availabl: id  0 | task -1 | selected slot by LRU, t_last = -1                                                                                                                                  
    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 0 | processing task, is_child = 0                                                                                                                                       
    slot update_slots: id  0 | task 0 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 14995                                                                                                  
    slot update_slots: id  0 | task 0 | n_tokens = 0, memory_seq_rm [0, end)                                                                                                                                
    slot update_slots: id  0 | task 0 | prompt processing progress, n_tokens = 4096, batch.n_tokens = 4096, progress = 0.273158                                                                             
    slot update_slots: id  0 | task 0 | n_tokens = 4096, memory_seq_rm [4096, end)                                                                                                                          
    slot update_slots: id  0 | task 0 | prompt processing progress, n_tokens = 8192, batch.n_tokens = 4096, progress = 0.546315                                                                             
    slot update_slots: id  0 | task 0 | n_tokens = 8192, memory_seq_rm [8192, end)                                                                                                                          
    slot update_slots: id  0 | task 0 | prompt processing progress, n_tokens = 12288, batch.n_tokens = 4096, progress = 0.819473                                                                            
    slot update_slots: id  0 | task 0 | n_tokens = 12288, memory_seq_rm [12288, end)                                                                                                                        
    slot update_slots: id  0 | task 0 | prompt processing progress, n_tokens = 14483, batch.n_tokens = 2195, progress = 0.965855                                                                            
    slot update_slots: id  0 | task 0 | n_tokens = 14483, memory_seq_rm [14483, end)                                                                                                                        
    slot update_slots: id  0 | task 0 | prompt processing progress, n_tokens = 14995, batch.n_tokens = 512, progress = 1.000000                                                                             
    slot update_slots: id  0 | task 0 | prompt done, n_tokens = 14995, batch.n_tokens = 512                                                                                                                 
    slot init_sampler: id  0 | task 0 | init sampler, took 1.23 ms, tokens: text = 14995, total = 14995                                                                                                     
    slot update_slots: id  0 | task 0 | created context checkpoint 1 of 256 (pos_min = 14482, pos_max = 14482, size = 75.376 MiB)                                                                           
    slot print_timing: id  0 | task 0 |                                                                                                                                                                     
    prompt eval time =   33956.89 ms / 14995 tokens (    2.26 ms per token,   441.59 tokens per second)                                                                                                     
           eval time =   49135.66 ms /  1240 tokens (   39.63 ms per token,    25.24 tokens per second)                                                                                                     
          total time =   83092.55 ms / 16235 tokens                                                                                                                                                         
    slot      release: id  0 | task 0 | stop processing: n_tokens = 16234, truncated = 0                                                                                                                    
    srv  update_slots: all slots are idle                                                                                                                                                                   
    srv  log_server_r: done request: POST /v1/chat/completions 127.0.0.1 200                                                                                                                                
    srv  params_from_: Chat format: peg-constructed                                                                                                                                                         
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 1.000 (> 0.100 thold), f_keep = 0.924                                                                                  
    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 1245 | processing task, is_child = 0                                                                                                                                    
    slot update_slots: id  0 | task 1245 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 14995                                                                                               
    slot update_slots: id  0 | task 1245 | n_past = 14995, slot.prompt.tokens.size() = 16234, seq_id = 0, pos_min = 16233, n_swa = 1                                                                        
    slot update_slots: id  0 | task 1245 | restored context checkpoint (pos_min = 14482, pos_max = 14482, size = 75.376 MiB)                                                                                
    slot update_slots: id  0 | task 1245 | n_tokens = 14483, memory_seq_rm [14483, end)                                                                                                                     
    slot update_slots: id  0 | task 1245 | prompt processing progress, n_tokens = 14995, batch.n_tokens = 512, progress = 1.000000                                                                          
    slot update_slots: id  0 | task 1245 | prompt done, n_tokens = 14995, batch.n_tokens = 512                                                                                                              
    slot init_sampler: id  0 | task 1245 | init sampler, took 1.22 ms, tokens: text = 14995, total = 14995                                                                                                  
    slot print_timing: id  0 | task 1245 |                                                                                                                                                                  
    prompt eval time =    2038.29 ms /   512 tokens (    3.98 ms per token,   251.19 tokens per second)                                                                                                     
           eval time =   49139.80 ms /  1240 tokens (   39.63 ms per token,    25.23 tokens per second)                                                                                                     
          total time =   51178.09 ms /  1752 tokens                                                                                                                                                         
    slot      release: id  0 | task 1245 | stop processing: n_tokens = 16234, truncated = 0                                                                                                                 
    srv  update_slots: all slots are idle                                                                                                                                                                   
    srv  log_server_r: done request: POST /v1/chat/completions 127.0.0.1 200                                                                                                                                
    srv  params_from_: Chat format: peg-constructed                                                                                                                                                         
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.999 (> 0.100 thold), f_keep = 0.923                                                                                  
    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 2486 | processing task, is_child = 0                                                                                                                                    
    slot update_slots: id  0 | task 2486 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 14997                                                                                               
    slot update_slots: id  0 | task 2486 | n_past = 14985, slot.prompt.tokens.size() = 16234, seq_id = 0, pos_min = 16233, n_swa = 1                                                                        
    slot update_slots: id  0 | task 2486 | restored context checkpoint (pos_min = 14482, pos_max = 14482, size = 75.376 MiB)                                                                                
    slot update_slots: id  0 | task 2486 | n_tokens = 14483, memory_seq_rm [14483, end)                                                                                                                     
    slot update_slots: id  0 | task 2486 | prompt processing progress, n_tokens = 14485, batch.n_tokens = 2, progress = 0.965860                                                                            
    slot update_slots: id  0 | task 2486 | n_tokens = 14485, memory_seq_rm [14485, end)                                                                                                                     
    slot update_slots: id  0 | task 2486 | prompt processing progress, n_tokens = 14997, batch.n_tokens = 512, progress = 1.000000                                                                          
    slot update_slots: id  0 | task 2486 | prompt done, n_tokens = 14997, batch.n_tokens = 512                                                                                                              
    slot init_sampler: id  0 | task 2486 | init sampler, took 1.23 ms, tokens: text = 14997, total = 14997                                                                                                  
    slot print_timing: id  0 | task 2486 |                                                                                                                                                                  
    prompt eval time =    2147.03 ms /   514 tokens (    4.18 ms per token,   239.40 tokens per second)                                                                                                     
           eval time =   23334.91 ms /   591 tokens (   39.48 ms per token,    25.33 tokens per second)                                                                                                     
          total time =   25481.94 ms /  1105 tokens                                                                                                                                                         
    slot      release: id  0 | task 2486 | stop processing: n_tokens = 15587, truncated = 0                                                                                                                 
    srv  update_slots: all slots are idle                                                                                                                                                                   
    srv  log_server_r: done request: POST /v1/chat/completions 127.0.0.1 200
    

    From these logs, I observed that the problem disappeared—cache hits occurred when the same token prefix was used. The remaining time was mostly spent on the model's output token generation phase.

    A comment in PR #19408 caught my attention: "this looks like OpenCode modifying something early in the prompt."

    Inspired by this, I wrote a simple proxy and set Claude Code's base URL to http://localhost:8081 (the proxy's port) to forward requests directly.

    simple_proxy_v1.py:

    # /// script
    # dependencies = [
    #   "flask",
    #   "requests",
    # ]
    # ///
    
    import json
    import time
    import uuid
    from flask import Flask, request, Response, stream_with_context
    import requests
    
    app = Flask(__name__)
    
    TARGET_URL = "http://localhost:8080/v1/messages"  # Your llama.cpp endpoint
    LOG_FILE = "proxy.log"
    
    def log_request_response(req_id, direction, data):
        timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
        log_line = f"[{timestamp}] [{req_id}] [{direction}]\n"
        if isinstance(data, (dict, list)):
            log_line += json.dumps(data, indent=2, ensure_ascii=False)
        else:
            log_line += str(data)
        log_line += "\n" + "-"*80 + "\n"
        print(log_line)
        with open(LOG_FILE, "a", encoding="utf-8") as f:
            f.write(log_line)
    
    @app.route('/v1/messages/count_tokens', methods=['POST'])
    def count_tokens():
        """Simulate token counting to avoid client hanging"""
        data = request.get_json()
        total_chars = 0
        # Count text in messages
        for msg in data.get('messages', []):
            content = msg.get('content', '')
            if isinstance(content, str):
                total_chars += len(content)
            elif isinstance(content, list):
                for block in content:
                    if block.get('type') == 'text':
                        total_chars += len(block.get('text', ''))
        # Count text in system
        for sys_block in data.get('system', []):
            if sys_block.get('type') == 'text':
                total_chars += len(sys_block.get('text', ''))
        # Rough estimate: 1 token ≈ 4 characters
        estimated_tokens = max(1, total_chars // 4)
        return {
            "input_tokens": estimated_tokens,
            "output_tokens": 0
        }
    
    @app.route('/v1/messages', methods=['POST'])
    @app.route('/v1/chat/completions', methods=['POST'])
    def proxy():
        req_id = str(uuid.uuid4())[:8]
        request_data = request.get_json()
        log_request_response(req_id, "REQUEST", request_data)
    
        try:
            resp = requests.post(
                TARGET_URL,
                json=request_data,
                stream=True,
                headers={"Content-Type": "application/json"},
                timeout=600
            )
        except Exception as e:
            error_msg = f"Forward request failed: {e}"
            log_request_response(req_id, "ERROR", error_msg)
            return Response(error_msg, status=500)
    
        def generate():
            collected_chunks = []
            for chunk in resp.iter_content(chunk_size=4096):
                if chunk:
                    yield chunk
                    collected_chunks.append(chunk)
            full_response = b"".join(collected_chunks).decode('utf-8', errors='replace')
            log_request_response(req_id, "RESPONSE", full_response)
    
        return Response(
            stream_with_context(generate()),
            status=resp.status_code,
            headers=dict(resp.headers)
        )
    
    if __name__ == '__main__':
        print(f"Starting proxy, listening on 0.0.0.0:8081, forwarding to {TARGET_URL}")
        print(f"Logs saved to {LOG_FILE}")
        app.run(host='0.0.0.0', port=8081, debug=False)

    I discovered that Claude injects additional content on every turn. While this might be useful for Claude's own users, for local model users it's entirely unnecessary—and worse, it breaks prompt prefix caching. Then I shared the logs and simple_proxy_v1.py with DeepSeek to help analyze exactly what content Claude Code injects. With DeepSeek's assistance, I obtained simple_proxy_v2.py:

    simple_proxy_v2.py:

    # /// script
    # dependencies = [
    #   "flask",
    #   "requests",
    # ]
    # ///
    
    import json
    import re
    import time
    import uuid
    from flask import Flask, request, Response, stream_with_context
    import requests
    
    app = Flask(__name__)
    
    # Target llama.cpp endpoint (modify according to your setup)
    TARGET_URL = "http://localhost:8080/v1/messages"
    
    LOG_FILE = "proxy.log"
    
    def log_message(req_id, direction, data):
        """Log request/response to console and log file"""
        timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
        log_line = f"[{timestamp}] [{req_id}] [{direction}]\n"
        if isinstance(data, (dict, list)):
            log_line += json.dumps(data, indent=2, ensure_ascii=False)
        else:
            log_line += str(data)
        log_line += "\n" + "-"*80 + "\n"
    
        print(log_line)
        with open(LOG_FILE, "a", encoding="utf-8") as f:
            f.write(log_line)
    
    def clean_system_text(text):
        """Clean useless tags from system text (applied only to kept blocks)"""
        # Remove <fast_mode_info> and its content
        text = re.sub(r'<fast_mode_info>.*?</fast_mode_info>', '', text, flags=re.DOTALL)
        # Remove <claude_background_info> and its content
        text = re.sub(r'<claude_background_info>.*?</claude_background_info>', '', text, flags=re.DOTALL)
        # Remove billing header line (extra safety, since whole block containing it is usually dropped)
        text = re.sub(r'^x-anthropic-billing-header:.*$', '', text, flags=re.MULTILINE)
        # Collapse excessive blank lines (optional)
        text = re.sub(r'\n\s*\n', '\n\n', text)
        return text.strip()
    
    def fix_request(data):
        """Apply unstripping to the request"""
        # 1. Fix the model field
        if "model" in data:
            data["model"] = "Qwen3-Coder-Next-80B-128K"  # Replace with your actual model name
    
        # 2. Clean the system array
        if "system" in data and isinstance(data["system"], list):
            new_system = []
            for block in data["system"]:
                if block.get("type") == "text":
                    text = block.get("text", "")
                    # Drop whole blocks containing specific strings
                    if "SessionStart:startup hook success: Success" in text:
                        continue
                    if "x-anthropic-billing-header" in text:
                        continue
                    if "You are Claude Code" in text:
                        continue
    
                    # Apply tag cleaning to kept blocks
                    cleaned = clean_system_text(text)
                    if cleaned:
                        block["text"] = cleaned
                        new_system.append(block)
                    # If cleaned is empty, drop the block
                else:
                    # Non-text blocks (e.g., cache_control) are kept
                    new_system.append(block)
            data["system"] = new_system
    
        return data
    
    @app.route('/v1/messages/count_tokens', methods=['POST'])
    def count_tokens():
        """Simulate token counting to avoid client stalling"""
        # Simply return an estimated value, does not affect actual usage
        return {
            "input_tokens": 100,
            "output_tokens": 0
        }
    
    @app.route('/v1/messages', methods=['POST'])
    @app.route('/v1/chat/completions', methods=['POST'])
    def proxy():
        req_id = str(uuid.uuid4())[:8]
    
        # Get and log original request
        original_data = request.get_json()
        log_message(req_id, "ORIGINAL_REQUEST", original_data)
    
        # Apply unstripping
        fixed_data = fix_request(original_data)
    
        # Log modified request
        log_message(req_id, "FIXED_REQUEST", fixed_data)
    
        # Forward to target server
        try:
            resp = requests.post(
                TARGET_URL,
                json=fixed_data,
                stream=True,
                headers={"Content-Type": "application/json"},
                timeout=600
            )
        except Exception as e:
            error_msg = f"Forward request failed: {e}"
            log_message(req_id, "ERROR", error_msg)
            return Response(error_msg, status=500)
    
        # Handle streaming response
        def generate():
            collected_chunks = []
            for chunk in resp.iter_content(chunk_size=4096):
                if chunk:
                    yield chunk
                    collected_chunks.append(chunk)
    
            # Log full response after it ends
            full_response = b"".join(collected_chunks).decode('utf-8', errors='replace')
            log_message(req_id, "RESPONSE", full_response)
    
        return Response(
            stream_with_context(generate()),
            status=resp.status_code,
            headers=dict(resp.headers)
        )
    
    if __name__ == '__main__':
        print(f"Starting proxy, listening on 0.0.0.0:8081, forwarding to {TARGET_URL}")
        print(f"Logs will be saved to {LOG_FILE}")
        app.run(host='0.0.0.0', port=8081, debug=False)

    Here’s what I observed after applying the improved proxy:

    srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
    slot print_timing: id  0 | task 421 | 
    prompt eval time =    6673.44 ms /  1402 tokens (    4.76 ms per token,   210.09 tokens per second)
           eval time =    1917.82 ms /    48 tokens (   39.95 ms per token,    25.03 tokens per second)
          total time =    8591.25 ms /  1450 tokens
    slot      release: id  0 | task 421 | stop processing: n_tokens = 19633, truncated = 0
    srv  update_slots: all slots are idle
    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.986 (> 0.100 thold), f_keep = 1.000
    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 471 | processing task, is_child = 0
    slot update_slots: id  0 | task 471 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 19914
    slot update_slots: id  0 | task 471 | n_past = 19631, slot.prompt.tokens.size() = 19633, seq_id = 0, pos_min = 19632, n_swa = 1
    slot update_slots: id  0 | task 471 | restored context checkpoint (pos_min = 19073, pos_max = 19073, size = 75.376 MiB)
    slot update_slots: id  0 | task 471 | n_tokens = 19074, memory_seq_rm [19074, end)
    slot update_slots: id  0 | task 471 | prompt processing progress, n_tokens = 19402, batch.n_tokens = 328, progress = 0.974289
    slot update_slots: id  0 | task 471 | n_tokens = 19402, memory_seq_rm [19402, end)
    slot update_slots: id  0 | task 471 | prompt processing progress, n_tokens = 19914, batch.n_tokens = 512, progress = 1.000000
    slot update_slots: id  0 | task 471 | prompt done, n_tokens = 19914, batch.n_tokens = 512
    slot init_sampler: id  0 | task 471 | init sampler, took 1.63 ms, tokens: text = 19914, total = 19914
    slot update_slots: id  0 | task 471 | created context checkpoint 6 of 256 (pos_min = 19401, pos_max = 19401, size = 75.376 MiB)
    srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
    slot print_timing: id  0 | task 471 | 
    prompt eval time =    4713.30 ms /   840 tokens (    5.61 ms per token,   178.22 tokens per second)
           eval time =    2060.38 ms /    51 tokens (   40.40 ms per token,    24.75 tokens per second)
          total time =    6773.67 ms /   891 tokens
    slot      release: id  0 | task 471 | stop processing: n_tokens = 19964, truncated = 0
    srv  update_slots: all slots are idle
    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.979 (> 0.100 thold), f_keep = 1.000
    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 524 | processing task, is_child = 0
    slot update_slots: id  0 | task 524 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 20393
    slot update_slots: id  0 | task 524 | n_past = 19962, slot.prompt.tokens.size() = 19964, seq_id = 0, pos_min = 19963, n_swa = 1
    slot update_slots: id  0 | task 524 | restored context checkpoint (pos_min = 19401, pos_max = 19401, size = 75.376 MiB)
    slot update_slots: id  0 | task 524 | n_tokens = 19402, memory_seq_rm [19402, end)
    slot update_slots: id  0 | task 524 | prompt processing progress, n_tokens = 19881, batch.n_tokens = 479, progress = 0.974893
    slot update_slots: id  0 | task 524 | n_tokens = 19881, memory_seq_rm [19881, end)
    slot update_slots: id  0 | task 524 | prompt processing progress, n_tokens = 20393, batch.n_tokens = 512, progress = 1.000000
    slot update_slots: id  0 | task 524 | prompt done, n_tokens = 20393, batch.n_tokens = 512
    slot init_sampler: id  0 | task 524 | init sampler, took 1.67 ms, tokens: text = 20393, total = 20393
    slot update_slots: id  0 | task 524 | created context checkpoint 7 of 256 (pos_min = 19880, pos_max = 19880, size = 75.376 MiB)
    srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
    slot print_timing: id  0 | task 524 | 
    prompt eval time =    5576.11 ms /   991 tokens (    5.63 ms per token,   177.72 tokens per second)
           eval time =    1923.23 ms /    48 tokens (   40.07 ms per token,    24.96 tokens per second)
          total time =    7499.34 ms /  1039 tokens
    slot      release: id  0 | task 524 | stop processing: n_tokens = 20440, truncated = 0
    srv  update_slots: all slots are idle
    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.956 (> 0.100 thold), f_keep = 1.000
    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 574 | processing task, is_child = 0
    slot update_slots: id  0 | task 574 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 21377
    slot update_slots: id  0 | task 574 | n_tokens = 20440, memory_seq_rm [20440, end)
    slot update_slots: id  0 | task 574 | prompt processing progress, n_tokens = 20865, batch.n_tokens = 425, progress = 0.976049
    slot update_slots: id  0 | task 574 | n_tokens = 20865, memory_seq_rm [20865, end)
    slot update_slots: id  0 | task 574 | prompt processing progress, n_tokens = 21377, batch.n_tokens = 512, progress = 1.000000
    slot update_slots: id  0 | task 574 | prompt done, n_tokens = 21377, batch.n_tokens = 512
    slot init_sampler: id  0 | task 574 | init sampler, took 1.75 ms, tokens: text = 21377, total = 21377
    slot update_slots: id  0 | task 574 | created context checkpoint 8 of 256 (pos_min = 20864, pos_max = 20864, size = 75.376 MiB)
    srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
    slot print_timing: id  0 | task 574 | 
    prompt eval time =    5182.17 ms /   937 tokens (    5.53 ms per token,   180.81 tokens per second)
           eval time =     948.68 ms /    24 tokens (   39.53 ms per token,    25.30 tokens per second)
          total time =    6130.85 ms /   961 tokens
    slot      release: id  0 | task 574 | stop processing: n_tokens = 21400, truncated = 0
    srv  update_slots: all slots are idle
    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.998 (> 0.100 thold), f_keep = 1.000
    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 600 | processing task, is_child = 0
    slot update_slots: id  0 | task 600 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 21449
    slot update_slots: id  0 | task 600 | n_tokens = 21400, memory_seq_rm [21400, end)
    slot update_slots: id  0 | task 600 | prompt processing progress, n_tokens = 21449, batch.n_tokens = 49, progress = 1.000000
    slot update_slots: id  0 | task 600 | prompt done, n_tokens = 21449, batch.n_tokens = 49
    slot init_sampler: id  0 | task 600 | init sampler, took 1.80 ms, tokens: text = 21449, total = 21449
    slot update_slots: id  0 | task 600 | created context checkpoint 9 of 256 (pos_min = 21399, pos_max = 21399, size = 75.376 MiB)
    srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
    slot print_timing: id  0 | task 600 | 
    prompt eval time =     361.10 ms /    49 tokens (    7.37 ms per token,   135.69 tokens per second)
           eval time =     989.97 ms /    25 tokens (   39.60 ms per token,    25.25 tokens per second)
          total time =    1351.08 ms /    74 tokens
    slot      release: id  0 | task 600 | stop processing: n_tokens = 21473, truncated = 0
    srv  update_slots: all slots are idle
    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.998 (> 0.100 thold), f_keep = 1.000
    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 626 | processing task, is_child = 0
    slot update_slots: id  0 | task 626 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 21522
    slot update_slots: id  0 | task 626 | n_tokens = 21473, memory_seq_rm [21473, end)
    slot update_slots: id  0 | task 626 | prompt processing progress, n_tokens = 21522, batch.n_tokens = 49, progress = 1.000000
    slot update_slots: id  0 | task 626 | prompt done, n_tokens = 21522, batch.n_tokens = 49
    slot init_sampler: id  0 | task 626 | init sampler, took 1.80 ms, tokens: text = 21522, total = 21522
    slot update_slots: id  0 | task 626 | created context checkpoint 10 of 256 (pos_min = 21472, pos_max = 21472, size = 75.376 MiB)
    

    The log message forcing full prompt re-processing due to lack of cache data (likely due to SWA or hybrid/recurrent memory, see https://github.com//pull/13194#issuecomment-2868343055) disappeared, and the cache hit rate approached 100%. The task I used for testing in Claude Code dropped from 20 minutes to 2 minutes (still slow, but a huge improvement). At this point, the cache miss issue was finally resolved. Due to my limited knowledge of low‑level AI details, I cannot determine whether this problem is related to the --swa-full parameter (PR #13194).

    To be clear, the issue does not stem from Qwen3-Coder-Next or llama.cpp; it is entirely a prompt-side problem.

    The above is my complete troubleshooting process and solution. I believe others using different coding agents can replicate it through the example above, and the problem can ultimately be solved.

  9. Dampfinchen commented on Feb 24, 2026

    @Dampfinchen

    Now that the new smaller Qwen 3.5's released, I am able to run the Qwen next architecture. It also always reprocesses the prompt for me with Qwen 3.5 A35B A3B.

    slot update_slots: id 3 | task 17222 | 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)

  10. xTimeCrystal commented on Feb 25, 2026

    @xTimeCrystal

    Now that the new smaller Qwen 3.5's released, I am able to run the Qwen next architecture. It also always reprocesses the prompt for me with Qwen 3.5 A35B A3B.

    slot update_slots: id 3 | task 17222 | 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)

    Same issue here with Qwen3.5-35B-A3B. The root cause is that Qwen3.5/Next uses a hybrid architecture (Gated Delta Networks for 3/4 layers, full attention for 1/4), and the Qwen team recommends deleting <think>...</think> content after each turn to prevent context bloat. But deleting those tokens shifts the sequence, invalidating the checkpoint — and since the GDN recurrent state S is fixed-size and path-dependent (unlike KV cache which can be prefix-matched), llama.cpp has no valid checkpoint to restore from and falls back to full reprocessing.

    Two potential fixes I've been thinking about:

    1. Selective layer reprocessing: When a checkpoint is partially valid (i.e. the attention KV cache prefix still matches), only reprocess the recurrent/GDN layers and reuse the cached KV for attention layers. The recurrent state S has to be recomputed sequentially anyway, but this would at least keep prompt processing speed constant with context length rather than scaling linearly since the attention layers (1/4 of the model) would be free.

    2. Speculative state caching on known-ephemeral tokens: Since the <think> start token is known in advance, cache a checkpoint at the <think> token boundary. When the think content is later deleted, you already have the valid recurrent state from before the reasoning started — no reprocessing needed at all. This is essentially a model-aware cache hint: "I know everything after this token will be discarded, save state here."

    cc @pwilkin would love your thoughts on feasibility here.

  11. ozdang commented on Feb 25, 2026

    @ozdang

    I encountered the same issue when deploying Claude Code with llama.cpp and the unsloth/Qwen3-Coder-Next-GGUF:UD-Q8_K_XL model on my Strix Halo mini PC. After reading through PR #13194 and numerous discussions, it became clear that many people are facing this problem, but no solution had been found yet.

    To verify whether the cache-miss issue was truly caused by an incompatibility between Qwen3-Coder-Next and llama.cpp, I wrote a small test script to examine cache behavior:

    #!/bin/bash

    Configure server address

    API_URL="http://localhost:8080/v1/chat/completions"

    echo "======================================================"
    echo "Qwen3 Cache Full Path Test (Three-Phase Verification)"
    echo "1. Cold Start | 2. Exact Match | 3. Prefix Match"
    echo "======================================================"

    Generate three strictly controlled test files using Python

    python3 -c '
    import json

    Construct a long code block of about 8000 tokens

    stable_code = "\n".join([f"function handle_event_type_{i}() {{ return "result_{i}"; }}" for i in range(1, 800)])

    def save_json(filename, task):
    data = {
    "model": "qwen3-coder",
    "messages": [
    {"role": "system", "content": "You are a Qwen3 Expert."},
    {"role": "user", "content": f"Context:\n{stable_code}\n\nTask: {task}"}
    ],
    "temperature": 0.0,
    "seed": 3407,
    "stream": False
    }
    with open(filename, "w", encoding="utf-8") as f:
    json.dump(data, f)

    V1: Initial request

    save_json("test_v1.json", "Analyze the architecture.")

    V2: Identical request

    save_json("test_v2.json", "Analyze the architecture.")

    V3: Same prefix, only the final instruction changes (test prefix caching)

    save_json("test_v3.json", "Now refactor it to use classes.")
    '

    --- Start testing ---

    echo -e "\n[TEST 1] Cold start (first load context)..."
    time curl -s -X POST $API_URL -H "Content-Type: application/json" -d @test_v1.json > /dev/null
    echo "Result: First calculation completed."

    echo -e "\n------------------------------------------------------"
    echo "[TEST 2] Exact match (verify full hash cache)..."
    echo "Expected: < 1s, logs should not show progress bar."
    time curl -s -X POST $API_URL -H "Content-Type: application/json" -d @test_v2.json > /dev/null

    echo -e "\n------------------------------------------------------"
    echo "[TEST 3] Prefix match (verify prefix caching)..."
    echo "Expected: < 2s (prefill should be skipped instantly, only inference time remains)."
    time curl -s -X POST $API_URL -H "Content-Type: application/json" -d @test_v3.json > /dev/null

    echo -e "\n======================================================"
    echo "Test finished. Observe the n_past value in the logs."
    rm test_v1.json test_v2.json test_v3.json
    The logs I obtained showed:

    srv  params_from_: Chat format: peg-constructed                                                                                                                                                         
    slot get_availabl: id  0 | task -1 | selected slot by LRU, t_last = -1                                                                                                                                  
    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 0 | processing task, is_child = 0                                                                                                                                       
    slot update_slots: id  0 | task 0 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 14995                                                                                                  
    slot update_slots: id  0 | task 0 | n_tokens = 0, memory_seq_rm [0, end)                                                                                                                                
    slot update_slots: id  0 | task 0 | prompt processing progress, n_tokens = 4096, batch.n_tokens = 4096, progress = 0.273158                                                                             
    slot update_slots: id  0 | task 0 | n_tokens = 4096, memory_seq_rm [4096, end)                                                                                                                          
    slot update_slots: id  0 | task 0 | prompt processing progress, n_tokens = 8192, batch.n_tokens = 4096, progress = 0.546315                                                                             
    slot update_slots: id  0 | task 0 | n_tokens = 8192, memory_seq_rm [8192, end)                                                                                                                          
    slot update_slots: id  0 | task 0 | prompt processing progress, n_tokens = 12288, batch.n_tokens = 4096, progress = 0.819473                                                                            
    slot update_slots: id  0 | task 0 | n_tokens = 12288, memory_seq_rm [12288, end)                                                                                                                        
    slot update_slots: id  0 | task 0 | prompt processing progress, n_tokens = 14483, batch.n_tokens = 2195, progress = 0.965855                                                                            
    slot update_slots: id  0 | task 0 | n_tokens = 14483, memory_seq_rm [14483, end)                                                                                                                        
    slot update_slots: id  0 | task 0 | prompt processing progress, n_tokens = 14995, batch.n_tokens = 512, progress = 1.000000                                                                             
    slot update_slots: id  0 | task 0 | prompt done, n_tokens = 14995, batch.n_tokens = 512                                                                                                                 
    slot init_sampler: id  0 | task 0 | init sampler, took 1.23 ms, tokens: text = 14995, total = 14995                                                                                                     
    slot update_slots: id  0 | task 0 | created context checkpoint 1 of 256 (pos_min = 14482, pos_max = 14482, size = 75.376 MiB)                                                                           
    slot print_timing: id  0 | task 0 |                                                                                                                                                                     
    prompt eval time =   33956.89 ms / 14995 tokens (    2.26 ms per token,   441.59 tokens per second)                                                                                                     
           eval time =   49135.66 ms /  1240 tokens (   39.63 ms per token,    25.24 tokens per second)                                                                                                     
          total time =   83092.55 ms / 16235 tokens                                                                                                                                                         
    slot      release: id  0 | task 0 | stop processing: n_tokens = 16234, truncated = 0                                                                                                                    
    srv  update_slots: all slots are idle                                                                                                                                                                   
    srv  log_server_r: done request: POST /v1/chat/completions 127.0.0.1 200                                                                                                                                
    srv  params_from_: Chat format: peg-constructed                                                                                                                                                         
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 1.000 (> 0.100 thold), f_keep = 0.924                                                                                  
    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 1245 | processing task, is_child = 0                                                                                                                                    
    slot update_slots: id  0 | task 1245 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 14995                                                                                               
    slot update_slots: id  0 | task 1245 | n_past = 14995, slot.prompt.tokens.size() = 16234, seq_id = 0, pos_min = 16233, n_swa = 1                                                                        
    slot update_slots: id  0 | task 1245 | restored context checkpoint (pos_min = 14482, pos_max = 14482, size = 75.376 MiB)                                                                                
    slot update_slots: id  0 | task 1245 | n_tokens = 14483, memory_seq_rm [14483, end)                                                                                                                     
    slot update_slots: id  0 | task 1245 | prompt processing progress, n_tokens = 14995, batch.n_tokens = 512, progress = 1.000000                                                                          
    slot update_slots: id  0 | task 1245 | prompt done, n_tokens = 14995, batch.n_tokens = 512                                                                                                              
    slot init_sampler: id  0 | task 1245 | init sampler, took 1.22 ms, tokens: text = 14995, total = 14995                                                                                                  
    slot print_timing: id  0 | task 1245 |                                                                                                                                                                  
    prompt eval time =    2038.29 ms /   512 tokens (    3.98 ms per token,   251.19 tokens per second)                                                                                                     
           eval time =   49139.80 ms /  1240 tokens (   39.63 ms per token,    25.23 tokens per second)                                                                                                     
          total time =   51178.09 ms /  1752 tokens                                                                                                                                                         
    slot      release: id  0 | task 1245 | stop processing: n_tokens = 16234, truncated = 0                                                                                                                 
    srv  update_slots: all slots are idle                                                                                                                                                                   
    srv  log_server_r: done request: POST /v1/chat/completions 127.0.0.1 200                                                                                                                                
    srv  params_from_: Chat format: peg-constructed                                                                                                                                                         
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.999 (> 0.100 thold), f_keep = 0.923                                                                                  
    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 2486 | processing task, is_child = 0                                                                                                                                    
    slot update_slots: id  0 | task 2486 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 14997                                                                                               
    slot update_slots: id  0 | task 2486 | n_past = 14985, slot.prompt.tokens.size() = 16234, seq_id = 0, pos_min = 16233, n_swa = 1                                                                        
    slot update_slots: id  0 | task 2486 | restored context checkpoint (pos_min = 14482, pos_max = 14482, size = 75.376 MiB)                                                                                
    slot update_slots: id  0 | task 2486 | n_tokens = 14483, memory_seq_rm [14483, end)                                                                                                                     
    slot update_slots: id  0 | task 2486 | prompt processing progress, n_tokens = 14485, batch.n_tokens = 2, progress = 0.965860                                                                            
    slot update_slots: id  0 | task 2486 | n_tokens = 14485, memory_seq_rm [14485, end)                                                                                                                     
    slot update_slots: id  0 | task 2486 | prompt processing progress, n_tokens = 14997, batch.n_tokens = 512, progress = 1.000000                                                                          
    slot update_slots: id  0 | task 2486 | prompt done, n_tokens = 14997, batch.n_tokens = 512                                                                                                              
    slot init_sampler: id  0 | task 2486 | init sampler, took 1.23 ms, tokens: text = 14997, total = 14997                                                                                                  
    slot print_timing: id  0 | task 2486 |                                                                                                                                                                  
    prompt eval time =    2147.03 ms /   514 tokens (    4.18 ms per token,   239.40 tokens per second)                                                                                                     
           eval time =   23334.91 ms /   591 tokens (   39.48 ms per token,    25.33 tokens per second)                                                                                                     
          total time =   25481.94 ms /  1105 tokens                                                                                                                                                         
    slot      release: id  0 | task 2486 | stop processing: n_tokens = 15587, truncated = 0                                                                                                                 
    srv  update_slots: all slots are idle                                                                                                                                                                   
    srv  log_server_r: done request: POST /v1/chat/completions 127.0.0.1 200
    

    From these logs, I observed that the problem disappeared—cache hits occurred when the same token prefix was used. The remaining time was mostly spent on the model's output token generation phase.

    A comment in PR #19408 caught my attention: "this looks like OpenCode modifying something early in the prompt."

    Inspired by this, I wrote a simple proxy and set Claude Code's base URL to http://localhost:8081 (the proxy's port) to forward requests directly.

    simple_proxy_v1.py:

    /// script

    dependencies = [

    "flask",

    "requests",

    ]

    ///

    import json
    import time
    import uuid
    from flask import Flask, request, Response, stream_with_context
    import requests

    app = Flask(name)

    TARGET_URL = "http://localhost:8080/v1/messages" # Your llama.cpp endpoint
    LOG_FILE = "proxy.log"

    def log_request_response(req_id, direction, data):
    timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
    log_line = f"[{timestamp}] [{req_id}] [{direction}]\n"
    if isinstance(data, (dict, list)):
    log_line += json.dumps(data, indent=2, ensure_ascii=False)
    else:
    log_line += str(data)
    log_line += "\n" + "-"*80 + "\n"
    print(log_line)
    with open(LOG_FILE, "a", encoding="utf-8") as f:
    f.write(log_line)

    @app.route('/v1/messages/count_tokens', methods=['POST'])
    def count_tokens():
    """Simulate token counting to avoid client hanging"""
    data = request.get_json()
    total_chars = 0
    # Count text in messages
    for msg in data.get('messages', []):
    content = msg.get('content', '')
    if isinstance(content, str):
    total_chars += len(content)
    elif isinstance(content, list):
    for block in content:
    if block.get('type') == 'text':
    total_chars += len(block.get('text', ''))
    # Count text in system
    for sys_block in data.get('system', []):
    if sys_block.get('type') == 'text':
    total_chars += len(sys_block.get('text', ''))
    # Rough estimate: 1 token ≈ 4 characters
    estimated_tokens = max(1, total_chars // 4)
    return {
    "input_tokens": estimated_tokens,
    "output_tokens": 0
    }

    @app.route('/v1/messages', methods=['POST'])
    @app.route('/v1/chat/completions', methods=['POST'])
    def proxy():
    req_id = str(uuid.uuid4())[:8]
    request_data = request.get_json()
    log_request_response(req_id, "REQUEST", request_data)

    try:
        resp = requests.post(
            TARGET_URL,
            json=request_data,
            stream=True,
            headers={"Content-Type": "application/json"},
            timeout=600
        )
    except Exception as e:
        error_msg = f"Forward request failed: {e}"
        log_request_response(req_id, "ERROR", error_msg)
        return Response(error_msg, status=500)
    
    def generate():
        collected_chunks = []
        for chunk in resp.iter_content(chunk_size=4096):
            if chunk:
                yield chunk
                collected_chunks.append(chunk)
        full_response = b"".join(collected_chunks).decode('utf-8', errors='replace')
        log_request_response(req_id, "RESPONSE", full_response)
    
    return Response(
        stream_with_context(generate()),
        status=resp.status_code,
        headers=dict(resp.headers)
    )
    

    if name == 'main':
    print(f"Starting proxy, listening on 0.0.0.0:8081, forwarding to {TARGET_URL}")
    print(f"Logs saved to {LOG_FILE}")
    app.run(host='0.0.0.0', port=8081, debug=False)
    I discovered that Claude injects additional content on every turn. While this might be useful for Claude's own users, for local model users it's entirely unnecessary—and worse, it breaks prompt prefix caching. Then I shared the logs and simple_proxy_v1.py with DeepSeek to help analyze exactly what content Claude Code injects. With DeepSeek's assistance, I obtained simple_proxy_v2.py:

    simple_proxy_v2.py:

    /// script

    dependencies = [

    "flask",

    "requests",

    ]

    ///

    import json
    import re
    import time
    import uuid
    from flask import Flask, request, Response, stream_with_context
    import requests

    app = Flask(name)

    Target llama.cpp endpoint (modify according to your setup)

    TARGET_URL = "http://localhost:8080/v1/messages"

    LOG_FILE = "proxy.log"

    def log_message(req_id, direction, data):
    """Log request/response to console and log file"""
    timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
    log_line = f"[{timestamp}] [{req_id}] [{direction}]\n"
    if isinstance(data, (dict, list)):
    log_line += json.dumps(data, indent=2, ensure_ascii=False)
    else:
    log_line += str(data)
    log_line += "\n" + "-"*80 + "\n"

    print(log_line)
    with open(LOG_FILE, "a", encoding="utf-8") as f:
        f.write(log_line)
    

    def clean_system_text(text):
    """Clean useless tags from system text (applied only to kept blocks)"""
    # Remove <fast_mode_info> and its content
    text = re.sub(r'<fast_mode_info>.?</fast_mode_info>', '', text, flags=re.DOTALL)
    # Remove <claude_background_info> and its content
    text = re.sub(r'<claude_background_info>.
    ?</claude_background_info>', '', text, flags=re.DOTALL)
    # Remove billing header line (extra safety, since whole block containing it is usually dropped)
    text = re.sub(r'^x-anthropic-billing-header:.$', '', text, flags=re.MULTILINE)
    # Collapse excessive blank lines (optional)
    text = re.sub(r'\n\s
    \n', '\n\n', text)
    return text.strip()

    def fix_request(data):
    """Apply unstripping to the request"""
    # 1. Fix the model field
    if "model" in data:
    data["model"] = "Qwen3-Coder-Next-80B-128K" # Replace with your actual model name

    # 2. Clean the system array
    if "system" in data and isinstance(data["system"], list):
        new_system = []
        for block in data["system"]:
            if block.get("type") == "text":
                text = block.get("text", "")
                # Drop whole blocks containing specific strings
                if "SessionStart:startup hook success: Success" in text:
                    continue
                if "x-anthropic-billing-header" in text:
                    continue
                if "You are Claude Code" in text:
                    continue
    
                # Apply tag cleaning to kept blocks
                cleaned = clean_system_text(text)
                if cleaned:
                    block["text"] = cleaned
                    new_system.append(block)
                # If cleaned is empty, drop the block
            else:
                # Non-text blocks (e.g., cache_control) are kept
                new_system.append(block)
        data["system"] = new_system
    
    return data
    

    @app.route('/v1/messages/count_tokens', methods=['POST'])
    def count_tokens():
    """Simulate token counting to avoid client stalling"""
    # Simply return an estimated value, does not affect actual usage
    return {
    "input_tokens": 100,
    "output_tokens": 0
    }

    @app.route('/v1/messages', methods=['POST'])
    @app.route('/v1/chat/completions', methods=['POST'])
    def proxy():
    req_id = str(uuid.uuid4())[:8]

    # Get and log original request
    original_data = request.get_json()
    log_message(req_id, "ORIGINAL_REQUEST", original_data)
    
    # Apply unstripping
    fixed_data = fix_request(original_data)
    
    # Log modified request
    log_message(req_id, "FIXED_REQUEST", fixed_data)
    
    # Forward to target server
    try:
        resp = requests.post(
            TARGET_URL,
            json=fixed_data,
            stream=True,
            headers={"Content-Type": "application/json"},
            timeout=600
        )
    except Exception as e:
        error_msg = f"Forward request failed: {e}"
        log_message(req_id, "ERROR", error_msg)
        return Response(error_msg, status=500)
    
    # Handle streaming response
    def generate():
        collected_chunks = []
        for chunk in resp.iter_content(chunk_size=4096):
            if chunk:
                yield chunk
                collected_chunks.append(chunk)
    
        # Log full response after it ends
        full_response = b"".join(collected_chunks).decode('utf-8', errors='replace')
        log_message(req_id, "RESPONSE", full_response)
    
    return Response(
        stream_with_context(generate()),
        status=resp.status_code,
        headers=dict(resp.headers)
    )
    

    if name == 'main':
    print(f"Starting proxy, listening on 0.0.0.0:8081, forwarding to {TARGET_URL}")
    print(f"Logs will be saved to {LOG_FILE}")
    app.run(host='0.0.0.0', port=8081, debug=False)
    Here’s what I observed after applying the improved proxy:

    srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
    slot print_timing: id  0 | task 421 | 
    prompt eval time =    6673.44 ms /  1402 tokens (    4.76 ms per token,   210.09 tokens per second)
           eval time =    1917.82 ms /    48 tokens (   39.95 ms per token,    25.03 tokens per second)
          total time =    8591.25 ms /  1450 tokens
    slot      release: id  0 | task 421 | stop processing: n_tokens = 19633, truncated = 0
    srv  update_slots: all slots are idle
    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.986 (> 0.100 thold), f_keep = 1.000
    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 471 | processing task, is_child = 0
    slot update_slots: id  0 | task 471 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 19914
    slot update_slots: id  0 | task 471 | n_past = 19631, slot.prompt.tokens.size() = 19633, seq_id = 0, pos_min = 19632, n_swa = 1
    slot update_slots: id  0 | task 471 | restored context checkpoint (pos_min = 19073, pos_max = 19073, size = 75.376 MiB)
    slot update_slots: id  0 | task 471 | n_tokens = 19074, memory_seq_rm [19074, end)
    slot update_slots: id  0 | task 471 | prompt processing progress, n_tokens = 19402, batch.n_tokens = 328, progress = 0.974289
    slot update_slots: id  0 | task 471 | n_tokens = 19402, memory_seq_rm [19402, end)
    slot update_slots: id  0 | task 471 | prompt processing progress, n_tokens = 19914, batch.n_tokens = 512, progress = 1.000000
    slot update_slots: id  0 | task 471 | prompt done, n_tokens = 19914, batch.n_tokens = 512
    slot init_sampler: id  0 | task 471 | init sampler, took 1.63 ms, tokens: text = 19914, total = 19914
    slot update_slots: id  0 | task 471 | created context checkpoint 6 of 256 (pos_min = 19401, pos_max = 19401, size = 75.376 MiB)
    srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
    slot print_timing: id  0 | task 471 | 
    prompt eval time =    4713.30 ms /   840 tokens (    5.61 ms per token,   178.22 tokens per second)
           eval time =    2060.38 ms /    51 tokens (   40.40 ms per token,    24.75 tokens per second)
          total time =    6773.67 ms /   891 tokens
    slot      release: id  0 | task 471 | stop processing: n_tokens = 19964, truncated = 0
    srv  update_slots: all slots are idle
    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.979 (> 0.100 thold), f_keep = 1.000
    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 524 | processing task, is_child = 0
    slot update_slots: id  0 | task 524 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 20393
    slot update_slots: id  0 | task 524 | n_past = 19962, slot.prompt.tokens.size() = 19964, seq_id = 0, pos_min = 19963, n_swa = 1
    slot update_slots: id  0 | task 524 | restored context checkpoint (pos_min = 19401, pos_max = 19401, size = 75.376 MiB)
    slot update_slots: id  0 | task 524 | n_tokens = 19402, memory_seq_rm [19402, end)
    slot update_slots: id  0 | task 524 | prompt processing progress, n_tokens = 19881, batch.n_tokens = 479, progress = 0.974893
    slot update_slots: id  0 | task 524 | n_tokens = 19881, memory_seq_rm [19881, end)
    slot update_slots: id  0 | task 524 | prompt processing progress, n_tokens = 20393, batch.n_tokens = 512, progress = 1.000000
    slot update_slots: id  0 | task 524 | prompt done, n_tokens = 20393, batch.n_tokens = 512
    slot init_sampler: id  0 | task 524 | init sampler, took 1.67 ms, tokens: text = 20393, total = 20393
    slot update_slots: id  0 | task 524 | created context checkpoint 7 of 256 (pos_min = 19880, pos_max = 19880, size = 75.376 MiB)
    srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
    slot print_timing: id  0 | task 524 | 
    prompt eval time =    5576.11 ms /   991 tokens (    5.63 ms per token,   177.72 tokens per second)
           eval time =    1923.23 ms /    48 tokens (   40.07 ms per token,    24.96 tokens per second)
          total time =    7499.34 ms /  1039 tokens
    slot      release: id  0 | task 524 | stop processing: n_tokens = 20440, truncated = 0
    srv  update_slots: all slots are idle
    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.956 (> 0.100 thold), f_keep = 1.000
    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 574 | processing task, is_child = 0
    slot update_slots: id  0 | task 574 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 21377
    slot update_slots: id  0 | task 574 | n_tokens = 20440, memory_seq_rm [20440, end)
    slot update_slots: id  0 | task 574 | prompt processing progress, n_tokens = 20865, batch.n_tokens = 425, progress = 0.976049
    slot update_slots: id  0 | task 574 | n_tokens = 20865, memory_seq_rm [20865, end)
    slot update_slots: id  0 | task 574 | prompt processing progress, n_tokens = 21377, batch.n_tokens = 512, progress = 1.000000
    slot update_slots: id  0 | task 574 | prompt done, n_tokens = 21377, batch.n_tokens = 512
    slot init_sampler: id  0 | task 574 | init sampler, took 1.75 ms, tokens: text = 21377, total = 21377
    slot update_slots: id  0 | task 574 | created context checkpoint 8 of 256 (pos_min = 20864, pos_max = 20864, size = 75.376 MiB)
    srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
    slot print_timing: id  0 | task 574 | 
    prompt eval time =    5182.17 ms /   937 tokens (    5.53 ms per token,   180.81 tokens per second)
           eval time =     948.68 ms /    24 tokens (   39.53 ms per token,    25.30 tokens per second)
          total time =    6130.85 ms /   961 tokens
    slot      release: id  0 | task 574 | stop processing: n_tokens = 21400, truncated = 0
    srv  update_slots: all slots are idle
    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.998 (> 0.100 thold), f_keep = 1.000
    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 600 | processing task, is_child = 0
    slot update_slots: id  0 | task 600 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 21449
    slot update_slots: id  0 | task 600 | n_tokens = 21400, memory_seq_rm [21400, end)
    slot update_slots: id  0 | task 600 | prompt processing progress, n_tokens = 21449, batch.n_tokens = 49, progress = 1.000000
    slot update_slots: id  0 | task 600 | prompt done, n_tokens = 21449, batch.n_tokens = 49
    slot init_sampler: id  0 | task 600 | init sampler, took 1.80 ms, tokens: text = 21449, total = 21449
    slot update_slots: id  0 | task 600 | created context checkpoint 9 of 256 (pos_min = 21399, pos_max = 21399, size = 75.376 MiB)
    srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
    slot print_timing: id  0 | task 600 | 
    prompt eval time =     361.10 ms /    49 tokens (    7.37 ms per token,   135.69 tokens per second)
           eval time =     989.97 ms /    25 tokens (   39.60 ms per token,    25.25 tokens per second)
          total time =    1351.08 ms /    74 tokens
    slot      release: id  0 | task 600 | stop processing: n_tokens = 21473, truncated = 0
    srv  update_slots: all slots are idle
    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.998 (> 0.100 thold), f_keep = 1.000
    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 626 | processing task, is_child = 0
    slot update_slots: id  0 | task 626 | new prompt, n_ctx_slot = 131072, n_keep = 0, task.n_tokens = 21522
    slot update_slots: id  0 | task 626 | n_tokens = 21473, memory_seq_rm [21473, end)
    slot update_slots: id  0 | task 626 | prompt processing progress, n_tokens = 21522, batch.n_tokens = 49, progress = 1.000000
    slot update_slots: id  0 | task 626 | prompt done, n_tokens = 21522, batch.n_tokens = 49
    slot init_sampler: id  0 | task 626 | init sampler, took 1.80 ms, tokens: text = 21522, total = 21522
    slot update_slots: id  0 | task 626 | created context checkpoint 10 of 256 (pos_min = 21472, pos_max = 21472, size = 75.376 MiB)
    

    The log message forcing full prompt re-processing due to lack of cache data (likely due to SWA or hybrid/recurrent memory, see https://github.com//pull/13194#issuecomment-2868343055) disappeared, and the cache hit rate approached 100%. The task I used for testing in Claude Code dropped from 20 minutes to 2 minutes (still slow, but a huge improvement). At this point, the cache miss issue was finally resolved. Due to my limited knowledge of low‑level AI details, I cannot determine whether this problem is related to the --swa-full parameter (PR #13194).

    To be clear, the issue does not stem from Qwen3-Coder-Next or llama.cpp; it is entirely a prompt-side problem.

    The above is my complete troubleshooting process and solution. I believe others using different coding agents can replicate it through the example above, and the problem can ultimately be solved.

    When running the Qwen3-Coder-Next Q8_0 quantized model with llama-server, this issue did not occur in open-webui chats, but it did occur in Claude Code. I tried the solution described here and it was resolved. Thank you.

  12. z80maniac commented on Feb 27, 2026

    @z80maniac
    Contributor

    Here is a clean reproducible example.

    • Commit: 2e7e638

    • System: Linux, RTX 5070Ti

    • Model: Qwen3-Coder-Next, the one linked in the first message.

    • Build: cmake -B build -DGGML_CUDA=ON; cmake --build build --clean-first --config Release "-j$(nproc)" --target llama-server

    • Launch: llama-server --model Qwen3-Coder-Next-UD-TQ1_0.gguf --ctx-size 4096 --jinja --mmap --swa-full

    • Request: curl -Ss http://127.0.0.1:8080/v1/chat/completions --data '{"messages":[{"role":"user","content":[{"type":"text","text":"a a a a a a a a a a"}]}],"max_tokens":0}' | jq

    Output:

    {
      "choices": [
        {
          "finish_reason": "length",
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "It"
          }
        }
      ],
      "created": 1772190549,
      "model": "Qwen3-Coder-Next-UD-TQ1_0.gguf",
      "system_fingerprint": "b8173-2e7e63852",
      "object": "chat.completion",
      "usage": {
        "completion_tokens": 1,
        "prompt_tokens": 18,
        "total_tokens": 19
      },
      "id": "chatcmpl-XKZmfNAW1nrUhjiYoytA3WHrvltLFki0",
      "timings": {
        "cache_n": 0,
        "prompt_n": 18,
        "prompt_ms": 88.613,
        "prompt_per_token_ms": 4.922944444444444,
        "prompt_per_second": 203.1304661844199,
        "predicted_n": 1,
        "predicted_ms": 0.001,
        "predicted_per_token_ms": 0.001,
        "predicted_per_second": 1000000.0
      }
    }

    The cache_n = 0 implies a cache miss.

    Now run the same request the second time. You will get cache_n = 0 again. It means the prompt cache was not used.

    The log after the second request:

    srv  params_from_: Chat format: peg-constructed
    slot get_availabl: id  3 | task -1 | selected slot by LCP similarity, sim_best = 1.000 (> 0.100 thold), f_keep = 1.000
    slot launch_slot_: id  3 | 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  3 | task 2 | processing task, is_child = 0
    slot update_slots: id  3 | task 2 | new prompt, n_ctx_slot = 4096, n_keep = 0, task.n_tokens = 18
    slot update_slots: id  3 | task 2 | need to evaluate at least 1 token for each active slot (n_past = 18, task.n_tokens() = 18)
    slot update_slots: id  3 | task 2 | n_past was set to 17
    slot update_slots: id  3 | task 2 | n_tokens = 17, memory_seq_rm [17, end)
    slot update_slots: id  3 | task 2 | failed to truncate tokens with position >= 17 - clearing the memory
    slot prompt_clear: id  3 | task 2 | clearing prompt with 17 tokens
    slot init_sampler: id  3 | task 2 | init sampler, took 0.00 ms, tokens: text = 18, total = 18
    slot update_slots: id  3 | task 2 | prompt processing done, n_tokens = 18, batch.n_tokens = 18
    slot print_timing: id  3 | task 2 |
    prompt eval time =     101.69 ms /    18 tokens (    5.65 ms per token,   177.00 tokens per second)
           eval time =       0.00 ms /     1 tokens (    0.00 ms per token, 1000000.00 tokens per second)
          total time =     101.70 ms /    19 tokens
    slot      release: id  3 | task 2 | stop processing: n_tokens = 18, truncated = 0
    srv  update_slots: all slots are idle
    srv  log_server_r: done request: POST /v1/chat/completions 127.0.0.1 200
    

    Notice the "failed to truncate tokens" line. It's different from "forcing full prompt re-processing due to lack of cache data" reported in the original message. So maybe it's a slightly different bug. I have seen the "forcing full prompt re-processing" message too, but I can't cleanly reproduce it.

    This exact bug also happens on Qwen3.5-397B-A17B. But doesn't happen, for example, on GLM-4.6V. When you perform the same request on GLM the second time it properly shows cache_n = 15.

  13. aarcange commented on Feb 28, 2026

    @aarcange
    Contributor

    I run into the "forcing full prompt re-processing ..." too, but my issue is going after I modified the ckpoint freq like this #19970 plus --ctx-checkpoints 64. This is only mean to solve the truncation of kvcache (like after editing a file in context).

  14. pwilkin commented on Feb 28, 2026

    @pwilkin
    Member

    I'll try to cook up a solution tomorrow.

  15. 6 remaining items

  16. CoreRasurae commented on Mar 4, 2026

    @CoreRasurae

    @pwilkin i have tested your patch and i am getting the same problem, it seems... i am running Qwen 3.5 and despiste the high LCP similarity it discarded all the context, even with --checkpoint-every-nb 3, as documented in this log excerpt:

    48327] slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.999 (> 0.100 thold), f_keep = 1.000
    [48327] 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 
    [48327] slot launch_slot_: id  0 | task 91904 | processing task, is_child = 0
    [48327] slot update_slots: id  0 | task 91904 | new prompt, n_ctx_slot = 262144, n_keep = 0, task.n_tokens = 208238
    [48327] slot update_slots: id  0 | task 91904 | n_tokens = 208091, memory_seq_rm [208091, end)
    [48327] slot init_sampler: id  0 | task 91904 | init sampler, took 19.54 ms, tokens: text = 208238, total = 208238
    [48327] slot update_slots: id  0 | task 91904 | prompt processing done, n_tokens = 208238, batch.n_tokens = 147
    [48327] slot update_slots: id  0 | task 91904 | erasing old context checkpoint (pos_min = 190278, pos_max = 190278, n_tokens = 190279, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 91904 | created context checkpoint 8 of 8 (pos_min = 208090, pos_max = 208090, n_tokens = 208091, size = 186.329 MiB)
    [48327] srv  log_server_r: done request: POST /v1/chat/completions 127.0.0.1 200
    srv  log_server_r: done request: POST /v1/chat/completions 172.18.0.2 200
    [48327] slot print_timing: id  0 | task 91904 | 
    [48327] prompt eval time =   10053.10 ms /   147 tokens (   68.39 ms per token,    14.62 tokens per second)
    [48327]        eval time =   51534.23 ms /   528 tokens (   97.60 ms per token,    10.25 tokens per second)
    [48327]       total time =   61587.34 ms /   675 tokens
    [48327] slot      release: id  0 | task 91904 | stop processing: n_tokens = 208765, truncated = 0
    [48327] srv  update_slots: all slots are idle
    srv  proxy_reques: proxying request to model unsloth/Qwen3.5-397B-A17B-GGUF:MXFP4_MOE on port 48327
    [48327] srv  params_from_: Chat format: peg-constructed
    [48327] slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.806 (> 0.100 thold), f_keep = 0.803
    [48327] 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 
    [48327] slot launch_slot_: id  0 | task 92433 | processing task, is_child = 0
    [48327] slot update_slots: id  0 | task 92433 | new prompt, n_ctx_slot = 262144, n_keep = 0, task.n_tokens = 208005
    [48327] slot update_slots: id  0 | task 92433 | n_past = 167705, slot.prompt.tokens.size() = 208765, seq_id = 0, pos_min = 208764, n_swa = 1
    [48327] slot update_slots: id  0 | task 92433 | 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)
    [48327] slot update_slots: id  0 | task 92433 | erased invalidated context checkpoint (pos_min = 194374, pos_max = 194374, n_tokens = 194375, n_swa = 1, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 92433 | erased invalidated context checkpoint (pos_min = 195469, pos_max = 195469, n_tokens = 195470, n_swa = 1, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 92433 | erased invalidated context checkpoint (pos_min = 202289, pos_max = 202289, n_tokens = 202290, n_swa = 1, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 92433 | erased invalidated context checkpoint (pos_min = 206385, pos_max = 206385, n_tokens = 206386, n_swa = 1, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 92433 | erased invalidated context checkpoint (pos_min = 207053, pos_max = 207053, n_tokens = 207054, n_swa = 1, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 92433 | erased invalidated context checkpoint (pos_min = 207669, pos_max = 207669, n_tokens = 207670, n_swa = 1, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 92433 | erased invalidated context checkpoint (pos_min = 207832, pos_max = 207832, n_tokens = 207833, n_swa = 1, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 92433 | erased invalidated context checkpoint (pos_min = 208090, pos_max = 208090, n_tokens = 208091, n_swa = 1, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 92433 | n_tokens = 0, memory_seq_rm [0, end)
    [48327] slot update_slots: id  0 | task 92433 | prompt processing progress, n_tokens = 2048, batch.n_tokens = 2048, progress = 0.009846
    [48327] slot update_slots: id  0 | task 92433 | n_tokens = 2048, memory_seq_rm [2048, end)
    [48327] slot update_slots: id  0 | task 92433 | prompt processing progress, n_tokens = 4096, batch.n_tokens = 2048, progress = 0.019692
    [48327] slot update_slots: id  0 | task 92433 | n_tokens = 4096, memory_seq_rm [4096, end)
    [48327] slot update_slots: id  0 | task 92433 | prompt processing progress, n_tokens = 6144, batch.n_tokens = 2048, progress = 0.029538
    [48327] slot update_slots: id  0 | task 92433 | n_tokens = 6144, memory_seq_rm [6144, end)
    [48327] slot update_slots: id  0 | task 92433 | 3 batches since last checkpoint at 0, creating new checkpoint during processing at position 8192
    [48327] slot update_slots: id  0 | task 92433 | prompt processing progress, n_tokens = 8192, batch.n_tokens = 2048, progress = 0.039384
    [48327] slot update_slots: id  0 | task 92433 | created context checkpoint 1 of 8 (pos_min = 6143, pos_max = 6143, n_tokens = 6144, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 92433 | n_tokens = 8192, memory_seq_rm [8192, end)
    [48327] slot update_slots: id  0 | task 92433 | prompt processing progress, n_tokens = 10240, batch.n_tokens = 2048, progress = 0.049230
    [48327] slot update_slots: id  0 | task 92433 | n_tokens = 10240, memory_seq_rm [10240, end)
    [48327] slot update_slots: id  0 | task 92433 | prompt processing progress, n_tokens = 12288, batch.n_tokens = 2048, progress = 0.059076
    [48327] slot update_slots: id  0 | task 92433 | n_tokens = 12288, memory_seq_rm [12288, end)
    [48327] slot update_slots: id  0 | task 92433 | 3 batches since last checkpoint at 6143, creating new checkpoint during processing at position 14336
    [48327] slot update_slots: id  0 | task 92433 | prompt processing progress, n_tokens = 14336, batch.n_tokens = 2048, progress = 0.068921
    [48327] slot update_slots: id  0 | task 92433 | created context checkpoint 2 of 8 (pos_min = 12287, pos_max = 12287, n_tokens = 12288, size = 186.329 MiB)
    [48327] slot update_slots: id  0 | task 92433 | n_tokens = 14336, memory_seq_rm [14336, end)
    [48327] slot update_slots: id  0 | task 92433 | prompt processing progress, n_tokens = 16384, batch.n_tokens = 2048, progress = 0.078767
    [48327] slot update_slots: id  0 | task 92433 | n_tokens = 16384, memory_seq_rm [16384, end)
    [48327] slot update_slots: id  0 | task 92433 | prompt processing progress, n_tokens = 18432, batch.n_tokens = 2048, progress = 0.088613
    [48327] slot update_slots: id  0 | task 92433 | n_tokens = 18432, memory_seq_rm [18432, end)
    [48327] slot update_slots: id  0 | task 92433 | 3 batches since last checkpoint at 12287, creating new checkpoint during processing at position 20480
    [48327] slot update_slots: id  0 | task 92433 | prompt processing progress, n_tokens = 20480, batch.n_tokens = 2048, progress = 0.098459
    [48327] slot update_slots: id  0 | task 92433 | created context checkpoint 3 of 8 (pos_min = 18431, pos_max = 18431, n_tokens = 18432, size = 186.329 MiB)
    
  17. odellus commented on Mar 7, 2026

    @odellus

    I use my own agent that keeps the reasoning content so as to not invalidate the kv cache (my method of compaction is cheap/fast) and I see the invalidated kv cache error all the time. Somewhat at random. It's not just strange cache invalidating behavior from opencode or CC. Agent custom built to preserve kv cache also triggers full reprocessing in a non-deterministic manner.

  18. yshui commented on Mar 7, 2026

    @yshui

    it's a bit annoying that even with enable_thinking = false, empty <think> </think> tags are still added and deleted, forcing reprocessing. can we change the chat template to not insert <think> at all, or is that going to wreck model performance?

  19. aarcange commented on Mar 7, 2026

    @aarcange
    Contributor

    it's a bit annoying that even with enable_thinking = false, empty <think> </think> tags are still added and deleted, forcing reprocessing. can we change the chat template to not insert <think> at all, or is that going to wreck model performance?

    You can leverage gbnf to handle this, likely by implementing a negative pattern similar to this example:
    https://gitlab.com/aarcange/ripgrep-edit/-/blob/main/src/gbnf.rs?ref_type=heads#L31

    For curiosity, a few days ago I ran the synthmerge_bench to measure how accuracy changes using --no-jinja when switching from the standard grammar (used when gbnf: true) to the same but prefixed with <think>\n\n</think> (in both cases thinking is disabled reliably through gbnf only).

    Findings:

    • The accuracy drops slightly with the <think>\n\n</think> prefix added the standard grammar
    • While the accuracy improvement seen when removing the think block might be a jitter, the relevant takeaway is that using gbnf to disable thinking should not negatively impact accuracy.

    I haven't noticed specific issues with messages in my setup, but my workflow requires KV-cache only on the system prompt (where context is), and I have gptel-include-reasoning set to the default "t". Consequently, the LLM plugin is including the think block in the response, which might be hiding any think related invalidation. That said, including the block is likely not ideal for accuracy...

  20. yshui commented on Mar 7, 2026

    @yshui

    I have a vague feeling that tool calling isn't going to work if I disable the chat template. If that's correct then the chat template will add <think>\n\n</think> back, even if I can stop the model from generating it with grammar.

  21. johnchouang commented on Mar 8, 2026

    @johnchouang

    I'm noticing the forced reprocessing only happen on concurrent calls. When in cluade code it usually sends 2 concurrent calls, so the forced processing always happens.

    When i switched to opencode and set --parallel to 1, i don't get the error.

    Seems if this can be fixed for concurrent calls qwen3 would be much more usable for local users.

  22. chrisoutwright commented on Mar 8, 2026

    @chrisoutwright

    I have found maybe some cause: microsoft/vscode#298554 (comment)

  23. ggerganov commented on Mar 9, 2026

    @ggerganov
    Member

    @johnchouang This will be fixed with #20287

  24. johnchouang commented on Mar 11, 2026

    @johnchouang

    Great thanks

  25. chrisoutwright commented on Mar 15, 2026

    @chrisoutwright

    I still had issue with invalidation ,, but I think it is because of the IDE (VSC example copilot) hiding code lines (to save context I guess?) in the session..

    Image

    very hard to pick up .. I had to write a whole UI to get this highlighted..

  26. subhamgiri460 commented on Mar 19, 2026

    @subhamgiri460
  27. RemizovDenis commented on Mar 31, 2026

    @RemizovDenis

    Prompt re-computation is a huge TTFT killer. We solved this in TurboQuant v0.3.0 using Speculative KV Prefill. It uses 1-bit "sketches" to quickly reconstruct a draft of the KV cache for evicted prefixes. It boosts prefill speed by 2-3x and only verifies against the anchor layers, which is way faster than a full re-computation from scratch.

  28. github-actions commented on May 15, 2026

    @github-actions
    Contributor

    This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions