mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #1097] [Issue]: OpenRouter Gemini reasoning replay inflates prompt tokens #541
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#541
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cha1latte on GitHub (May 22, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1097
Originally assigned to: @cha1latte on GitHub.
Summary
OpenRouter Gemini requests can replay prior assistant reasoning metadata into later OpenAI-compatible messages, causing excessive prompt token usage for Gemini-family models.
Expected behavior
Gemini/OpenRouter requests should not replay
extra.chatCompletionsReasoning/reasoning_detailsmetadata when that provider/model family does not need reasoning continuity from prior assistant messages.Actual behavior
The reporter observed that Gemini 3.5 Flash through Vertex AI via OpenRouter BYOK consumed unusually high prompt tokens. Locally, they found Marinara reattaching
extra.chatCompletionsReasoningfrom assistant messages intoproviderMetadataand replaying it in OpenAI-compatible messages. After a local patch stopped the replay, Gemini 3.5 Flash prompt token counts returned to normal.Steps to reproduce
google-vertex/globalprovider.google/gemini-3.1-pro-previewversusgoogle/gemini-3.5-flash.extra.chatCompletionsReasoning/reasoning_detailsmetadata is being saved and replayed into later OpenAI-compatible messages.Reporter's example:
Marinara Engine version
v1.6.0, build
171edefInstall type
Not specified.
OS + version
Windows 11
Browser or app shell
Not specified.
Screenshots or video
Logs
Additional context
Source: Discord forum post by 로도 in
#marinara-engine-bugs-features, posted Friday, May 22, 2026 at 11:23 AM and edited at 11:31 AM.Reporter recommendation: for OpenRouter Gemini models, do not replay
chatCompletionsReasoningas assistant message metadata and do not save Gemini reasoning metadata for future replay. This should stay separate from thinking models that require replay, such as DeepSeek or GLM.Template check
@franko-c commented on GitHub (May 23, 2026):
the replay site is
packages/server/src/routes/generate.routes.ts:1162-1166, gated only onm.role === "assistant"with no provider check —extra.chatCompletionsReasoningfrom prior turns getsObject.assign'd intoproviderMetadataregardless of the active model:isGoogleProviderat line 1151 (conn.provider === "google" || conn.provider === "google_vertex") already exists but only covers direct Google connections. OpenRouter BYOK routing togoogle-vertex/globallands asconn.provider === "openrouter"withconn.modellikegoogle/gemini-3.5-flash, so it falls outside that check and gets the OpenAI-style reasoning replay anyway. there's a similar provider+model-prefix pattern at line 2975 (providerLower === "openrouter" && modelLower.startsWith("x-ai/grok-")) that's the right shape to reuse.both the replay site and the save site (line 6280-6282
rememberChatCompletionsReasoning, persisted at 6911-6912) need to gate on the same condition — otherwise re-enabling replay for Gemini would silently work for cached chats but not new ones, or vice-versa. the existing comment at line 6910 ("Store Chat Completions reasoning fields for providers that require replay (DeepSeek/OpenRouter)") suggests the original author already had a model-family allowlist in mind — turning that comment into a real check covers the reporter's case.haven't traced whether GLM (mentioned in the reporter's note alongside DeepSeek) routes through OpenRouter the same way, so the allowlist might need to include both an OpenRouter+model-prefix shape and direct-provider matches.