[GH-ISSUE #3120] [Issue]: Manual Game background generation skips the prompt-review setting and reuses the same image across locations #1672

Closed
opened 2026-10-21 05:41:34 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

The manual "generate background" button in Game mode behaves differently from the automatic Illustrator, in two visible ways:

  1. It ignores the "review prompts before image generation" setting. With that setting on, the automatic Illustrator shows you the image prompt to review/edit before generating — but the manual background button just fires immediately, no review.
  2. It reuses the same image for different locations. Generate a background at location A, move to location B and generate again, and you get the identical image; move to location C and generate, identical again.

Both come from one root cause: the manual button uses a separate code path (/backgrounds/generate-scene → generateChatBackground) instead of the Illustrator's path (/game/generate-assets → generateBackground), and that separate path has neither the prompt-review gate nor per-location cache keying.

How to reproduce (try it yourself)

Review-bypass:

  1. Settings → enable "Review prompts before image generation" (reviewImagePromptsBeforeSend).
  2. In a Game-mode chat, let the Illustrator auto-generate once → you get the prompt-review modal (correct).
  3. Now click the manual "generate background" button (Gallery / scene background).
    You'll see: it generates immediately with no review modal.
    Expected: the manual button shows the same prompt-review modal the Illustrator does.

Image reuse:

  1. In a Game-mode chat, manually generate a background.
  2. Progress the story to a clearly different location and manually generate again.
  3. Repeat once more.
    You'll see: the same image is returned for each location (especially when the GM hasn't emitted a fresh [state: location: ...] for the new place).
    Expected: each manual generation produces a new background for the current scene.

Where it is

  • Manual handler: packages/client/src/components/game/GameSurface.tsx handleManualSceneBackground (line 4770) POSTs /backgrounds/generate-scene (4801) with locationSlug: gameSnapshot?.location || chat.name (4804). It never references reviewImagePromptsBeforeSend. (The roleplay manual button handleGenerateRoleplayBackground, ChatArea.tsx:914, hits the same endpoint and has the same bypass.)
  • Server route: packages/server/src/routes/backgrounds.routes.ts /generate-scene (~241-316) calls generateChatBackground (~277) with no preview/confirmation step.
  • Cache reuse: packages/server/src/services/game/game-asset-generation.ts generateChatBackground (885): baseSlug = safeGeneratedAssetSlug(req.locationSlug || …) (886), slug = generated-${baseSlug} (889), then const existingPath = existingGeneratedBackgroundPath(...) (892) and if (existingPath) return basename(existingPath); (893) — an unconditional cache hit with no force flag and no per-request uniqueness. GameState.location is string | null (packages/shared/src/types/game-state.ts:18), so when it's empty the client's locationSlug falls back to chat.name — constant for the whole chat — and every manual generation resolves to slug generated-<chat-name> and returns the first image.
  • For contrast, the automatic Illustrator path (runGameAssetGeneration in GameSurface.tsx:4424, gated at ~4438 on reviewImagePromptsBeforeSend and opening GameImagePromptReviewModal) keys its background by the per-scene backgroundTag (game.routes.ts ~8226), so it both reviews and varies per location — which is why the user sees correct behavior there.

What's happening

The manual button was wired to a standalone background endpoint that predates / sits outside the Illustrator's review + per-location-keying logic. So it skips the review modal, and its cache key is too coarse (location-or-chat-name) with an unconditional early-return, so distinct locations collide onto one cached file.

Suggested fix

Cleanest: route the manual background button through runGameAssetGeneration (the Illustrator path) so it inherits both the prompt-review gate and per-location keying. If keeping the standalone /generate-scene endpoint:

  • Review: in handleManualSceneBackground, gate on useUIStore.getState().reviewImagePromptsBeforeSend and, when on, fetch a prompt preview and open GameImagePromptReviewModal before POSTing (add a /generate-scene/preview companion, or accept a promptOverride — the route already imports buildBackgroundProviderPrompt).
  • Reuse: add a force flag to ChatBackgroundGenRequest, plumb it from the manual path, and skip the line 892-893 early-return for user-initiated generations; and/or make the slug unique per scene (include weather/time or a short hash / Date.now() suffix like generateSceneIllustration already does), and stop falling back to the bare chat.name in GameSurface.tsx:4804.

AI-investigated against the current tree (v2.0.9); manual handler + cache lookup lines read and confirmed. Reported on v2.0.8. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 30, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3120 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The **manual** "generate background" button in Game mode behaves differently from the automatic Illustrator, in two visible ways: 1. **It ignores the "review prompts before image generation" setting.** With that setting on, the automatic Illustrator shows you the image prompt to review/edit before generating — but the manual background button just fires immediately, no review. 2. **It reuses the same image for different locations.** Generate a background at location A, move to location B and generate again, and you get the *identical* image; move to location C and generate, identical again. Both come from one root cause: the manual button uses a **separate** code path (`/backgrounds/generate-scene` → `generateChatBackground`) instead of the Illustrator's path (`/game/generate-assets` → `generateBackground`), and that separate path has neither the prompt-review gate nor per-location cache keying. **How to reproduce (try it yourself)** Review-bypass: 1. Settings → enable "Review prompts before image generation" (`reviewImagePromptsBeforeSend`). 2. In a Game-mode chat, let the Illustrator auto-generate once → you get the prompt-review modal (correct). 3. Now click the manual "generate background" button (Gallery / scene background). **You'll see:** it generates immediately with no review modal. **Expected:** the manual button shows the same prompt-review modal the Illustrator does. Image reuse: 1. In a Game-mode chat, manually generate a background. 2. Progress the story to a clearly different location and manually generate again. 3. Repeat once more. **You'll see:** the same image is returned for each location (especially when the GM hasn't emitted a fresh `[state: location: ...]` for the new place). **Expected:** each manual generation produces a new background for the current scene. **Where it is** - Manual handler: `packages/client/src/components/game/GameSurface.tsx` `handleManualSceneBackground` (line 4770) POSTs `/backgrounds/generate-scene` (4801) with `locationSlug: gameSnapshot?.location || chat.name` (4804). It never references `reviewImagePromptsBeforeSend`. (The roleplay manual button `handleGenerateRoleplayBackground`, `ChatArea.tsx:914`, hits the same endpoint and has the same bypass.) - Server route: `packages/server/src/routes/backgrounds.routes.ts` `/generate-scene` (~241-316) calls `generateChatBackground` (~277) with no preview/confirmation step. - Cache reuse: `packages/server/src/services/game/game-asset-generation.ts` `generateChatBackground` (885): `baseSlug = safeGeneratedAssetSlug(req.locationSlug || …)` (886), `slug = generated-${baseSlug}` (889), then `const existingPath = existingGeneratedBackgroundPath(...)` (892) and `if (existingPath) return basename(existingPath);` (893) — an **unconditional** cache hit with **no `force` flag** and no per-request uniqueness. `GameState.location` is `string | null` (`packages/shared/src/types/game-state.ts:18`), so when it's empty the client's `locationSlug` falls back to `chat.name` — constant for the whole chat — and every manual generation resolves to slug `generated-<chat-name>` and returns the first image. - For contrast, the automatic Illustrator path (`runGameAssetGeneration` in `GameSurface.tsx:4424`, gated at ~4438 on `reviewImagePromptsBeforeSend` and opening `GameImagePromptReviewModal`) keys its background by the per-scene `backgroundTag` (`game.routes.ts` ~8226), so it both reviews and varies per location — which is why the user sees correct behavior there. **What's happening** The manual button was wired to a standalone background endpoint that predates / sits outside the Illustrator's review + per-location-keying logic. So it skips the review modal, and its cache key is too coarse (location-or-chat-name) with an unconditional early-return, so distinct locations collide onto one cached file. **Suggested fix** Cleanest: route the manual background button through `runGameAssetGeneration` (the Illustrator path) so it inherits both the prompt-review gate and per-location keying. If keeping the standalone `/generate-scene` endpoint: - **Review:** in `handleManualSceneBackground`, gate on `useUIStore.getState().reviewImagePromptsBeforeSend` and, when on, fetch a prompt preview and open `GameImagePromptReviewModal` before POSTing (add a `/generate-scene/preview` companion, or accept a `promptOverride` — the route already imports `buildBackgroundProviderPrompt`). - **Reuse:** add a `force` flag to `ChatBackgroundGenRequest`, plumb it from the manual path, and skip the line 892-893 early-return for user-initiated generations; and/or make the slug unique per scene (include weather/time or a short hash / `Date.now()` suffix like `generateSceneIllustration` already does), and stop falling back to the bare `chat.name` in `GameSurface.tsx:4804`. --- *AI-investigated against the current tree (v2.0.9); manual handler + cache lookup lines read and confirmed. Reported on v2.0.8. Please verify before fixing.*
bsakaguchi 2026-10-21 05:41:34 +07:00
  • closed this issue
  • added the
    in-pr
    label
Author
Owner

@SpicyMarinara commented on GitHub (Jul 2, 2026):

Codex is taking this in branch codex/issue-sweep-3119-3135 for a staging-targeted fix sweep.

<!-- gh-comment-id:4864514419 --> @SpicyMarinara commented on GitHub (Jul 2, 2026): Codex is taking this in branch codex/issue-sweep-3119-3135 for a staging-targeted fix sweep.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 2, 2026):

Fix is ready in PR #3138 with CI passing. This issue will close automatically when the PR merges into staging.

<!-- gh-comment-id:4864746647 --> @SpicyMarinara commented on GitHub (Jul 2, 2026): Fix is ready in PR #3138 with CI passing. This issue will close automatically when the PR merges into staging.
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#1672
No description provided.