[GH-ISSUE #2958] [Issue]: Regenerating a message leaks the previous swipe's translation / sprite / choices / token count onto the new one #1535

Closed
opened 2026-10-21 05:38:24 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2958

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

When you regenerate an assistant message (which creates a new swipe), the new swipe inherits the previous swipe's per-swipe display data — its translation, sprite expression, CYOA choice buttons, token count, and Gemini "thought parts." If the new generation doesn't produce its own version of that data, the stale old data stays attached to the new, unrelated text.

The worst case is Gemini: a stale geminiParts value can later be sent to the model as that message's content, silently replacing your regenerated text.

How to reproduce (try it yourself)

Translation (most reliable):

  1. In a roleplay/conversation chat, translate an assistant message (auto-translate or manual) so it shows a translation.
  2. Regenerate that message.
    You'll see: the new swipe shows the previous swipe's translation (mistranslating the now-visible new text); it survives a page refresh and auto-translate won't re-translate it.
    Expected: no translation, or a fresh translation of the new text.

CYOA: in a CYOA chat, generate a message with choice buttons, then regenerate; if the new generation emits no choices, the old swipe's buttons stay under the new prose.

Gemini (the severe one):

  1. On a Gemini connection with thinking enabled, generate an assistant message (stores geminiParts).
  2. Switch the chat to a non-Gemini connection and regenerate that message.
  3. Switch back to a Gemini connection and continue.
    You'll see: the next Gemini call sends the old generation's parts as that turn's content, discarding the regenerated text.
    Expected: a fresh swipe starts with empty per-swipe data.

Where it is

packages/server/src/services/storage/chats.storage.ts — addSwipe() clearedExtra at lines 1050-1062 spreads the outgoing swipe's entire extra and nulls only thinking / generationInfo / attachments / generationReplay, while the new swipe row is inserted with extra: {} (line 1042). So the mirrored message row keeps every other field; the swipe row is empty — they diverge at creation. Fields that every regenerate unconditionally rewrites (cachedPrompt, thinking, generationInfo, contextInjections, chatCompletionsReasoning) don't leak; the ones with no unconditional rewrite do: translation, translationHidden, spriteExpressions, cyoaChoices, tokenCount, geminiParts. For Gemini specifically, generate.routes.ts:7013 is if (geminiResponseParts) extraUpdate.geminiParts = geminiResponseParts; with no else-null (unlike thinking at 7010-7011 and chatCompletionsReasoning at 7015-7016), so a non-Gemini regen never clears it; it's later consumed in google.provider.ts where stored parts replace the message content.

What's happening

clearedExtra is an allowlist-NULL of 4 fields layered on top of a full spread of the old extra, so the message-row mirror is born carrying stale per-swipe data that the empty swipe row doesn't have. The client hydrates translation/sprites/choices from the message-row mirror, so the stale data displays and persists.

Suggested fix

Invert clearedExtra: build it by copying only the genuine message-level fields that must survive a swipe (e.g. hiddenFromAI, hiddenFromUser, reactions, isConversationStart, persona/command flags) and start everything else empty — matching the {} written to the new swipe row at line 1042. That clears translation, translationHidden, spriteExpressions, cyoaChoices, geminiParts, tokenCount, etc. in one place. Additionally add else extraUpdate.geminiParts = null; at generate.routes.ts:7013 to mirror the other reasoning fields.


AI-investigated against v2.0.6; clearedExtra and the geminiParts else-branch read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2958 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** When you regenerate an assistant message (which creates a new swipe), the new swipe inherits the **previous** swipe's per-swipe display data — its translation, sprite expression, CYOA choice buttons, token count, and Gemini "thought parts." If the new generation doesn't produce its own version of that data, the stale old data stays attached to the new, unrelated text. The worst case is Gemini: a stale `geminiParts` value can later be sent to the model **as that message's content**, silently replacing your regenerated text. **How to reproduce (try it yourself)** Translation (most reliable): 1. In a roleplay/conversation chat, translate an assistant message (auto-translate or manual) so it shows a translation. 2. Regenerate that message. **You'll see:** the new swipe shows the *previous* swipe's translation (mistranslating the now-visible new text); it survives a page refresh and auto-translate won't re-translate it. **Expected:** no translation, or a fresh translation of the new text. CYOA: in a CYOA chat, generate a message with choice buttons, then regenerate; if the new generation emits no choices, the **old** swipe's buttons stay under the new prose. Gemini (the severe one): 1. On a Gemini connection with thinking enabled, generate an assistant message (stores `geminiParts`). 2. Switch the chat to a **non-Gemini** connection and regenerate that message. 3. Switch **back** to a Gemini connection and continue. **You'll see:** the next Gemini call sends the *old* generation's parts as that turn's content, discarding the regenerated text. **Expected:** a fresh swipe starts with empty per-swipe data. **Where it is** `packages/server/src/services/storage/chats.storage.ts` — `addSwipe()` `clearedExtra` at lines 1050-1062 spreads the outgoing swipe's **entire** extra and nulls **only** `thinking` / `generationInfo` / `attachments` / `generationReplay`, while the new swipe **row** is inserted with `extra: {}` (line 1042). So the mirrored message row keeps every other field; the swipe row is empty — they diverge at creation. Fields that every regenerate unconditionally rewrites (cachedPrompt, thinking, generationInfo, contextInjections, chatCompletionsReasoning) don't leak; the ones with no unconditional rewrite do: `translation`, `translationHidden`, `spriteExpressions`, `cyoaChoices`, `tokenCount`, `geminiParts`. For Gemini specifically, `generate.routes.ts:7013` is `if (geminiResponseParts) extraUpdate.geminiParts = geminiResponseParts;` with **no** `else`-null (unlike `thinking` at 7010-7011 and `chatCompletionsReasoning` at 7015-7016), so a non-Gemini regen never clears it; it's later consumed in `google.provider.ts` where stored parts replace the message content. **What's happening** `clearedExtra` is an allowlist-NULL of 4 fields layered on top of a full spread of the old extra, so the message-row mirror is born carrying stale per-swipe data that the empty swipe row doesn't have. The client hydrates translation/sprites/choices from the message-row mirror, so the stale data displays and persists. **Suggested fix** Invert `clearedExtra`: build it by copying **only** the genuine message-level fields that must survive a swipe (e.g. `hiddenFromAI`, `hiddenFromUser`, `reactions`, `isConversationStart`, persona/command flags) and start everything else empty — matching the `{}` written to the new swipe row at line 1042. That clears `translation`, `translationHidden`, `spriteExpressions`, `cyoaChoices`, `geminiParts`, `tokenCount`, etc. in one place. Additionally add `else extraUpdate.geminiParts = null;` at `generate.routes.ts:7013` to mirror the other reasoning fields. --- *AI-investigated against v2.0.6; clearedExtra and the geminiParts else-branch read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in staging: new regenerated swipes start with fresh message metadata and clear provider/Gemini/per-swipe fields so prior translation/sprite/choices/token data does not leak. Validated with pnpm check and pnpm regression:prompt.

<!-- gh-comment-id:4830955821 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in staging: new regenerated swipes start with fresh message metadata and clear provider/Gemini/per-swipe fields so prior translation/sprite/choices/token data does not leak. Validated with pnpm check and pnpm regression:prompt.
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#1535
No description provided.