[PR #1875] [MERGED] Fix Gemini stream truncation handling #5329

Closed
opened 2026-10-22 04:15:17 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1875
Author: @cha1latte
Created: 6/2/2026
Status: ✅ Merged
Merged: 6/2/2026
Merged by: @cha1latte

Base: refactor ← Head: fix/1871-gm-narration-truncation


📝 Commits (2)

  • d84b180 Fix Gemini stream truncation handling
  • 5873585 Fix Gemini stream clippy warning

📊 Changes

1 file changed (+61 additions, -5 deletions)

View changed files

📝 src-tauri/crates/llm/src/lib.rs (+61 -5)

📄 Description

Linked issue

Closes #1871

Why this change

  • Game Mode narration could show a partial LinkAPI/Gemini response as if it were final when the Google/Gemini stream ended without a clean stop, or when Gemini stopped for a truncating finish reason such as MAX_TOKENS.

What changed

  • Require Google/Gemini streaming responses to receive an explicit terminal event before the Rust LLM stream reports success.
  • Treat non-STOP Gemini finish reasons as llm_stream_incomplete so generation surfaces a provider issue instead of saving/displaying partial narration as complete.
  • Added regression coverage for abrupt stream close and MAX_TOKENS, while preserving normal STOP and usage/thinking stream handling.

Refactor impact

Primary owner:

  • Rust storage / LLM provider transport

Impact areas reviewed:

  • Google/Gemini streaming parser
  • LinkAPI Gemini endpoint path, because it uses the Google provider stream path
  • Runtime generation consumer behavior, which depends on provider stream success/failure

Boundary notes:

  • The change stays in the Rust LLM provider stream producer. No React, engine prompt assembly, storage schema, shared API wrapper, or dependency declarations changed.

Pressure points touched:

  • src-tauri/crates/llm/src/lib.rs Google/Gemini stream parsing and stream completion contract

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • Codex reproduced the provider-stream bug with a focused regression test: before the fix, an abrupt Gemini stream close returned Ok(()).
  • cargo test --manifest-path src-tauri\crates\llm\Cargo.toml google_stream_ passed after the fix.
  • cargo test --manifest-path src-tauri\crates\llm\Cargo.toml passed after the fix.
  • cargo check --manifest-path src-tauri\Cargo.toml passed after the fix.
  • pnpm check passed on the rebased commit before push.
  • node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json passed.
  • Bunny review passed on the rebased commit.
  • No live LinkAPI credentialed request was run in this environment; the provider-stream contract is covered by local Rust tests.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • This is a provider-stream bugfix and does not add a new discoverable product surface.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

N/A: backend/provider-stream contract bug. Proof is the failing-before/passing-after Rust regression and PR gate output above.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/1875 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 6/2/2026 **Status:** ✅ Merged **Merged:** 6/2/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/1871-gm-narration-truncation` --- ### 📝 Commits (2) - [`d84b180`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d84b180f17dcc9c6bb2899d4de30b50d7dd5315d) Fix Gemini stream truncation handling - [`5873585`](https://github.com/Pasta-Devs/Marinara-Engine/commit/587358567ea2cc40e756d64f3a9469df8a0218a8) Fix Gemini stream clippy warning ### 📊 Changes **1 file changed** (+61 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/crates/llm/src/lib.rs` (+61 -5) </details> ### 📄 Description ## Linked issue Closes #1871 ## Why this change - Game Mode narration could show a partial LinkAPI/Gemini response as if it were final when the Google/Gemini stream ended without a clean stop, or when Gemini stopped for a truncating finish reason such as `MAX_TOKENS`. ## What changed - Require Google/Gemini streaming responses to receive an explicit terminal event before the Rust LLM stream reports success. - Treat non-`STOP` Gemini finish reasons as `llm_stream_incomplete` so generation surfaces a provider issue instead of saving/displaying partial narration as complete. - Added regression coverage for abrupt stream close and `MAX_TOKENS`, while preserving normal `STOP` and usage/thinking stream handling. ## Refactor impact Primary owner: - Rust storage / LLM provider transport Impact areas reviewed: - Google/Gemini streaming parser - LinkAPI Gemini endpoint path, because it uses the Google provider stream path - Runtime generation consumer behavior, which depends on provider stream success/failure Boundary notes: - The change stays in the Rust LLM provider stream producer. No React, engine prompt assembly, storage schema, shared API wrapper, or dependency declarations changed. Pressure points touched: - `src-tauri/crates/llm/src/lib.rs` Google/Gemini stream parsing and stream completion contract ## Validation - [ ] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - Codex reproduced the provider-stream bug with a focused regression test: before the fix, an abrupt Gemini stream close returned `Ok(())`. - `cargo test --manifest-path src-tauri\crates\llm\Cargo.toml google_stream_` passed after the fix. - `cargo test --manifest-path src-tauri\crates\llm\Cargo.toml` passed after the fix. - `cargo check --manifest-path src-tauri\Cargo.toml` passed after the fix. - `pnpm check` passed on the rebased commit before push. - `node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json` passed. - Bunny review passed on the rebased commit. - No live LinkAPI credentialed request was run in this environment; the provider-stream contract is covered by local Rust tests. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [ ] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - This is a provider-stream bugfix and does not add a new discoverable product surface. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [ ] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence N/A: backend/provider-stream contract bug. Proof is the failing-before/passing-after Rust regression and PR gate output above. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:15:17 +07:00
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#5329
No description provided.