Anthropic: preserve visible output when thinking consumes a tiny remaining budget
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start in the server's Anthropic /v1/messages handling and trace the existing decoder, batched decode path, model syntax prompts, and stream state. Run ./ds4_test --server and use the listed threshold, recovery, suffix-failure, and OpenAI-compatibility cases to define coverage. Done means the Anthropic near-limit request returns visible text while the stated safety constraints and normal reasoning behavior remain intact.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
For Anthropic /v1/messages requests on reasoning models, ds4 clamps max_tokens to the remaining context room. When only a small budget remains (for example 180 tokens), the model can spend the whole budget inside <think> and return no visible text. Claude CLI automatic compaction then reports an empty summary instead of recovering.
The current Anthropic overflow error also does not use the wording Anthropic clients recognise for a truncated-history retry.
Proposed behavior
Add --anthropic-thinking-min-budget N with default 1024; 0 disables it.
On the first decode pass only, when all of these hold:
- endpoint is Anthropic
- reasoning mode is active
- real decode budget is
<= N - no recovery completion or DSML recovery is active
- the stream is untouched
append the model syntax's think-close suffix tokens to the live KV state, update thinking and Anthropic stream state, then decode visible text. Derive the suffix from the model syntax's thinking and non-thinking generation prompts; do not hand-write model-specific token ids.
Also return Anthropic overflow text exactly as:
prompt is too long: N tokens > M maximum
OpenAI-compatible endpoints must remain byte-identical.
Safety constraints
- Do not re-render, re-tokenise, re-parse, or cold-prefill the prompt.
- Use the decoder's real position, not rendered prompt length.
- Append pre-resolved suffix ids through the existing batched decode path under the model lock; do not call the session evaluator directly.
- Run only once and never after tool/recovery re-entry or after any stream output.
- Re-derive thinking and stream state after the suffix.
- If suffix evaluation fails partway, invalidate the session and clear live slot state before returning the existing error.
- A syntax without a pure close suffix is a no-op.
- Do not expose hidden reasoning as visible text.
Acceptance
- Unit tests cover threshold values
180,1024,1025, disabled0, reasoning off, recovery paths, already-streamed output, partial suffix failure, and unchanged OpenAI output. - Qwen's derived suffix detokenises to exactly
\n</think>\n\n. - A near-limit Anthropic request with
max_tokens=180returns a non-empty text block and no thinking block. - Repeating a long prompt preserves KV reuse; continuation after a tail-closed answer does not cold-prefill.
- A normal high-budget reasoning request still emits thinking normally.
./ds4_test --serverpasses.
This change is intentionally limited to the server.
- 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