[PR #1103] [MERGED] Fix OpenRouter Gemini reasoning replay #4922

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1103
Author: @cha1latte
Created: 5/22/2026
Status: ✅ Merged
Merged: 5/22/2026
Merged by: @cha1latte

Base: staging ← Head: fix/issue-1097-openrouter-gemini-reasoning


📝 Commits (1)

  • d5718f6 Fix OpenRouter Gemini reasoning replay

📊 Changes

2 files changed (+31 additions, -11 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+9 -1)
📝 packages/server/src/services/llm/providers/openai.provider.ts (+22 -10)

📄 Description

Linked issue

Closes #1097

Why this change

  • OpenRouter Gemini requests were replaying stored Chat Completions reasoning metadata from prior assistant messages, which inflated prompt token usage for Gemini-family models that do not need that metadata for continuity.

What changed

  • Skips replaying and capturing Chat Completions reasoning metadata for OpenRouter Gemini-family models.
  • Keeps replay behavior intact for providers/models that still need it, such as DeepSeek reasoning metadata.
  • Ignores stored Gemini reasoning metadata during prompt hydration so existing affected chats recover without manual cleanup.

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

Manual verification notes

  • Codex proof: pnpm --filter @marinara-engine/server exec tsx ../../scratch/issue-1097-repro.mjs google/gemini-3.5-flash google-vertex/global ../../scratch/issue-1097-after-gemini.json now shows no replayed assistant reasoning / reasoning_details and no captured Gemini reasoning for future replay.
  • Codex edge case: pnpm --filter @marinara-engine/server exec tsx ../../scratch/issue-1097-repro.mjs deepseek/deepseek-r1 default ../../scratch/issue-1097-after-deepseek.json still replays/captures reasoning metadata for DeepSeek.
  • Codex edge case: pnpm --filter @marinara-engine/server exec tsx ../../scratch/issue-1097-repro.mjs anthropic/claude-sonnet-4 default ../../scratch/issue-1097-after-claude.json keeps OpenRouter unified reasoning replay suppressed.
  • Codex baseline: pnpm check passed locally.
  • Non-blocking limitation: actual OpenRouter billing/token accounting was not measured because this environment does not have the reporter's OpenRouter BYOK credentials; the harness verifies the owned request-body and metadata-callback behavior that caused the inflated prompt input.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

N/A - server/provider message serialization change.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of previously stored AI reasoning across different providers
    • Added special handling for specific model types
    • Enhanced provider endpoint detection
    • Refined reasoning metadata processing consistency in different response modes

Review Change Stack


🔄 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/1103 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/22/2026 **Status:** ✅ Merged **Merged:** 5/22/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `staging` ← **Head:** `fix/issue-1097-openrouter-gemini-reasoning` --- ### 📝 Commits (1) - [`d5718f6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d5718f61c0027e8fe7e7e66625baf5061d9bfa67) Fix OpenRouter Gemini reasoning replay ### 📊 Changes **2 files changed** (+31 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+9 -1) 📝 `packages/server/src/services/llm/providers/openai.provider.ts` (+22 -10) </details> ### 📄 Description <!-- Target branch: `staging`. The default base in this UI is `main` (release branch). --> <!-- Change the base to `staging` before submitting unless this is a maintainer-approved mainline change. --> <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue <!-- Every PR should reference a feature request or issue report. If there isn't one yet, open one first to gather opinions: --> <!-- https://github.com/Pasta-Devs/Marinara-Engine/issues/new/choose --> Closes #1097 ## Why this change <!-- What user problem, bug, or goal does this solve? --> - OpenRouter Gemini requests were replaying stored Chat Completions reasoning metadata from prior assistant messages, which inflated prompt token usage for Gemini-family models that do not need that metadata for continuity. ## What changed <!-- List the key changes in this PR --> - Skips replaying and capturing Chat Completions reasoning metadata for OpenRouter Gemini-family models. - Keeps replay behavior intact for providers/models that still need it, such as DeepSeek reasoning metadata. - Ignores stored Gemini reasoning metadata during prompt hydration so existing affected chats recover without manual cleanup. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [ ] `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` ### Manual verification notes <!-- Describe exactly what you tested in a real browser/app, step by step. --> <!-- ⚠️ If an AI agent filled out or ticked these boxes for you, treat them --> <!-- as a TO-DO LIST, not as proof the work is done. Verify each item yourself --> <!-- before submitting. If you haven't verified it, untick the box. --> - Codex proof: `pnpm --filter @marinara-engine/server exec tsx ../../scratch/issue-1097-repro.mjs google/gemini-3.5-flash google-vertex/global ../../scratch/issue-1097-after-gemini.json` now shows no replayed assistant `reasoning` / `reasoning_details` and no captured Gemini reasoning for future replay. - Codex edge case: `pnpm --filter @marinara-engine/server exec tsx ../../scratch/issue-1097-repro.mjs deepseek/deepseek-r1 default ../../scratch/issue-1097-after-deepseek.json` still replays/captures reasoning metadata for DeepSeek. - Codex edge case: `pnpm --filter @marinara-engine/server exec tsx ../../scratch/issue-1097-repro.mjs anthropic/claude-sonnet-4 default ../../scratch/issue-1097-after-claude.json` keeps OpenRouter unified reasoning replay suppressed. - Codex baseline: `pnpm check` passed locally. - Non-blocking limitation: actual OpenRouter billing/token accounting was not measured because this environment does not have the reporter's OpenRouter BYOK credentials; the harness verifies the owned request-body and metadata-callback behavior that caused the inflated prompt input. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) N/A - server/provider message serialization change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of previously stored AI reasoning across different providers * Added special handling for specific model types * Enhanced provider endpoint detection * Refined reasoning metadata processing consistency in different response modes <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/1103?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- 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-22 04:11:45 +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#4922
No description provided.