Anthropic clients never see a failed turn: anthropic_stop_reason maps finish=="error" to end_turn
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 ds4_server.c at anthropic_stop_reason, then trace anthropic_final_response and anthropic_sse_finish_live, including sse_error_event and send_prefill_failure_response. Review the existing OpenAI-compatible and Responses handling, then run ds4_test --server. Done requires an agreed failure-surfacing behavior and coverage for both Anthropic response paths.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
anthropic_stop_reason maps every finish state except tool_calls and length to end_turn — including "error". A turn that failed server-side is therefore indistinguishable from a normal completion on the Anthropic API, and the error text is not surfaced anywhere in the response body or stream.
Current upstream code (ds4_server.c @ 0aaea5a):
static const char *anthropic_stop_reason(const char *finish) { // :9038
if (finish && !strcmp(finish, "tool_calls")) return "tool_use";
if (finish && !strcmp(finish, "length")) return "max_tokens";
return "end_turn";
}
Both Anthropic surfaces route through it: the non-streaming final message (anthropic_final_response, :9113, stop_reason at :9123) and the streaming terminator (anthropic_sse_finish_live → message_delta's stop_reason at :9828).
The other two APIs are honest about the same event:
- OpenAI-compatible:
finish_reason: "error"on the 200 body (the value is passed through verbatim). - Responses:
finish == "error"→status: "failed"witherror.code = "server_error"(:8636, :8676).
And the SSE error event the server already has (sse_error_event, :7005, which emits a proper type: "error" / api_error) is called from exactly one place — send_prefill_failure_response (:12759). A failure raised after decoding (engine fault during generation, failed session append, unterminated tool call, stream-write failure) never reaches it on the Anthropic path.
Observed in production
While investigating the case that became #1163: the model opened a tool envelope and never closed it, the generator set finish = "error", and the Anthropic client received the raw truncated markup as ordinary assistant text with stop_reason: "end_turn". Nothing in the response indicated anything had gone wrong; the only trace is in the server log. (#1163 removes that specific trigger by deferring to the parse-failure recovery, but the collapse itself stays for every other error class.)
Why this is not a one-line mapping fix
Anthropic's stop_reason vocabulary (end_turn | max_tokens | stop_sequence | tool_use | pause_turn) has no error member, so the choices are shaped by what clients tolerate:
- Out-of-band surfacing (probably the smallest honest change): keep
stop_reason: "end_turn", but deliver the failure alongside it — e.g. anerrorfield on the message object, or amessage_delta-adjacenterrorevent reusing the existingsse_error_eventmachinery. Clients that ignore unknown fields keep working; clients that look can tell. - HTTP-level errors for genuine server faults (5xx, or a terminal error event mid-stream), while model-output shapes (unclosed envelope, parse failures) stay completions — which is the same distinction #1163 draws one layer down.
- Document the collapse so an operator debugging a silent Anthropic failure knows to check the server log rather than the response.
Option 2 changes failure semantics clients can actually branch on, but risks breaking agent loops that today silently receive end_turn and treat the truncated markup as a real answer (a working failure mode, in a sense). I don't have a strong claim on which the project prefers — hence the issue rather than a PR; happy to implement whichever shape you pick, with the Anthropic unit cases pinned against the current anthropic_final_response/anthropic_sse_finish_live pair.
Reproduction notes (per CONTRIBUTING.md)
Machine/backend/model: Apple M5 Max 128 GB, Metal, Qwen3.8 Flash Next Q4_K + vision, production server (--thinking enabled, Anthropic /v1/messages via REQ_ANTHROPIC). The error-finish trigger (unclosed envelope) is model-output-shaped and rare by construction (1 of 149 tool turns in a multi-day soak), so a deterministic local repro is easier through the parse layer than the model: generate/hold a result with finish == "error" and observe anthropic_final_response emits stop_reason: "end_turn" with the content verbatim.
ds4_test --server is green on current main at these line references; this issue reports behavior, it is not a crash.
- 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