[GH-ISSUE #2989] [Issue]: Retry persona resolution falls back to the globally-active persona in game mode, mismatching the original generation #1564

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

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
The retry-agents route resolves persona by falling back to whatever persona is globally active when the chat has no persona set — even in game mode. The main generate route deliberately suppresses this fallback for game mode ("persona must be explicitly selected in the setup wizard"). So a game-mode chat with no chat.personaId but some unrelated globally-active persona will, on agent retry, inject that wrong persona into agent context (persona block, illustrator references, sprite/expression targeting, persona sprite persistence) — a persona that was never part of the original game generation.

How to reproduce (try it yourself)

  1. Create a game-mode chat where chat.personaId is null/unset (no persona selected in the setup wizard).
  2. Separately have any persona marked isActive === "true" globally.
  3. Generate a message normally — the main route uses NO persona (personaName stays "User").
  4. Retry/regenerate agents on that message (POST /retry-agents) including illustrator, expression, or world-state.

You'll see: the retry injects the globally-active persona — a non-"User" persona block, that personaId targeted for sprite expressions, and it passed to the illustrator references.
Expected: no persona is used on retry (matching the original game generation), exactly as the main route does.

Where it is
packages/server/src/routes/generate/retry-agents-route.ts:441-443 (resolvePersonaContext, called at line 549; consumed at 665-677, 689-691, 700, 776-803). Canonical contrast: packages/server/src/routes/generate.routes.ts:1767-1769.

What's happening
resolvePersonaContext omits the chatMode !== "game" guard the main route applies. It mirrors only the first half of the main route's resolution (prefer chat.personaId) but not the game-mode fallback suppression.

Suggested fix
Gate the active-persona fallback on game mode inside resolvePersonaContext, deriving chatMode from the chat argument the function already receives. Replace lines 441-443:

  const chatMode = ((chat as { mode?: ChatMode }).mode ?? "conversation") as ChatMode;
  const persona =
    (chat.personaId ? allPersonas.find((p: any) => p.id === chat.personaId) : null) ??
    (chatMode !== "game" ? allPersonas.find((p: any) => p.isActive === "true") : null);

The function signature and single call site are untouched. No regression: for conversation/roleplay/visual_novel the guard is always true so the happy path is unchanged; for game mode with chat.personaId set, the first branch resolves before the guard. (Note: the dry-run preview route at dry-run-route.ts:768-770 has the identical missing guard — separate read-only path, worth a follow-up but out of scope here.)


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2989 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The retry-agents route resolves persona by falling back to whatever persona is globally active when the chat has no persona set — even in game mode. The main generate route deliberately suppresses this fallback for game mode ("persona must be explicitly selected in the setup wizard"). So a game-mode chat with no chat.personaId but some unrelated globally-active persona will, on agent retry, inject that wrong persona into agent context (persona block, illustrator references, sprite/expression targeting, persona sprite persistence) — a persona that was never part of the original game generation. **How to reproduce (try it yourself)** 1. Create a game-mode chat where chat.personaId is null/unset (no persona selected in the setup wizard). 2. Separately have any persona marked isActive === "true" globally. 3. Generate a message normally — the main route uses NO persona (personaName stays "User"). 4. Retry/regenerate agents on that message (POST /retry-agents) including illustrator, expression, or world-state. You'll see: the retry injects the globally-active persona — a non-"User" persona block, that personaId targeted for sprite expressions, and it passed to the illustrator references. Expected: no persona is used on retry (matching the original game generation), exactly as the main route does. **Where it is** `packages/server/src/routes/generate/retry-agents-route.ts:441-443` (`resolvePersonaContext`, called at line 549; consumed at 665-677, 689-691, 700, 776-803). Canonical contrast: `packages/server/src/routes/generate.routes.ts:1767-1769`. **What's happening** `resolvePersonaContext` omits the `chatMode !== "game"` guard the main route applies. It mirrors only the first half of the main route's resolution (prefer chat.personaId) but not the game-mode fallback suppression. **Suggested fix** Gate the active-persona fallback on game mode inside `resolvePersonaContext`, deriving chatMode from the `chat` argument the function already receives. Replace lines 441-443: ```ts const chatMode = ((chat as { mode?: ChatMode }).mode ?? "conversation") as ChatMode; const persona = (chat.personaId ? allPersonas.find((p: any) => p.id === chat.personaId) : null) ?? (chatMode !== "game" ? allPersonas.find((p: any) => p.isActive === "true") : null); ``` The function signature and single call site are untouched. No regression: for conversation/roleplay/visual_novel the guard is always true so the happy path is unchanged; for game mode with chat.personaId set, the first branch resolves before the guard. (Note: the dry-run preview route at dry-run-route.ts:768-770 has the identical missing guard — separate read-only path, worth a follow-up but out of scope here.) --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

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

Fixed in merged staging PR #3004.

<!-- gh-comment-id:4832280141 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in merged staging PR #3004.
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#1564
No description provided.