[PR #7552] [MERGED] fix(gemini): keep unnamed safety categories off when Custom Parameters set some #7789

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

📋 Pull Request Information

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

Base: staging ← Head: fix/gemini-safety-partial-list


📝 Commits (2)

  • b29628e fix(gemini): keep unnamed safety categories off when Custom Parameters set some
  • cef4cc8 fix(gemini): leave a body with both safety spellings as the user wrote it

📊 Changes

3 files changed (+26 additions, -4 deletions)

View changed files

📝 docs/connections/providers-reference.md (+1 -1)
📝 packages/server/src/services/llm/providers/google.provider.ts (+10 -2)
📝 scripts/regressions/provider-compat.regression.ts (+15 -1)

📄 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 #7542

This follows up #7544, which was merged and closed #7542. A review of #7544 found one gap against the requirement that Gemini safety filters are always off.

Why this change

  • In #7544, any safety list in Custom Parameters, even one that names a single category, replaced the whole Off list. For example, {"safety_settings":[{"category":"HARM_CATEGORY_HARASSMENT","threshold":"BLOCK_ONLY_HIGH"}]} sent only that entry. Hate speech, sexually explicit and dangerous content then went back to Google's defaults. On Vertex that default is BLOCK_MEDIUM_AND_ABOVE for models before gemini-3.5-flash (Vertex safety filters), and Gemini 4 Argon has no documented default (Gemini safety settings).
  • Mari wants Gemini filters always off. A user's own entry now wins only for the category it names, and every other category stays Off.

What changed

  • applyGeminiSafetySettingsOff in google.provider.ts (the one helper both Gemini request builders use) now merges by category. It keeps the user's own entries and adds OFF for each of the four adjustable categories the user did not name. The result goes under the spelling the user used (safetySettings or safety_settings), so the field is never sent twice.
  • If the user's Custom Parameters contain both spellings, the body is sent exactly as written, the same as staging today. Adding Off entries under one spelling could contradict a category the user set under the other. Local CodeRabbit flagged this case (see Validation).
  • Docs: the sentence in docs/connections/providers-reference.md now says filters are off "except for any category you set yourself in Custom Parameters". #7543 is updated to the new sentence.
  • No change for a request with no Custom Parameters safety list: it still carries the four OFF entries, and the pinned Gemini 3 bytes are unchanged.

Known gaps (corrected record from #7544)

These routes are still unchanged. #7544 and the #7542 comment are corrected to match.

  • OpenRouter: the chat API reference lists a provider.options object keyed by provider slug, including google-ai-studio and google-vertex, each open-ended. Only options for the matched provider are forwarded, and unrecognised keys are silently dropped. #7544 said this object existed only for video, which was wrong. No Gemini safety key is documented under it, so adding one would be a guess. OpenRouter bodies stay unchanged.
  • NanoGPT and Custom (OpenAI-compatible) connections serving Gemini: both go through the OpenAI-compatible provider, and their bodies are unchanged. The NanoGPT chat reference documents no safety or Gemini passthrough field. For a custom proxy that does document one, the user can add it in Custom Parameters.
  • Google's OpenAI-compatible endpoint, gemini_image, Gemini Omni (Interactions API), Veo, embeddings and model listing are unchanged, for the reasons recorded in #7544.

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 the agent ran (results only; the boxes above are for a human to tick):

  • pnpm check: exit 0.
  • node ./scripts/run-regressions.mjs --filter provider-compat: passed. The existing Gemini 4 Argon block now expects a one-category safety_settings list to arrive with the user's entry plus OFF for the other three categories (Vertex streamGenerateContent). A new assertion pins a body with both spellings as sent exactly as written. Each assertion was run against the code without its fix and failed: the #7544 helper and the helper without the both-spellings guard.
  • --filter provider-caching, generation-parameter-relevance, agent-connection-parameters, open-issues, agent-activation.regression, agent-activation-questions, spatial-context: all passed.
  • Local CodeRabbit (coderabbit review --agent --committed --base-commit 27b4cc004), one run on the first commit: 1 minor finding. With both spellings present, both were serialized. I did not apply the suggested fix, which deletes safety_settings, because it would silently drop categories the user named only there. The finding did show that the merge could add an Off entry contradicting the user's other spelling, so the second commit leaves that body as written. It was not re-run after that guard.
  • GitHub CodeRabbit on #7544 hit its review rate limit and did not review it.
  • No live requests were sent to Google, OpenRouter or any provider. All bodies were checked against a stubbed fetch.

Manual verification notes

  • Send a Gemini message on a Google Gemini (AI Studio) connection and confirm content that Google blocked before now gets a reply with no safety block.
  • Do the same on a Google Vertex AI connection.
  • Do the same with a Gemini model on OpenRouter. OpenRouter is unchanged, so a block there confirms the known gap above.
  • On a Google connection, set Custom Parameters to {"safety_settings":[{"category":"HARM_CATEGORY_HARASSMENT","threshold":"BLOCK_ONLY_HIGH"}]}. With debug mode on, confirm the logged request has that entry plus OFF for hate speech, sexually explicit and dangerous content, and no safetySettings field.

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 follow-up: #7543 ([docs-i18n] docs/connections/providers-reference.md), updated to the new sentence.

UI evidence (if applicable)

Not applicable (server request bodies and one docs sentence).


🔄 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/7552 **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-safety-partial-list` --- ### 📝 Commits (2) - [`b29628e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b29628ed15bd9b533a5c1d6d7c1996522cf44971) fix(gemini): keep unnamed safety categories off when Custom Parameters set some - [`cef4cc8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cef4cc8ad8d1707521a34ec08f7d0544c9160bbb) fix(gemini): leave a body with both safety spellings as the user wrote it ### 📊 Changes **3 files changed** (+26 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/connections/providers-reference.md` (+1 -1) 📝 `packages/server/src/services/llm/providers/google.provider.ts` (+10 -2) 📝 `scripts/regressions/provider-compat.regression.ts` (+15 -1) </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 #7542 This follows up #7544, which was merged and closed #7542. A review of #7544 found one gap against the requirement that Gemini safety filters are always off. ## Why this change - In #7544, any safety list in **Custom Parameters**, even one that names a single category, replaced the whole Off list. For example, `{"safety_settings":[{"category":"HARM_CATEGORY_HARASSMENT","threshold":"BLOCK_ONLY_HIGH"}]}` sent only that entry. Hate speech, sexually explicit and dangerous content then went back to Google's defaults. On Vertex that default is `BLOCK_MEDIUM_AND_ABOVE` for models before gemini-3.5-flash ([Vertex safety filters](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-filters)), and Gemini 4 Argon has no documented default ([Gemini safety settings](https://ai.google.dev/gemini-api/docs/safety-settings)). - Mari wants Gemini filters always off. A user's own entry now wins only for the category it names, and every other category stays Off. ## What changed - `applyGeminiSafetySettingsOff` in `google.provider.ts` (the one helper both Gemini request builders use) now merges by category. It keeps the user's own entries and adds `OFF` for each of the four adjustable categories the user did not name. The result goes under the spelling the user used (`safetySettings` or `safety_settings`), so the field is never sent twice. - If the user's Custom Parameters contain both spellings, the body is sent exactly as written, the same as staging today. Adding Off entries under one spelling could contradict a category the user set under the other. Local CodeRabbit flagged this case (see Validation). - Docs: the sentence in `docs/connections/providers-reference.md` now says filters are off "except for any category you set yourself in **Custom Parameters**". #7543 is updated to the new sentence. - No change for a request with no Custom Parameters safety list: it still carries the four `OFF` entries, and the pinned Gemini 3 bytes are unchanged. ### Known gaps (corrected record from #7544) These routes are still unchanged. #7544 and the #7542 comment are corrected to match. - **OpenRouter:** the [chat API reference](https://openrouter.ai/docs/api/api-reference/chat/send-chat-completion-request) lists a `provider.options` object keyed by provider slug, including `google-ai-studio` and `google-vertex`, each open-ended. Only options for the matched provider are forwarded, and unrecognised keys are silently dropped. #7544 said this object existed only for video, which was wrong. No Gemini safety key is documented under it, so adding one would be a guess. OpenRouter bodies stay unchanged. - **NanoGPT and Custom (OpenAI-compatible) connections serving Gemini:** both go through the OpenAI-compatible provider, and their bodies are unchanged. The [NanoGPT chat reference](https://docs.nano-gpt.com/api-reference/endpoint/chat-completion) documents no safety or Gemini passthrough field. For a custom proxy that does document one, the user can add it in Custom Parameters. - Google's OpenAI-compatible endpoint, `gemini_image`, Gemini Omni (Interactions API), Veo, embeddings and model listing are unchanged, for the reasons recorded in #7544. ## 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 the agent ran (results only; the boxes above are for a human to tick): - `pnpm check`: exit 0. - `node ./scripts/run-regressions.mjs --filter provider-compat`: passed. The existing Gemini 4 Argon block now expects a one-category `safety_settings` list to arrive with the user's entry plus `OFF` for the other three categories (Vertex `streamGenerateContent`). A new assertion pins a body with both spellings as sent exactly as written. Each assertion was run against the code without its fix and failed: the #7544 helper and the helper without the both-spellings guard. - `--filter provider-caching`, `generation-parameter-relevance`, `agent-connection-parameters`, `open-issues`, `agent-activation.regression`, `agent-activation-questions`, `spatial-context`: all passed. - Local CodeRabbit (`coderabbit review --agent --committed --base-commit 27b4cc004`), one run on the first commit: 1 minor finding. With both spellings present, both were serialized. I did not apply the suggested fix, which deletes `safety_settings`, because it would silently drop categories the user named only there. The finding did show that the merge could add an Off entry contradicting the user's other spelling, so the second commit leaves that body as written. It was not re-run after that guard. - GitHub CodeRabbit on #7544 hit its review rate limit and did not review it. - No live requests were sent to Google, OpenRouter or any provider. All bodies were checked against a stubbed `fetch`. ### Manual verification notes - Send a Gemini message on a **Google Gemini (AI Studio)** connection and confirm content that Google blocked before now gets a reply with no safety block. - Do the same on a **Google Vertex AI** connection. - Do the same with a Gemini model on **OpenRouter**. OpenRouter is unchanged, so a block there confirms the known gap above. - On a Google connection, set Custom Parameters to `{"safety_settings":[{"category":"HARM_CATEGORY_HARASSMENT","threshold":"BLOCK_ONLY_HIGH"}]}`. With debug mode on, confirm the logged request has that entry plus `OFF` for hate speech, sexually explicit and dangerous content, and no `safetySettings` field. ## 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 follow-up: #7543 (`[docs-i18n] docs/connections/providers-reference.md`), updated to the new sentence. ## UI evidence (if applicable) Not applicable (server request bodies and one docs sentence). --- <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:32 +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#7789
No description provided.