GLM tool turns clear the live checkpoint, so every follow-up turn rebuilds its prefix
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c
- Ambito
- ai-infra-agents, backend, performance
Direzione di ricerca
Start with should_remember_thinking_checkpoint(), the tool-call branch using remember_qwen_tool_visible_checkpoint(), and the existing build_thinking_visible_text() GLM path. Run ./ds4_test --server, including test_glm_tool_turn_checkpoint_eligible(), and verify that a GLM tool follow-up reuses the live checkpoint instead of re-prefilling the older prefix.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi Salvatore,
while running a long agent session against glm5_next (GLM-5.3-Flash, Q2 resident, ctx 393216, MTP on)
I noticed that every follow-up turn after a tool call rebuilds its prompt prefix from an older disk
block instead of continuing the live KV. On this machine that is ~30k tokens of prefill (~100 s) per
follow-up turn.
What the log shows (one server, one client session)
12:32:48 chat ctx=50681..50747:66 gen=92 TOOLS DSML_START DSML_END finish=tool_calls 7.054s
12:57:50 GLM live prefix rewind from 50839 to 50746 requires rebuild
12:57:50 kv cache skipped tokens=50746 reason=evict because KV payload staging failed: session has no valid checkpoint to stage
12:57:51 kv cache hit text tokens=20536 ... load=563.0 ms
12:57:51 chat ctx=20536..50747:30211 TOOLS prompt start <- 30211 tokens re-prefilled
Three observations:
- The follow-up request is 92 tokens shorter than the live frontier (50839 -> 50747): the client
(Hermes desktop) does not send the generated tool-call text back as reasoning. That is normal for
an OpenAI-style chat client — it is exactly the case the Qwen path was built for
(build_qwen_tool_turn_visible_text, "Match clients that omit reasoning"). - The rewind cannot rescue it:
ds4_session_glm_mtp_rewind()only covers the two-token MTP cycle, so
ds4_session_rewind()finishes withstate_ok == false, clearscheckpoint_validand the caller
rebuilds. That looks correct for the compressed DSA KV — truncation is not a valid rollback. - Therefore the only thing that can keep the live prefix usable is a visible checkpoint — and for
GLM it is never set.
Root cause
should_remember_thinking_checkpoint():
const bool qwen_chat = r->model_syntax == SERVER_MODEL_SYNTAX_QWEN &&
r->api != API_RESPONSES && r->api != API_ANTHROPIC;
if ((r->has_tools || r->prompt_preserves_reasoning) && !qwen_chat) return false;
Qwen is exempted here, GLM is not. At the call site in the tool-call branch:
} else if (parsed_calls.len) {
if (!remember_qwen_tool_turn_visible_checkpoint(...)) /* hard Qwen-only check -> false */
{
thinking_live_clear(s, slot); /* live checkpoint is dropped */
}
}
For a GLM chat request with tools and known raw DSML, should_canonicalize_tool_checkpoint()
also returns false (raw_tool_text is known -> exact DSML replay is preferred), so no checkpoint is
written on any path. The live checkpoint is cleared instead, the disk staging then fails with
"session has no valid checkpoint to stage", no block at ~50k tokens is stored, and the next request
falls back to the newest older block that still matches.
Proposed fix
Mirror the Qwen behaviour for GLM: remember the visible key (prompt + closed think block + the
tool-call text) using the existing build_thinking_visible_text(), which already has a GLM branch.
The next request renders that same visible surface, thinking_live_visible_prefix_prompt() matches it
and the live KV is reused.
My branch adds glm_tool_turn_checkpoint_eligible() — eligibility mirrors what
build_thinking_visible_text() requires: chat completions, SERVER_MODEL_SYNTAX_GLM, not
Responses/Anthropic, finish == "tool_calls" (decode finish, not the promoted parser status), not
inside thinking, non-empty tool text, and a prompt that still ends with the open <think> marker —
and calls remember_thinking_checkpoint() in the tool-call branch when the Qwen helper declines.
Unit test test_glm_tool_turn_checkpoint_eligible() covers the positive case plus the rejections
(finish != tool_calls, inside thinking, empty content, no finish, Qwen syntax, Responses API, prompt
without the open marker, NULL request). ./ds4_test --server passes on the branch.
Status: unit-tested, live before/after not measured yet — the production server was busy with a live
agent run while I prepared this, so I did not restart it. I can report the measured numbers
(visible checkpoint remembered + follow-up prefill tokens) once it has run, if that helps before
review.
Related, smaller observation
On a client cancel during prefill, kv_cache_discard_failed_disk_entry() unlinks the disk entry and
calls ds4_session_invalidate(). The entry itself was intact, so the next attempt starts from an
older block than necessary. I left that alone — the defensive delete looks deliberate.
- Lingua principale
- C
- Stelle
- 24.4k
- Fork
- 2.4k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di antirez/ds4
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
antirez/ds4#1189 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
antirez/ds4#1173 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
antirez/ds4#1032 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
awslabs/aws-c-common#1319 ·
-
editor/integration
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
DeusData/codebase-memory-mcp#3130 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 13 giorni
-
DBMS_UTILITY.FORMAT_ERROR_STACK exceeds the 2000-byte limitForse già presa @coder999o l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
zephyrproject-rtos/zephyr#127560 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni