[PR #7560] [MERGED] fix(gemini): no final AI turn or penalties for Argon and Gemini 3.6+ Flash on every route #7797

Closed
opened 2026-10-24 04:07:35 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7560
Author: @SpicyMarinara
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/gemini-request-shapes


📝 Commits (1)

  • 32861db fix(gemini): no final AI turn or penalties for Argon and Gemini 3.6+ Flash on every route

📊 Changes

6 files changed (+305 additions, -29 deletions)

View changed files

📝 packages/server/src/services/llm/providers/google.provider.ts (+25 -14)
📝 packages/server/src/services/llm/providers/openai.provider.ts (+45 -13)
📝 packages/shared/src/constants/generation-parameter-relevance.ts (+3 -0)
📝 packages/shared/src/constants/model-lists.ts (+12 -0)
📝 scripts/regressions/generation-parameter-relevance.regression.ts (+6 -2)
📝 scripts/regressions/provider-compat.regression.ts (+214 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7558

Why this change

Google rejects a Gemini request that ends on an AI turn, and also rejects frequency and presence penalties, for these models:

  • Gemini 4 Argon
  • Gemini 3.5 Flash-Lite
  • Gemini 3.6, 3.7 and 3.8 Flash

Marinara only guarded Argon, and only on the native Google and Vertex connections. Several common actions could therefore fail:

  • On OpenRouter, NanoGPT or a custom connection, Argon failed after a preset with an Assistant Prefill, or after pressing Send with an empty box following an AI reply in Roleplay.
  • The newer Flash models failed the same way on every connection.
  • Any penalty setting broke all of these models.

Two smaller OpenRouter problems:

  • OpenRouter Gemini tool rounds dropped the reasoning details OpenRouter asks to be sent back.
  • With Post-Processing: Don't Apply, Gemini got mid-chat system messages whose handling OpenRouter does not document.

What changed

Behaviour that changes for things that worked before:

  • Penalties are no longer sent for Gemini 3.5 Flash-Lite and 3.6 to 3.8 Flash. This applies on Google, Vertex, OpenRouter and NanoGPT, and the panel now hides them for these models. Google documents that these models reject penalties. A custom connection still sends them, as it already does for Argon.
  • With Post-Processing: Don't Apply, any Gemini model on an OpenRouter, NanoGPT or custom connection now gets system messages that come after the first turn as user messages, in place. Leading system messages are unchanged. Native Google and Vertex are unchanged.

Fixes:

  • One shared rule (isGeminiStrictRequestModel in model-lists.ts) covers Argon, 3.5 Flash-Lite and 3.6 to 3.8 Flash. Both native Google and the OpenAI-compatible path use it.
  • Requests that end on an AI turn get a short user turn asking the model to continue. Native Google already did this for Argon. The OpenAI-compatible path reuses the helper Claude Opus 5.5 and Sonnet 5.5 already use, without their Claude-only rewrites. This covers both prefills and empty Sends after a reply.
  • OpenRouter Gemini tool rounds send each tool call's reasoning_details back unmodified, within the same tool loop only. Saved chat history is still filtered at the route, so #1097 stays fixed.
  • Native chat() keeps a past AI turn that has saved Gemini parts but no text, as the tools path already does.
  • Code comments: the Argon comments now cite the Vertex guide that contains the prefill and penalty rules.

What stays Argon-only: the temperature, top-p and top-k removal, the thinking levels and streaming. Google documents those differently for the Flash models: it ignores their samplers rather than rejecting them, and Marinara never sends minimal or thinkingBudget to them.

Bodies that do not change:

  • Gemini 3.5 Flash and 3.1 Pro on Google and Vertex.
  • Gemini 3.5 Flash, 3.1 Pro and a non-Gemini model on OpenRouter.

Both sets are pinned byte for byte, and I checked them against a capture from staging.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Commands run by the agent. Each passed locally; nothing was sent to Google, OpenRouter or any running instance:

  • pnpm check
  • node ./scripts/run-regressions.mjs --filter scripts/regressions/provider-compat.regression.ts
  • node ./scripts/run-regressions.mjs --filter scripts/regressions/generation-parameter-relevance.regression.ts
  • node ./scripts/run-regressions.mjs --filter past-reasoning-history
  • node ./scripts/run-regressions.mjs --filter agent-activation
  • node ./scripts/run-regressions.mjs --filter spatial-context
  • node ./scripts/run-regressions.mjs --filter open-issues

Local CodeRabbit (coderabbit review --agent --committed --base-commit adcfe6d76) reviewed all 6 files and reported 0 findings. The GitHub CodeRabbit check on the first push said "Review rate limited", so it has not reviewed yet.

The provider bodies were checked against a stubbed fetch (PROVIDER_LOCAL_URLS_ENABLED=true). The new cases fail on staging's provider code and pass on this branch. The panel parity check fails if the new panel rule is removed.

Manual verification notes

Manual verification needed:

  • On OpenRouter with google/gemini-4-argon, press Send with an empty box after a reply in Roleplay. Confirm the reply continues without an error.
  • On OpenRouter with google/gemini-4-argon, use a preset with an Assistant Prefill. Confirm the reply continues the prefill without an error.
  • On Google AI Studio or Vertex with gemini-3.8-flash, do the same empty Send and the same prefill. Confirm both work, and that the penalty sliders are hidden for that model.
  • On OpenRouter with a Gemini model and chat tools on (for example, dice rolls), trigger a tool call. Confirm the second round answers without a "thought signature" or 400 error.
  • On OpenRouter with a Gemini model and Post-Processing: Don't Apply, add an author's note. Confirm the reply still follows the main prompt and the character card.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

docs/connections/providers-reference.md does not describe prefill or penalty handling, so this PR changes no docs and adds nothing to #7543.

Sources


🔄 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/7560 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/gemini-request-shapes` --- ### 📝 Commits (1) - [`32861db`](https://github.com/Pasta-Devs/Marinara-Engine/commit/32861db9a39677c1d66d78dbafa20c60ecdf35dc) fix(gemini): no final AI turn or penalties for Argon and Gemini 3.6+ Flash on every route ### 📊 Changes **6 files changed** (+305 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/llm/providers/google.provider.ts` (+25 -14) 📝 `packages/server/src/services/llm/providers/openai.provider.ts` (+45 -13) 📝 `packages/shared/src/constants/generation-parameter-relevance.ts` (+3 -0) 📝 `packages/shared/src/constants/model-lists.ts` (+12 -0) 📝 `scripts/regressions/generation-parameter-relevance.regression.ts` (+6 -2) 📝 `scripts/regressions/provider-compat.regression.ts` (+214 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7558 ## Why this change Google rejects a Gemini request that ends on an AI turn, and also rejects frequency and presence penalties, for these models: - Gemini 4 Argon - Gemini 3.5 Flash-Lite - Gemini 3.6, 3.7 and 3.8 Flash Marinara only guarded Argon, and only on the native Google and Vertex connections. Several common actions could therefore fail: - On OpenRouter, NanoGPT or a custom connection, Argon failed after a preset with an Assistant Prefill, or after pressing Send with an empty box following an AI reply in Roleplay. - The newer Flash models failed the same way on every connection. - Any penalty setting broke all of these models. Two smaller OpenRouter problems: - OpenRouter Gemini tool rounds dropped the reasoning details OpenRouter asks to be sent back. - With **Post-Processing: Don't Apply**, Gemini got mid-chat system messages whose handling OpenRouter does not document. ## What changed Behaviour that changes for things that worked before: - **Penalties are no longer sent** for Gemini 3.5 Flash-Lite and 3.6 to 3.8 Flash. This applies on Google, Vertex, OpenRouter and NanoGPT, and the panel now hides them for these models. Google documents that these models reject penalties. A custom connection still sends them, as it already does for Argon. - **With Post-Processing: Don't Apply**, any Gemini model on an OpenRouter, NanoGPT or custom connection now gets system messages that come after the first turn as user messages, in place. Leading system messages are unchanged. Native Google and Vertex are unchanged. Fixes: - **One shared rule** (`isGeminiStrictRequestModel` in `model-lists.ts`) covers Argon, 3.5 Flash-Lite and 3.6 to 3.8 Flash. Both native Google and the OpenAI-compatible path use it. - **Requests that end on an AI turn** get a short user turn asking the model to continue. Native Google already did this for Argon. The OpenAI-compatible path reuses the helper Claude Opus 5.5 and Sonnet 5.5 already use, without their Claude-only rewrites. This covers both prefills and empty Sends after a reply. - **OpenRouter Gemini tool rounds** send each tool call's `reasoning_details` back unmodified, within the same tool loop only. Saved chat history is still filtered at the route, so #1097 stays fixed. - **Native `chat()`** keeps a past AI turn that has saved Gemini parts but no text, as the tools path already does. - **Code comments**: the Argon comments now cite the Vertex guide that contains the prefill and penalty rules. What stays Argon-only: the temperature, top-p and top-k removal, the thinking levels and streaming. Google documents those differently for the Flash models: it ignores their samplers rather than rejecting them, and Marinara never sends `minimal` or `thinkingBudget` to them. Bodies that do not change: - Gemini 3.5 Flash and 3.1 Pro on Google and Vertex. - Gemini 3.5 Flash, 3.1 Pro and a non-Gemini model on OpenRouter. Both sets are pinned byte for byte, and I checked them against a capture from staging. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Commands run by the agent. Each passed locally; nothing was sent to Google, OpenRouter or any running instance: - `pnpm check` - `node ./scripts/run-regressions.mjs --filter scripts/regressions/provider-compat.regression.ts` - `node ./scripts/run-regressions.mjs --filter scripts/regressions/generation-parameter-relevance.regression.ts` - `node ./scripts/run-regressions.mjs --filter past-reasoning-history` - `node ./scripts/run-regressions.mjs --filter agent-activation` - `node ./scripts/run-regressions.mjs --filter spatial-context` - `node ./scripts/run-regressions.mjs --filter open-issues` Local CodeRabbit (`coderabbit review --agent --committed --base-commit adcfe6d76`) reviewed all 6 files and reported 0 findings. The GitHub CodeRabbit check on the first push said "Review rate limited", so it has not reviewed yet. The provider bodies were checked against a stubbed `fetch` (`PROVIDER_LOCAL_URLS_ENABLED=true`). The new cases fail on staging's provider code and pass on this branch. The panel parity check fails if the new panel rule is removed. ### Manual verification notes Manual verification needed: - On OpenRouter with `google/gemini-4-argon`, press Send with an empty box after a reply in Roleplay. Confirm the reply continues without an error. - On OpenRouter with `google/gemini-4-argon`, use a preset with an Assistant Prefill. Confirm the reply continues the prefill without an error. - On Google AI Studio or Vertex with `gemini-3.8-flash`, do the same empty Send and the same prefill. Confirm both work, and that the penalty sliders are hidden for that model. - On OpenRouter with a Gemini model and chat tools on (for example, dice rolls), trigger a tool call. Confirm the second round answers without a "thought signature" or 400 error. - On OpenRouter with a Gemini model and **Post-Processing: Don't Apply**, add an author's note. Confirm the reply still follows the main prompt and the character card. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) `docs/connections/providers-reference.md` does not describe prefill or penalty handling, so this PR changes no docs and adds nothing to #7543. ## Sources - Argon (prefill, penalties, sampling, thinking): https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/guides/gemini-4-argon - Gemini 3.6 Flash and 3.5 Flash-Lite (prefill rule): https://ai.google.dev/gemini-api/docs/whats-new-gemini-3.6 - Gemini 3.6 Flash (final model turn and penalties): https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/guides/gemini-3-6-flash - Gemini 3.7 Flash: https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/guides/gemini-3-7-flash - Gemini 3.8 Flash: https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/guides/gemini-3-8-flash - Gemini 3.5 Flash-Lite (final model turn and penalties): https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/3-5-flash-lite - OpenRouter, passing `reasoning_details` back during tool calling: https://openrouter.ai/docs/guides/best-practices/reasoning-tokens - Report that later system messages replace earlier ones for Gemini (third party): https://github.com/pipecat-ai/pipecat/issues/3362 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:07:35 +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#7797
No description provided.