[GH-ISSUE #2666] [Issue]: Gemini streaming swallows mid-stream error / promptFeedback.blockReason → silent truncated output #1317

Closed
opened 2026-10-21 05:31:28 +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/2666

Originally assigned to: @SpicyMarinara on GitHub.

Summary

During a Gemini stream, mid-stream error objects and promptFeedback.blockReason notices are valid JSON, so they bypass the malformed-line catch, are not recognized by the parser, and are silently dropped — the stream ends with truncated/empty output and no error surfaced.

Expected behavior

A mid-stream Gemini error or safety block should abort generation and surface a clear error the user can see and retry, not return partial/empty text as success.

Actual behavior

The streaming loop only reads parsed.usageMetadata and parsed.candidates?.[0]?.content?.parts. A {"error":{...}} or {"promptFeedback":{"blockReason":"SAFETY"}} line parses cleanly (so the // Skip malformed lines catch never fires), matches neither branch, yields empty parts, and is ignored; the generator then ends normally.

How it breaks the pipeline

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

  • Streaming loop ~:664–691; JSON.parse ~:665; only usageMetadata (:666) and candidates[0].content.parts (:674) are read; catch { // Skip malformed lines } at ~:690.
  • There is no reference to error or promptFeedback/blockReason anywhere in the file (confirmed by search), so neither is handled.

This is the Google analog of the already-filed Anthropic mid-stream error swallow (#2659), which is scoped to anthropic.provider.ts only — so it is a distinct, unfiled bug.

Steps to reproduce

  1. Stream against a Gemini endpoint that emits data: {"error":{"code":429,...}} mid-stream (rate limit), or a prompt that trips a mid-stream SAFETY block after the initial 200 OK.
  2. Observe: output stops early; chat() returns normally with partial/empty text; no error is logged or surfaced.

Suggested fix

Inside the streaming try block, after JSON.parse, inspect the object before extracting parts: if parsed.error is present, throw a sanitized Gemini API streaming error: ...; if parsed.promptFeedback?.blockReason is set, throw an error naming the block reason.

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). Closely related to the "blocked/empty Gemini response reported as normal stop" issue filed concurrently; both stem from the Gemini handlers not inspecting promptFeedback/error/finishReason.

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/2666 Originally assigned to: @SpicyMarinara on GitHub. ## Summary During a Gemini stream, mid-stream `error` objects and `promptFeedback.blockReason` notices are valid JSON, so they bypass the malformed-line `catch`, are not recognized by the parser, and are silently dropped — the stream ends with truncated/empty output and no error surfaced. ## Expected behavior A mid-stream Gemini error or safety block should abort generation and surface a clear error the user can see and retry, not return partial/empty text as success. ## Actual behavior The streaming loop only reads `parsed.usageMetadata` and `parsed.candidates?.[0]?.content?.parts`. A `{"error":{...}}` or `{"promptFeedback":{"blockReason":"SAFETY"}}` line parses cleanly (so the `// Skip malformed lines` catch never fires), matches neither branch, yields empty `parts`, and is ignored; the generator then ends normally. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`) — `packages/server/src/services/llm/providers/google.provider.ts`: - Streaming loop ~`:664–691`; `JSON.parse` ~`:665`; only `usageMetadata` (`:666`) and `candidates[0].content.parts` (`:674`) are read; `catch { // Skip malformed lines }` at ~`:690`. - There is **no** reference to `error` or `promptFeedback`/`blockReason` anywhere in the file (confirmed by search), so neither is handled. This is the Google analog of the already-filed Anthropic mid-stream error swallow (#2659), which is scoped to `anthropic.provider.ts` only — so it is a distinct, unfiled bug. ## Steps to reproduce 1. Stream against a Gemini endpoint that emits `data: {"error":{"code":429,...}}` mid-stream (rate limit), or a prompt that trips a mid-stream `SAFETY` block after the initial 200 OK. 2. Observe: output stops early; `chat()` returns normally with partial/empty text; no error is logged or surfaced. ## Suggested fix Inside the streaming `try` block, after `JSON.parse`, inspect the object **before** extracting `parts`: if `parsed.error` is present, throw a sanitized `Gemini API streaming error: ...`; if `parsed.promptFeedback?.blockReason` is set, throw an error naming the block reason. ## 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`). Closely related to the "blocked/empty Gemini response reported as normal stop" issue filed concurrently; both stem from the Gemini handlers not inspecting `promptFeedback`/`error`/`finishReason`. ## 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: Gemini streaming now aborts on streamed error objects and promptFeedback.blockReason. Final validation will run after the full assigned sweep per maintainer request.

<!-- gh-comment-id:4760051975 --> @SpicyMarinara commented on GitHub (Jun 20, 2026): Implemented on branch codex/spicymarinara-assigned-issues: Gemini streaming now aborts on streamed error objects and promptFeedback.blockReason. 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#1317
No description provided.