[PR #3454] [MERGED] Skip active-persona fallback for persona-less game chats #5947

Closed
opened 2026-10-23 04:05:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3454
Author: @kolacheee
Created: 7/10/2026
Status: ✅ Merged
Merged: 7/11/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/game-persona-fallback-3452


📝 Commits (3)

  • 0ca71cf Skip active-persona fallback for persona-less game chats
  • 76ac1e8 Merge branch 'staging' into fix/game-persona-fallback-3452
  • 6991675 Centralize game-aware persona selection

📊 Changes

8 files changed (+83 additions, -43 deletions)

View changed files

📝 packages/client/src/hooks/use-generate.ts (+4 -1)
📝 packages/server/src/routes/chats.routes.ts (+10 -10)
📝 packages/server/src/routes/encounter.routes.ts (+14 -7)
📝 packages/server/src/routes/generate.routes.ts (+4 -6)
📝 packages/server/src/routes/generate/dry-run-route.ts (+2 -3)
📝 packages/server/src/routes/generate/generate-route-utils.ts (+18 -0)
📝 packages/server/src/routes/prompts.routes.ts (+2 -3)
📝 packages/server/src/routes/scene.routes.ts (+29 -13)

📄 Description

Linked issue

Closes #3452

Why this change

A Game Mode chat created without a persona (chat.personaId = null — a designed state: persona selection is optional in the setup wizard, and game creation stores "null = no persona") was still leaking the globally active persona into several generation and serialization paths. The main GM generation and the client display both already treat these chats as persona-less, so the model was receiving persona data in combat and scene prompts that the user never selected and the screen never shows, exported transcripts resolved {{user}} to the wrong name, and user messages were stamped with a personaSnapshot of a persona that was never part of the chat. Full analysis and a live reproduction matrix are in #3452.

This PR applies the same mode !== "game" gate that the main generation path already uses (generate.routes.ts — "Game mode skips the fallback — persona must be explicitly selected in the setup wizard", and retry-agents-route.ts since #2989) to the remaining unguarded active-persona fallbacks. Outside Game Mode the fallback behavior is unchanged, and a game with an explicitly selected persona is unaffected (the chat-scoped persona resolves before the guard is consulted).

What changed

  • packages/server/src/routes/chats.routes.ts
    • buildPersonaSnapshotForChat (feeds personaSnapshot stamping on user messages and {{user}}/persona macro context in transcript exports) now skips the active-persona fallback for game chats.
    • Memory-recall rebuild (/:id/memories/rebuild path) no longer labels user turns with the active persona's name in persona-less game chats.
    • /:id/peek-prompt persona resolution gets the same guard (latent today — the game prompt assembly doesn't render it — but now matches generation).
  • packages/server/src/routes/generate.routes.ts — the per-message personaSnapshot stamped during generation uses the same game-mode guard as the prompt's own persona resolution a few lines below.
  • packages/server/src/routes/generate/dry-run-route.ts — the dry-run persona resolution now actually matches its "same strategy as generation" comment (follow-up explicitly deferred in #2989).
  • packages/server/src/routes/encounter.routes.ts — buildPersonaContext takes the chat mode and skips the fallback for game chats; all three call sites (/init, /action, /summary) pass chat.mode. A persona-less game now gets "No persona information available." in the <persona> block instead of the active persona's card and stats.
  • packages/server/src/routes/scene.routes.ts — buildPersonaContext now prefers the chat-scoped persona before the active-persona fallback (matching the resolution order everywhere else; previously it only ever used the active persona, which was also wrong for non-game chats with an explicit per-chat persona) and skips the fallback for game chats. /create and /plan pass the origin chat's persona/mode; /conclude passes the scene chat's inherited persona with the origin chat's mode (scene chats are always roleplay, so the game guard must come from the origin). The origin fetch added for /conclude is deliberately separate from the pre-existing step-4 fetch — that one re-reads the origin after the LLM call so the metadata write doesn't clobber concurrent updates.
  • packages/client/src/hooks/use-generate.ts — the optimistic message's personaSnapshot mirrors the server-side guard, so the optimistic render matches what the server persists.

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

What I verified live (dev server on Windows, all LLM traffic routed through a local mock OpenAI-compatible endpoint that records every outbound prompt; game chat created via POST /api/game/create with no setupConfig.personaId, persona "Astra Vex" globally active, marker strings in its card):

  • Before the fix, on the persona-less game chat: POST /api/encounter/init sent a full <persona> block for Astra Vex; POST /api/scene/plan leaked the persona; new user messages were stamped personaSnapshot: Astra Vex; GET /:id/export?format=text rendered {{user}} as "Astra Vex" while the actual generation prompt rendered the same message as "User".
  • After the fix, same chat: encounter prompt contains <persona>\nNo persona information available.\n</persona> (zero marker hits); scene plan prompt has zero marker hits; newly created user messages carry no personaSnapshot; export renders {{user}} as "User" (including for messages stamped before the fix, since export resolves at serialization time).
  • Regression checks, after the fix: a roleplay chat with personaId = null still receives the active persona in its outbound generation prompt (the intended global fallback is untouched); a game chat with an explicitly selected persona still gets that persona's full <persona> block in the combat prompt.
  • pnpm check (typecheck + lint + build) run locally — result noted in the PR conversation.
  • Manually verified in the app that a persona-less game's combat and side-scene flows read correctly with the "No persona information available." context (prompts remain coherent).
  • Manually verified user-message rendering in a persona-less game chat after this change (messages should show the default "Player"/"You" naming, not the active persona's name/colors).
  • Manually verified a normal roleplay/conversation chat still shows the active persona's name and colors on new user messages.

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)

No docs or release-file changes are included; this is a behavior fix with no configuration surface.

UI evidence (if applicable)

No visual changes beyond user-message naming in persona-less game chats (server-side prompt/serialization fix); before/after prompt captures are quoted in #3452.

Summary by CodeRabbit

  • Bug Fixes
    • Improved persona handling in game mode across generation, previews, scenes, and encounters.
    • Game chats now use only an explicitly selected persona; otherwise, no persona is assigned.
    • Non-game chats continue to use the active persona when no specific persona is selected.
    • Ensured persona context remains consistent throughout encounter and scene workflows.

🔄 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/3454 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 7/10/2026 **Status:** ✅ Merged **Merged:** 7/11/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/game-persona-fallback-3452` --- ### 📝 Commits (3) - [`0ca71cf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0ca71cf7310d28f73f48c3e51c3b778ec1a2c5bb) Skip active-persona fallback for persona-less game chats - [`76ac1e8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/76ac1e8ece57411f4983b18f344bdf4b26e727b7) Merge branch 'staging' into fix/game-persona-fallback-3452 - [`6991675`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6991675fdbe4b2465a48d784b532d9e16e2f47cb) Centralize game-aware persona selection ### 📊 Changes **8 files changed** (+83 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/hooks/use-generate.ts` (+4 -1) 📝 `packages/server/src/routes/chats.routes.ts` (+10 -10) 📝 `packages/server/src/routes/encounter.routes.ts` (+14 -7) 📝 `packages/server/src/routes/generate.routes.ts` (+4 -6) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+2 -3) 📝 `packages/server/src/routes/generate/generate-route-utils.ts` (+18 -0) 📝 `packages/server/src/routes/prompts.routes.ts` (+2 -3) 📝 `packages/server/src/routes/scene.routes.ts` (+29 -13) </details> ### 📄 Description ## Linked issue Closes #3452 ## Why this change A Game Mode chat created without a persona (`chat.personaId = null` — a designed state: persona selection is optional in the setup wizard, and game creation stores "null = no persona") was still leaking the **globally active persona** into several generation and serialization paths. The main GM generation and the client display both already treat these chats as persona-less, so the model was receiving persona data in combat and scene prompts that the user never selected and the screen never shows, exported transcripts resolved `{{user}}` to the wrong name, and user messages were stamped with a `personaSnapshot` of a persona that was never part of the chat. Full analysis and a live reproduction matrix are in #3452. This PR applies the same `mode !== "game"` gate that the main generation path already uses (`generate.routes.ts` — "Game mode skips the fallback — persona must be explicitly selected in the setup wizard", and `retry-agents-route.ts` since #2989) to the remaining unguarded active-persona fallbacks. Outside Game Mode the fallback behavior is unchanged, and a game with an explicitly selected persona is unaffected (the chat-scoped persona resolves before the guard is consulted). ## What changed - `packages/server/src/routes/chats.routes.ts` - `buildPersonaSnapshotForChat` (feeds `personaSnapshot` stamping on user messages and `{{user}}`/persona macro context in transcript exports) now skips the active-persona fallback for game chats. - Memory-recall rebuild (`/:id/memories/rebuild` path) no longer labels user turns with the active persona's name in persona-less game chats. - `/:id/peek-prompt` persona resolution gets the same guard (latent today — the game prompt assembly doesn't render it — but now matches generation). - `packages/server/src/routes/generate.routes.ts` — the per-message `personaSnapshot` stamped during generation uses the same game-mode guard as the prompt's own persona resolution a few lines below. - `packages/server/src/routes/generate/dry-run-route.ts` — the dry-run persona resolution now actually matches its "same strategy as generation" comment (follow-up explicitly deferred in #2989). - `packages/server/src/routes/encounter.routes.ts` — `buildPersonaContext` takes the chat mode and skips the fallback for game chats; all three call sites (`/init`, `/action`, `/summary`) pass `chat.mode`. A persona-less game now gets "No persona information available." in the `<persona>` block instead of the active persona's card and stats. - `packages/server/src/routes/scene.routes.ts` — `buildPersonaContext` now prefers the chat-scoped persona before the active-persona fallback (matching the resolution order everywhere else; previously it *only* ever used the active persona, which was also wrong for non-game chats with an explicit per-chat persona) and skips the fallback for game chats. `/create` and `/plan` pass the origin chat's persona/mode; `/conclude` passes the scene chat's inherited persona with the origin chat's mode (scene chats are always `roleplay`, so the game guard must come from the origin). The origin fetch added for `/conclude` is deliberately separate from the pre-existing step-4 fetch — that one re-reads the origin *after* the LLM call so the metadata write doesn't clobber concurrent updates. - `packages/client/src/hooks/use-generate.ts` — the optimistic message's `personaSnapshot` mirrors the server-side guard, so the optimistic render matches what the server persists. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes What I verified live (dev server on Windows, all LLM traffic routed through a local mock OpenAI-compatible endpoint that records every outbound prompt; game chat created via `POST /api/game/create` with no `setupConfig.personaId`, persona "Astra Vex" globally active, marker strings in its card): - Before the fix, on the persona-less game chat: `POST /api/encounter/init` sent a full `<persona>` block for Astra Vex; `POST /api/scene/plan` leaked the persona; new user messages were stamped `personaSnapshot: Astra Vex`; `GET /:id/export?format=text` rendered `{{user}}` as "Astra Vex" while the actual generation prompt rendered the same message as "User". - After the fix, same chat: encounter prompt contains `<persona>\nNo persona information available.\n</persona>` (zero marker hits); scene plan prompt has zero marker hits; newly created user messages carry no `personaSnapshot`; export renders `{{user}}` as "User" (including for messages stamped before the fix, since export resolves at serialization time). - Regression checks, after the fix: a **roleplay** chat with `personaId = null` still receives the active persona in its outbound generation prompt (the intended global fallback is untouched); a **game chat with an explicitly selected persona** still gets that persona's full `<persona>` block in the combat prompt. - `pnpm check` (typecheck + lint + build) run locally — result noted in the PR conversation. - Manually verified in the app that a persona-less game's combat and side-scene flows read correctly with the "No persona information available." context (prompts remain coherent). - Manually verified user-message rendering in a persona-less game chat after this change (messages should show the default "Player"/"You" naming, not the active persona's name/colors). - Manually verified a normal roleplay/conversation chat still shows the active persona's name and colors on new user messages. ## Docs and release impact - [x] 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) No docs or release-file changes are included; this is a behavior fix with no configuration surface. ## UI evidence (if applicable) No visual changes beyond user-message naming in persona-less game chats (server-side prompt/serialization fix); before/after prompt captures are quoted in #3452. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved persona handling in game mode across generation, previews, scenes, and encounters. * Game chats now use only an explicitly selected persona; otherwise, no persona is assigned. * Non-game chats continue to use the active persona when no specific persona is selected. * Ensured persona context remains consistent throughout encounter and scene workflows. <!-- 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-23 04:05:28 +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#5947
No description provided.