[PR #5974] [MERGED] fix(gemini): stream reasoning on official Google endpoints #7006

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5974
Author: @SpicyMarinara
Created: 9/8/2026
Status: ✅ Merged
Merged: 9/9/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/google-thinking-stream-5904


📝 Commits (5)

  • 2fd3191 chore: start Gemini thinking stream fix (#5904)
  • 8867ac9 fix(gemini): scope buffered thinking to proxy endpoints
  • 5093525 fix(google): cancel response body when streaming stops early
  • 0aa78cc Merge remote-tracking branch 'origin/staging' into fix/google-thinking-stream-5904
  • 0e8b73d Merge remote-tracking branch 'origin/staging' into fix/google-thinking-stream-5904

📊 Changes

3 files changed (+140 additions, -18 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/llm/providers/google.provider.ts (+18 -10)
📝 scripts/regressions/provider-compat.regression.ts (+121 -8)

📄 Description

Linked issue

Closes #5904

Why this change

Gemini reasoning replies buffered the entire turn on Google's own API because a workaround for proxies that strip thought parts applied to every endpoint. Users waited with an empty reply even though the native API supports streaming thought summaries.

What changed

Both the ordinary and tool-calling paths use the same hostname check: thinking can stream on generativelanguage.googleapis.com, while other endpoints retain their existing buffered compatibility path. Explicit non-streaming requests and tool calls without a token sink retain their existing behavior. No new setting or dependency.

Validation

  • pnpm check passed, including the production build.
  • Provider compatibility regressions passed. The new case failed against the original buffered endpoint and passes after the fix.
  • Both native generation paths are exercised with a withheld stream tail: text must reach its callback before the rest of the response can arrive. Thought summaries and signatures survive, including a tool-call signature. Existing proxy-buffering and no-token-sink controls also pass.
  • Manually verify a reasoning reply streams on a real Google API connection, with and without tools.
  • Manually verify an existing proxy connection retains its thought summaries.
  • Build and run the container.

The provider tests use controlled responses, not a paid live-provider call. Google's official Gemini 2.5 example demonstrates streaming with include_thoughts enabled.

Docs and release impact

Unreleased changelog entry included. No user-facing documentation or release-version changes. Vertex and unrecognized proxies keep their existing compatibility behavior.

Summary by CodeRabbit

  • Bug Fixes

    • Gemini reasoning responses now stream correctly through Google’s official API, including tool-using conversations.
    • Compatibility is preserved for proxy endpoints that require buffered reasoning responses.
  • Tests

    • Added regression coverage for streamed reasoning, tool calls, token callbacks, provider metadata, and request cleanup.
  • Documentation

    • Updated the changelog with the Gemini streaming fix.

🔄 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/5974 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 9/8/2026 **Status:** ✅ Merged **Merged:** 9/9/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/google-thinking-stream-5904` --- ### 📝 Commits (5) - [`2fd3191`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2fd319189a48869db653ae8f0bc3a4c4c3eb5d30) chore: start Gemini thinking stream fix (#5904) - [`8867ac9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8867ac9f825f7de1f74d5be7963e7c07fb6b0b28) fix(gemini): scope buffered thinking to proxy endpoints - [`5093525`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5093525bfc25b6a93ae7ed5a6323c5896731b76e) fix(google): cancel response body when streaming stops early - [`0aa78cc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0aa78cc60c41fc53f5cbd53c0c6a0b0ee7a63777) Merge remote-tracking branch 'origin/staging' into fix/google-thinking-stream-5904 - [`0e8b73d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0e8b73d1c37e8bed389248188233e2329337bc77) Merge remote-tracking branch 'origin/staging' into fix/google-thinking-stream-5904 ### 📊 Changes **3 files changed** (+140 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/llm/providers/google.provider.ts` (+18 -10) 📝 `scripts/regressions/provider-compat.regression.ts` (+121 -8) </details> ### 📄 Description ## Linked issue Closes #5904 ## Why this change Gemini reasoning replies buffered the entire turn on Google's own API because a workaround for proxies that strip thought parts applied to every endpoint. Users waited with an empty reply even though the native API supports streaming thought summaries. ## What changed Both the ordinary and tool-calling paths use the same hostname check: thinking can stream on `generativelanguage.googleapis.com`, while other endpoints retain their existing buffered compatibility path. Explicit non-streaming requests and tool calls without a token sink retain their existing behavior. No new setting or dependency. ## Validation - `pnpm check` passed, including the production build. - Provider compatibility regressions passed. The new case failed against the original buffered endpoint and passes after the fix. - Both native generation paths are exercised with a withheld stream tail: text must reach its callback before the rest of the response can arrive. Thought summaries and signatures survive, including a tool-call signature. Existing proxy-buffering and no-token-sink controls also pass. - [ ] Manually verify a reasoning reply streams on a real Google API connection, with and without tools. - [ ] Manually verify an existing proxy connection retains its thought summaries. - [ ] Build and run the container. The provider tests use controlled responses, not a paid live-provider call. Google's [official Gemini 2.5 example](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/getting-started/intro_gemini_2_5_flash.ipynb) demonstrates streaming with `include_thoughts` enabled. ## Docs and release impact Unreleased changelog entry included. No user-facing documentation or release-version changes. Vertex and unrecognized proxies keep their existing compatibility behavior. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Gemini reasoning responses now stream correctly through Google’s official API, including tool-using conversations. - Compatibility is preserved for proxy endpoints that require buffered reasoning responses. - **Tests** - Added regression coverage for streamed reasoning, tool calls, token callbacks, provider metadata, and request cleanup. - **Documentation** - Updated the changelog with the Gemini streaming fix. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:15:41 +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#7006
No description provided.