[GH-ISSUE #3452] [Issue]: Game-mode chats with no persona leak the globally active persona into combat, scenes, snapshots, and exports #1866

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

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

Originally assigned to: @kolacheee on GitHub.

Summary

Game Mode chats created without a persona (chat.personaId = null — a designed state: persona selection is optional in the setup wizard, and game.routes.ts explicitly stores "null = no persona") still leak the globally active persona into several server paths: combat encounter prompts, scene planning prompts, per-message personaSnapshot stamps, transcript exports, and memory-recall labels. The main GM generation and the client display both correctly treat these chats as persona-less, so the model receives persona data in some generations that the user never selected and the screen never shows.

Expected behavior

A Game Mode chat with personaId = null uses no persona anywhere. That is the documented convention:

  • packages/server/src/routes/generate.routes.ts:1101-1103 — main generation skips the active-persona fallback in game mode, with the comment "Game mode skips the fallback — persona must be explicitly selected in the setup wizard".
  • packages/server/src/routes/generate/retry-agents-route.ts:484 — same guard (added for #2989).
  • packages/server/src/routes/lorebooks.routes.ts:845-854 — same guard.
  • packages/server/src/routes/game.routes.ts:5896-5902 — game creation comment: "Use only the persona explicitly selected in the wizard (null = no persona)".
  • Client: packages/client/src/components/chat/ChatArea.tsx:982-984 skips the fallback in game mode; packages/client/src/components/game/GameSurface.tsx:7066-7075 shows a default "Player" entry when no persona is selected.

Actual behavior

Live-verified on staging @ 7bb4ab66f (v2.1.2) with a game chat where personaId = null, one character in the party, and an unrelated persona ("Astra Vex", with marker strings in its description/personality) marked globally active:

  1. Combat encounters inject the full active persona. POST /api/encounter/init sent my mock LLM a prompt containing <persona>\nName: Astra Vex\nASTRA_PERSONA_MARKER: ...\nASTRA_PERSONALITY_MARKER: ...\n</persona>, and the prompt instructs the model to narrate that persona's actions by name. Cause: packages/server/src/routes/encounter.routes.ts:162-166 (buildPersonaContext falls back to isActive === "true" with no mode guard; used by /init, /action, /summary at lines 571, 666, 764). The persona's configured HP/stats are also surfaced (lines 177-190).
  2. Scene planning uses the active persona. POST /api/scene/plan on the same game chat sent a prompt containing the Astra marker. Cause: packages/server/src/routes/scene.routes.ts:134-144 — this buildPersonaContext never even reads chat.personaId; it always uses the active persona (so it is also wrong for non-game chats with an explicit per-chat persona). Used by /create, /conclude, /plan at lines 299, 394, 764.
  3. User messages are stamped with the wrong personaSnapshot. Both the generation path (packages/server/src/routes/generate.routes.ts:649-654) and the plain message-create route (packages/server/src/routes/chats.routes.ts:335-343 via lines 1601-1607) stamped personaSnapshot: Astra Vex onto user messages in the persona-less game chat. The client mirrors this in its optimistic message (packages/client/src/hooks/use-generate.ts:1090-1094, also unguarded), and packages/client/src/components/chat/ChatMessage.tsx:1471-1478 prefers the snapshot for the displayed user name and {{user}} macro context.
  4. Transcript export resolves {{user}} to the active persona. The sharpest contrast, same chat, same message: the real generation prompt (guarded) rendered {{user}} draws a blade. as "User draws a blade.", while GET /api/chats/:id/export?format=text rendered it as "Astra Vex draws a blade." Cause: packages/server/src/routes/chats.routes.ts:2803-2812 (buildPersonaSnapshotForChat, no mode guard at lines 338-341).
  5. Memory-recall rebuild labels user turns with the active persona's name. packages/server/src/routes/chats.routes.ts:1547-1551 (not live-verified; identical unguarded pattern feeding userName into rebuildMemoryChunks).

Latent (live-verified as not currently user-visible, noted for completeness): the dry-run route (packages/server/src/routes/generate/dry-run-route.ts:713-716, whose comment claims "same strategy as generation"; already flagged as a follow-up in #2989), the peek-prompt route (packages/server/src/routes/chats.routes.ts:2064-2067), and the preset-preview route (packages/server/src/routes/prompts.routes.ts:318-320) all resolve the persona with the unguarded fallback, but the game prompt assembly does not render those variables today — dry-run and peek responses for the game chat contained zero persona markers.

Control check: a roleplay chat with personaId = null correctly received the active persona in its generation prompt — the global fallback itself is intended behavior outside Game Mode; only the missing game guard is the bug.

Steps to reproduce

  1. Create a persona with distinctive text and activate it (POST /api/characters/personas, then PUT /api/characters/personas/:id/activate) — or just have any active persona, as most users do.
  2. Create a game without selecting a persona: in the setup wizard leave the persona step unselected (clicking a selected persona deselects it — GameSetupWizard.tsx:1468), or POST /api/game/create with a setupConfig that omits personaId. The returned session chat has "mode":"game","personaId":null.
  3. Generate a message normally (POST /api/generate) — the outbound prompt contains no persona (correct), and the game UI shows "Player".
  4. POST /api/encounter/init with {"chatId":"<gameChatId>","settings":{"historyDepth":8}} — the outbound prompt contains a <persona> block with the active persona's name, description, personality, and stats.
  5. Add a user message containing {{user}} and GET /api/chats/<gameChatId>/export?format=text — the macro resolves to the active persona's name, unlike the real prompt.
  6. Inspect any user message's extra — personaSnapshot is the active persona.

Environment

  • Marinara Engine version: 2.1.2 (staging @ 7bb4ab66f)
  • Install type: source (pnpm dev, server only, driven via API)
  • OS + version: Windows 11 Pro 10.0.26200
  • Browser or app shell: n/a (API-level reproduction against a local mock OpenAI-compatible endpoint capturing outbound prompts)

Logs, screenshots, or video

Captured outbound combat-init prompt (system message excerpt) for the persona-less game chat:

<persona>
Name: Astra Vex
ASTRA_PERSONA_MARKER: a starship salvage captain with a cybernetic arm.
ASTRA_PERSONALITY_MARKER: reckless and sardonic.
</persona>

Same-chat contrast for the message {{user}} draws a blade.:

main generation prompt (actual model input):  "User draws a blade."
GET /:id/export?format=text:                  "Astra Vex draws a blade."

Captured main-generation prompt for the same chat: zero occurrences of the persona. Stored message extra: personaSnapshot: { name: "Astra Vex", personaId: "0TTEk66_..." }.

Additional context

  • #2989 fixed this exact class for the retry-agents route and explicitly deferred the dry-run occurrence as a follow-up; this issue covers the remaining unguarded sites.
  • PR #514 made encounter's buildPersonaContext prefer chat.personaId, but kept the unguarded active fallback.
  • Suggested fix: apply the same mode !== "game" gate used at generate.routes.ts:1101-1103 to each remaining fallback site (the chat row with mode is already in scope at every one), and make scene.routes.ts's buildPersonaContext additionally prefer the chat-scoped persona like its encounter counterpart already does.
  • I'm working on a PR for this (draft to follow shortly). — @kolacheee

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jul 10, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3452 Originally assigned to: @kolacheee on GitHub. ## Summary Game Mode chats created without a persona (`chat.personaId = null` — a designed state: persona selection is optional in the setup wizard, and `game.routes.ts` explicitly stores "null = no persona") still leak the **globally active persona** into several server paths: combat encounter prompts, scene planning prompts, per-message `personaSnapshot` stamps, transcript exports, and memory-recall labels. The main GM generation and the client display both correctly treat these chats as persona-less, so the model receives persona data in some generations that the user never selected and the screen never shows. ## Expected behavior A Game Mode chat with `personaId = null` uses **no persona anywhere**. That is the documented convention: - `packages/server/src/routes/generate.routes.ts:1101-1103` — main generation skips the active-persona fallback in game mode, with the comment "Game mode skips the fallback — persona must be explicitly selected in the setup wizard". - `packages/server/src/routes/generate/retry-agents-route.ts:484` — same guard (added for #2989). - `packages/server/src/routes/lorebooks.routes.ts:845-854` — same guard. - `packages/server/src/routes/game.routes.ts:5896-5902` — game creation comment: "Use only the persona explicitly selected in the wizard (null = no persona)". - Client: `packages/client/src/components/chat/ChatArea.tsx:982-984` skips the fallback in game mode; `packages/client/src/components/game/GameSurface.tsx:7066-7075` shows a default "Player" entry when no persona is selected. ## Actual behavior Live-verified on staging @ `7bb4ab66f` (v2.1.2) with a game chat where `personaId = null`, one character in the party, and an unrelated persona ("Astra Vex", with marker strings in its description/personality) marked globally active: 1. **Combat encounters inject the full active persona.** `POST /api/encounter/init` sent my mock LLM a prompt containing `<persona>\nName: Astra Vex\nASTRA_PERSONA_MARKER: ...\nASTRA_PERSONALITY_MARKER: ...\n</persona>`, and the prompt instructs the model to narrate that persona's actions by name. Cause: `packages/server/src/routes/encounter.routes.ts:162-166` (`buildPersonaContext` falls back to `isActive === "true"` with no mode guard; used by `/init`, `/action`, `/summary` at lines 571, 666, 764). The persona's configured HP/stats are also surfaced (lines 177-190). 2. **Scene planning uses the active persona.** `POST /api/scene/plan` on the same game chat sent a prompt containing the Astra marker. Cause: `packages/server/src/routes/scene.routes.ts:134-144` — this `buildPersonaContext` never even reads `chat.personaId`; it always uses the active persona (so it is also wrong for non-game chats with an explicit per-chat persona). Used by `/create`, `/conclude`, `/plan` at lines 299, 394, 764. 3. **User messages are stamped with the wrong `personaSnapshot`.** Both the generation path (`packages/server/src/routes/generate.routes.ts:649-654`) and the plain message-create route (`packages/server/src/routes/chats.routes.ts:335-343` via lines 1601-1607) stamped `personaSnapshot: Astra Vex` onto user messages in the persona-less game chat. The client mirrors this in its optimistic message (`packages/client/src/hooks/use-generate.ts:1090-1094`, also unguarded), and `packages/client/src/components/chat/ChatMessage.tsx:1471-1478` prefers the snapshot for the displayed user name and `{{user}}` macro context. 4. **Transcript export resolves `{{user}}` to the active persona.** The sharpest contrast, same chat, same message: the real generation prompt (guarded) rendered `{{user}} draws a blade.` as **"User draws a blade."**, while `GET /api/chats/:id/export?format=text` rendered it as **"Astra Vex draws a blade."** Cause: `packages/server/src/routes/chats.routes.ts:2803-2812` (`buildPersonaSnapshotForChat`, no mode guard at lines 338-341). 5. **Memory-recall rebuild labels user turns with the active persona's name.** `packages/server/src/routes/chats.routes.ts:1547-1551` (not live-verified; identical unguarded pattern feeding `userName` into `rebuildMemoryChunks`). Latent (live-verified as **not** currently user-visible, noted for completeness): the dry-run route (`packages/server/src/routes/generate/dry-run-route.ts:713-716`, whose comment claims "same strategy as generation"; already flagged as a follow-up in #2989), the peek-prompt route (`packages/server/src/routes/chats.routes.ts:2064-2067`), and the preset-preview route (`packages/server/src/routes/prompts.routes.ts:318-320`) all resolve the persona with the unguarded fallback, but the game prompt assembly does not render those variables today — dry-run and peek responses for the game chat contained zero persona markers. Control check: a **roleplay** chat with `personaId = null` correctly received the active persona in its generation prompt — the global fallback itself is intended behavior outside Game Mode; only the missing game guard is the bug. ## Steps to reproduce 1. Create a persona with distinctive text and activate it (`POST /api/characters/personas`, then `PUT /api/characters/personas/:id/activate`) — or just have any active persona, as most users do. 2. Create a game without selecting a persona: in the setup wizard leave the persona step unselected (clicking a selected persona deselects it — `GameSetupWizard.tsx:1468`), or `POST /api/game/create` with a `setupConfig` that omits `personaId`. The returned session chat has `"mode":"game","personaId":null`. 3. Generate a message normally (`POST /api/generate`) — the outbound prompt contains no persona (correct), and the game UI shows "Player". 4. `POST /api/encounter/init` with `{"chatId":"<gameChatId>","settings":{"historyDepth":8}}` — the outbound prompt contains a `<persona>` block with the active persona's name, description, personality, and stats. 5. Add a user message containing `{{user}}` and `GET /api/chats/<gameChatId>/export?format=text` — the macro resolves to the active persona's name, unlike the real prompt. 6. Inspect any user message's `extra` — `personaSnapshot` is the active persona. ## Environment - Marinara Engine version: 2.1.2 (staging @ `7bb4ab66f`) - Install type: source (`pnpm dev`, server only, driven via API) - OS + version: Windows 11 Pro 10.0.26200 - Browser or app shell: n/a (API-level reproduction against a local mock OpenAI-compatible endpoint capturing outbound prompts) ## Logs, screenshots, or video Captured outbound combat-init prompt (system message excerpt) for the persona-less game chat: ``` <persona> Name: Astra Vex ASTRA_PERSONA_MARKER: a starship salvage captain with a cybernetic arm. ASTRA_PERSONALITY_MARKER: reckless and sardonic. </persona> ``` Same-chat contrast for the message `{{user}} draws a blade.`: ``` main generation prompt (actual model input): "User draws a blade." GET /:id/export?format=text: "Astra Vex draws a blade." ``` Captured main-generation prompt for the same chat: zero occurrences of the persona. Stored message extra: `personaSnapshot: { name: "Astra Vex", personaId: "0TTEk66_..." }`. ## Additional context - #2989 fixed this exact class for the retry-agents route and explicitly deferred the dry-run occurrence as a follow-up; this issue covers the remaining unguarded sites. - PR #514 made encounter's `buildPersonaContext` prefer `chat.personaId`, but kept the unguarded active fallback. - Suggested fix: apply the same `mode !== "game"` gate used at `generate.routes.ts:1101-1103` to each remaining fallback site (the chat row with `mode` is already in scope at every one), and make `scene.routes.ts`'s `buildPersonaContext` additionally prefer the chat-scoped persona like its encounter counterpart already does. - I'm working on a PR for this (draft to follow shortly). — @kolacheee ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:43:22 +07:00
  • closed this issue
  • added the
    in-pr
    bug
    labels
Author
Owner

@kolacheee commented on GitHub (Jul 10, 2026):

Draft PR is up: #3454 (fork branch kolacheee:fix/game-persona-fallback-3452, targeting staging). All leak paths from the matrix above re-verified clean after the fix; the roleplay fallback and explicit game-persona paths verified unchanged. — owning this one (@kolacheee)

<!-- gh-comment-id:4940143539 --> @kolacheee commented on GitHub (Jul 10, 2026): Draft PR is up: #3454 (fork branch `kolacheee:fix/game-persona-fallback-3452`, targeting `staging`). All leak paths from the matrix above re-verified clean after the fix; the roleplay fallback and explicit game-persona paths verified unchanged. — owning this one (@kolacheee)
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#1866
No description provided.