[GH-ISSUE #2667] [Issue]: Gemini safety-blocked or empty responses are reported as a normal stop with no error #1318

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/2667

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The non-streaming and streaming Gemini handlers only read candidates[0].content.parts and never inspect promptFeedback.blockReason or a non-stop finishReason (SAFETY/RECITATION/etc.). A safety-blocked or empty response (HTTP 200 with empty candidates) is reported as a normal "stop" with empty content and no error.

Expected behavior

When Gemini blocks a prompt or returns no content for a terminal non-stop reason, the user should get a clear error explaining the block, not a silent empty turn that looks like a successful (empty) completion.

Actual behavior

chatComplete() parses parts and computes finishReason: candidate?.finishReason ?? "stop" — when there is no candidate at all this becomes literally "stop". The streaming chat() path similarly yields nothing and returns normally. promptFeedback.blockReason is never inspected.

How it breaks the pipeline

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

  • chatComplete: parts ~:434; finishReason: toolCalls.length > 0 ? "tool_calls" : (candidate?.finishReason ?? "stop") at :451.
  • chat (streaming): parts ~:602.
  • No promptFeedback / blockReason handling exists anywhere in the file.

Result: a blocked prompt ({ promptFeedback: { blockReason: "SAFETY" }, candidates: [] }) returns { content: null, finishReason: "stop" }, and the streaming path returns empty with no error.

Steps to reproduce

  1. Send a prompt Gemini blocks (it returns HTTP 200 with promptFeedback.blockReason and empty candidates).
  2. Observe: the assistant turn is blank; finishReason is "stop"; no error surfaces explaining the block.

Suggested fix

After computing parts, if promptFeedback?.blockReason is set, or candidates is empty, or the candidate's finishReason is a non-stop terminal reason (SAFETY/RECITATION/PROHIBITED_CONTENT/MAX_TOKENS) and no text/tool parts were produced, throw an error that includes the block/finish reason so the caller can surface why no output was produced.

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). Companion to the Gemini streaming-error-swallow issue filed concurrently — the non-streaming path has the same blind spot for blocked/empty responses.

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/2667 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The non-streaming and streaming Gemini handlers only read `candidates[0].content.parts` and never inspect `promptFeedback.blockReason` or a non-`stop` `finishReason` (SAFETY/RECITATION/etc.). A safety-blocked or empty response (HTTP 200 with empty `candidates`) is reported as a normal `"stop"` with empty content and no error. ## Expected behavior When Gemini blocks a prompt or returns no content for a terminal non-stop reason, the user should get a clear error explaining the block, not a silent empty turn that looks like a successful (empty) completion. ## Actual behavior `chatComplete()` parses `parts` and computes `finishReason: candidate?.finishReason ?? "stop"` — when there is no candidate at all this becomes literally `"stop"`. The streaming `chat()` path similarly yields nothing and returns normally. `promptFeedback.blockReason` is never inspected. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`) — `packages/server/src/services/llm/providers/google.provider.ts`: - `chatComplete`: `parts` ~`:434`; `finishReason: toolCalls.length > 0 ? "tool_calls" : (candidate?.finishReason ?? "stop")` at `:451`. - `chat` (streaming): `parts` ~`:602`. - No `promptFeedback` / `blockReason` handling exists anywhere in the file. Result: a blocked prompt (`{ promptFeedback: { blockReason: "SAFETY" }, candidates: [] }`) returns `{ content: null, finishReason: "stop" }`, and the streaming path returns empty with no error. ## Steps to reproduce 1. Send a prompt Gemini blocks (it returns HTTP 200 with `promptFeedback.blockReason` and empty `candidates`). 2. Observe: the assistant turn is blank; `finishReason` is `"stop"`; no error surfaces explaining the block. ## Suggested fix After computing `parts`, if `promptFeedback?.blockReason` is set, or `candidates` is empty, or the candidate's `finishReason` is a non-stop terminal reason (SAFETY/RECITATION/PROHIBITED_CONTENT/MAX_TOKENS) **and** no text/tool parts were produced, throw an error that includes the block/finish reason so the caller can surface why no output was produced. ## 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`). Companion to the Gemini streaming-error-swallow issue filed concurrently — the non-streaming path has the same blind spot for blocked/empty responses. ## 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 blocked/empty responses now surface clear errors instead of empty stop results. Final validation will run after the full assigned sweep per maintainer request.

<!-- gh-comment-id:4760051979 --> @SpicyMarinara commented on GitHub (Jun 20, 2026): Implemented on branch codex/spicymarinara-assigned-issues: Gemini blocked/empty responses now surface clear errors instead of empty stop results. 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#1318
No description provided.