mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3036] [Issue]: Anthropic streaming throws "completed without text" on a valid thinking-only / empty completion, discarding the reply #1607
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1607
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3036
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
With extended thinking enabled on an Anthropic connection, a response that spends its whole budget thinking and gets cut off (
stop_reason: max_tokens) before emitting any text — or one that hits a stop sequence immediately — is turned into a hard error instead of a (truncated) reply. The streaming generator throwsAnthropic stream completed without text (finish reason: ...)whenever no text delta was yielded, even though a thinking-only or empty-but-terminated completion is a legitimate outcome. The captured thinking and token usage are discarded, and the user sees an error rather than a length-truncated turn. The non-streaming branch handles the same empty-text case gracefully (yields"", returns usage), so the two branches disagree.How to reproduce (try it yourself)
enableThinking), streaming on.max_tokensso the budget is consumed by thinking before any text is produced (stop_reason: max_tokensduring the thinking block).You'll see: the stream emits
message_start, thinking deltas,message_delta(stop_reason=max_tokens),message_stop— but no text delta, soemittedTextstays false and the generator throws. The user gets a generation error.Expected: the (truncated) thinking + token usage +
finishReasonare returned, like the non-streaming branch, instead of a hard error.Where it is
packages/server/src/services/llm/providers/anthropic.provider.ts: themessage_stopthrow at lines 614-617 and the parallel post-loop throw at lines 634-636 (both fire on!emittedText && !options.signal?.aborted).emittedTextis set true only on a text delta (lines 609-611); thinking deltas (606-608) never set it. Graceful non-streaming branch: lines 514-537.finishReasoncapture: lines 599-601. Thinking enablement: lines 463-487.What's happening
The provider treats "no text was streamed" as a stream failure, but an empty/thinking-only completion is valid (especially when
stop_reasonindicates length or a stop sequence). The check ignoresfinishReasonand is inconsistent with the non-streaming branch.Suggested fix
Make the throw finish-reason-AWARE by tracking whether a terminal
stop_reasonwas actually observed, rather than matchingfinishReasonagainst a value list:finishReason(line 557):let sawStopReason = false;stop_reasonis captured (lines 599-601): inside themessage_deltabranch, after assigningfinishReason, addsawStopReason = true;.message_stopthrow (615-617) on!emittedText && !sawStopReason && !options.signal?.aborted— a thinking-only/max_tokens/stop_sequence completion then returns usage (withfinishReason) gracefully like the non-streaming branch.!sawStopReasonguard to the post-loop throw (634-636) — the genuinely-truncated case (nomessage_stopseen) still throws when nostop_reasonever arrived.Regression avoided: the literal suggestion — "don't throw when
finishReasonislength/stop/tool_calls" — would break truncated-stream detection, becausefinishReasonis initialized to"stop"(line 557). A connection that drops mid-response (nomessage_delta, nomessage_stop) reaches the post-loop check withfinishReasonstill"stop", so a value-list containing"stop"would suppress that throw and silently turn a failed stream into a clean empty completion. Tracking observation of astop_reasonavoids this. Tool calls never flow through this streaming generator, and the abort and happy-text paths are untouched.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Claiming this for the current staging sweep in draft PR #3053 (branch
codex/issue-sweep-3033-3052).@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in PR #3053 on branch
codex/issue-sweep-3033-3052(commitbfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.