mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3033] [Issue]: Non-streaming Gemini path drops finishReason, so MAX_TOKENS truncation is reported as a clean "stop" #1603
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#1603
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/3033
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
With a Gemini connection that has thinking/reasoning enabled (the mainstream config for gemini-2.5/3), a response truncated by the output-token limit is reported to the rest of the app as a clean completion. The non-streaming branch of
GoogleProvider.chat()returns token usage but never includes thefinishReason, even though Gemini'sMAX_TOKENSvalue is sitting right there in the candidate. As a result, two genuinely helpful user messages never fire: the game-setup "World generation response was cut off — increase max output tokens" message, and the Professor Mari "hit the model output limit, ask her to continue" warning. The user just sees a truncated or garbled response, or a generic JSON parse error.How to reproduce (try it yourself)
useStreaming = options.stream && !thinkingConfigat line 633. Alternatively call any non-tool generation withstream:false.)finishReason: "MAX_TOKENS".You'll see: the partial text returned, recorded as a normal completion (
finishReasonpersisted as null), and the explicit truncation message never shown.Expected: truncation surfaces as
finishReason: "length", and the "response was cut off / hit the output limit" message fires — matching a streaming Gemini turn, which already does this.Where it is
packages/server/src/services/llm/providers/google.provider.ts— non-streaming branch ofchat(), theif (json.usageMetadata)return block at lines 752-758 (thecandidatewith itsfinishReasonis in scope at line 735 but never read). Contrast: streaming return at line 875 (return { ...streamUsage, finishReason: normalizeGeminiFinishReason(lastFinishReason) }) and tools path at line 583. HelpernormalizeGeminiFinishReason(lines 445-450, mapsMAX_TOKENS→"length"). Fallback that masks the missing reason:base-provider.ts:658(usage?.finishReason ?? "stop"). Consumers:game.routes.ts:1638-1643+4158;professor-mari/workspace-agent.service.ts:579-581+1317.What's happening
The non-streaming branch was written to return only token counts and never threads
candidate.finishReasoninto the returnedLLMUsage, even though it has the candidate in scope.assertGeminiUsableResponsealso does not flagMAX_TOKENSwhen there is visible text (geminiFinishReasonErrorreturns null for that case), so nothing else catches it.BaseLLMProvider.chatCompletethen computesfinishReason: usage?.finishReason ?? "stop", surfacing the truncation as a clean stop.Suggested fix
In the non-streaming return block (lines 752-758), add the finish reason, mirroring the streaming path:
candidateis already in scope (line 735),normalizeGeminiFinishReasonalready exists (line 445), andLLMUsage.finishReasonis a valid optional field. Regression avoided: do NOT also fabricate a zeroed usage object in the no-usagereturn;case (line 760). The live Gemini API always returnsusageMetadataon aMAX_TOKENStruncation, so that path is effectively unreachable; returning{promptTokens:0,...}there would persist fabricated 0-token counts (generate.routes.ts:6998-7005storesusage?.promptTokens ?? null) for a response that actually produced text, and would make this path the lone outlier versus the streaming/OpenAI convention of returning undefined when no usage exists. Touch only theif (json.usageMetadata)block.Related: one of a family of provider-level "finish/stop reason dropped → truncation reported as a clean stop" issues filed together (Gemini non-streaming, Anthropic non-streaming, OpenAI streaming, ChatGPT-subscription streaming). Same root-cause class, separate per-provider fix.
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.