[GH-ISSUE #2659] [Issue]: Mid-stream Anthropic error events are swallowed → silent truncated output #1309

Closed
opened 2026-10-21 05:31:21 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2659

Originally assigned to: @SpicyMarinara on GitHub.

Summary

During an Anthropic stream, mid-stream error events (e.g. overloaded_error) emitted over an already-open HTTP 200 connection are not handled, so the stream ends "successfully" with truncated/partial output and no error surfaced to the user.

Expected behavior

A mid-stream error event should abort the generation and propagate a clear error the user can see and retry, rather than silently returning partial text.

Actual behavior

The SSE parsing loop handles message_start, message_delta, content_block_start, content_block_delta, and message_stop, but has no branch for event.type === "error". An error event is valid JSON (so the bare catch {} never fires) and matches no branch, so it falls through; when the upstream closes the connection, the generator returns normally with whatever partial text was already yielded.

How it breaks the pipeline

Code trace (staging @ b826f8f4) — packages/server/src/services/llm/providers/anthropic.provider.ts:

  • SSE loop handlers: message_start :513, message_delta :518, content_block_start :522, content_block_delta :525, message_stop :532. There is no error-type handler.
  • The initial if (!response.ok) guard only inspects the initial HTTP status and cannot catch an error event that arrives after a 200 + open stream.
  • Anthropic emits {"type":"error","error":{"type":"overloaded_error",...}} mid-stream under load/rate-limit/server error; it parses cleanly, matches nothing, and is ignored. The loop later ends at done and returns the partial text as a success.

Steps to reproduce

  1. Use an Anthropic connection and trigger an overloaded_error during streaming (e.g. under load / rate limiting).
  2. Observe: the client receives the partial text generated so far and the generation completes with no error; the user sees a truncated or empty response with no indication anything failed.

Suggested fix

In the SSE loop, add a handler: if (event.type === "error") throw new Error(event.error?.message ?? event.error?.type ?? "Anthropic stream error"); so the failure propagates instead of being treated as a normal stream end. Apply to every path that parses Anthropic SSE.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Identified via systematic source review on staging (refs @ b826f8f4). Silent partial output is particularly damaging in roleplay/story contexts because the truncated text looks like a deliberate (if abrupt) model response. Filed alongside related pipeline issues.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jun 20, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2659 Originally assigned to: @SpicyMarinara on GitHub. ## Summary During an Anthropic stream, mid-stream `error` events (e.g. `overloaded_error`) emitted over an already-open HTTP 200 connection are not handled, so the stream ends "successfully" with truncated/partial output and no error surfaced to the user. ## Expected behavior A mid-stream error event should abort the generation and propagate a clear error the user can see and retry, rather than silently returning partial text. ## Actual behavior The SSE parsing loop handles `message_start`, `message_delta`, `content_block_start`, `content_block_delta`, and `message_stop`, but has no branch for `event.type === "error"`. An error event is valid JSON (so the bare `catch {}` never fires) and matches no branch, so it falls through; when the upstream closes the connection, the generator returns normally with whatever partial text was already yielded. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`) — `packages/server/src/services/llm/providers/anthropic.provider.ts`: - SSE loop handlers: `message_start` `:513`, `message_delta` `:518`, `content_block_start` `:522`, `content_block_delta` `:525`, `message_stop` `:532`. There is **no** `error`-type handler. - The initial `if (!response.ok)` guard only inspects the initial HTTP status and cannot catch an error event that arrives after a 200 + open stream. - Anthropic emits `{"type":"error","error":{"type":"overloaded_error",...}}` mid-stream under load/rate-limit/server error; it parses cleanly, matches nothing, and is ignored. The loop later ends at `done` and returns the partial text as a success. ## Steps to reproduce 1. Use an Anthropic connection and trigger an `overloaded_error` during streaming (e.g. under load / rate limiting). 2. Observe: the client receives the partial text generated so far and the generation completes with **no error**; the user sees a truncated or empty response with no indication anything failed. ## Suggested fix In the SSE loop, add a handler: `if (event.type === "error") throw new Error(event.error?.message ?? event.error?.type ?? "Anthropic stream error");` so the failure propagates instead of being treated as a normal stream end. Apply to every path that parses Anthropic SSE. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Identified via systematic source review on staging (refs @ `b826f8f4`). Silent partial output is particularly damaging in roleplay/story contexts because the truncated text looks like a deliberate (if abrupt) model response. Filed alongside related pipeline issues. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 20, 2026):

Implemented on branch codex/spicymarinara-assigned-issues: Anthropic SSE error events now throw instead of being swallowed as successful partial streams. Final validation will run after the full assigned sweep per maintainer request.

<!-- gh-comment-id:4760051973 --> @SpicyMarinara commented on GitHub (Jun 20, 2026): Implemented on branch codex/spicymarinara-assigned-issues: Anthropic SSE error events now throw instead of being swallowed as successful partial streams. Final validation will run after the full assigned sweep per maintainer request.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1309
No description provided.