[PR #679] [MERGED] fix(game-setup): recover HUD widgets through schema slips and mount prep modal on Start Game #4728

Closed
opened 2026-10-22 04:10:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/679
Author: @Romuromylus
Created: 5/11/2026
Status: ✅ Merged
Merged: 5/11/2026
Merged by: @Romuromylus

Base: main ← Head: fix/hud-widget-setup-recovery


📝 Commits (2)

  • 3b3b79d fix(game-setup): recover HUD widgets through schema slips and mount prep modal on Start Game
  • 891b9da fix(gm-prompts): disambiguate pressureClock current bound wording

📊 Changes

3 files changed (+77 additions, -28 deletions)

View changed files

📝 packages/client/src/components/game/GameSurface.tsx (+14 -0)
📝 packages/server/src/routes/game.routes.ts (+61 -27)
📝 packages/server/src/services/game/gm-prompts.ts (+2 -1)

📄 Description

Linked issue

Closes #664

Why this change

Setting up a Game Mode game with Custom HUD Widgets enabled has two related failure modes (originally reported on Discord by jasonwocky):

  • When the generated setup blueprint violates the Zod schema (typically too many pressureClocks / factions / questSeeds / encounterPrinciples, or a pressureClock.steps value above 12), blueprintSchema.safeParse() rejects the whole payload and the if (parsed.success) branch is a no-op — so updates.gameBlueprint never gets persisted and the user's HUD widgets vanish without any log line or UI feedback.
  • When the blueprint does satisfy the schema, the Start Game button on the "ready" screen appears to do nothing: handleStartGameRequest sets prepareInitialWidgetsOpen=true to open GameWidgetSessionPrepModal, but the modal element is only rendered inside the main game-surface return — the sessionStatus === "ready" && !introPresented early-return branch (the Start Game screen itself) never mounts it, so the state flip goes nowhere visible.

What changed

  • packages/server/src/routes/game.routes.ts — wrapped the offending campaignPlan fields in z.preprocess(...) to coerce LLM slips into the documented ranges (slice arrays to the max, clamp steps to 1-12 and current to 0-12) instead of rejecting them. Added a logger.warn({ issues }, ...) plus a hudWidgets-only retry parse as a last-ditch recovery so the user keeps their widgets even when the rest of the blueprint is malformed beyond preprocessing.
  • packages/client/src/components/game/GameSurface.tsx — mounted <GameWidgetSessionPrepModal mode="initial"> inside the sessionStatus === "ready" early-return branch with the same props the existing main-return instance uses, so the modal can actually open when handleStartGameRequest flips prepareInitialWidgetsOpen on the Start Game screen.
  • packages/server/src/services/game/gm-prompts.ts — tightened the campaign_structure_rules wording so the LLM is told the hard caps explicitly (max 2 pressureClocks / 2 factions / 3 quest seeds / 2 encounter principles; pressureClock.steps 1-12). Defense in depth: even with the new permissive schema, fewer retries / coercion are needed if the LLM stays in range.

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

  • Manually verify on a fresh Game Mode setup with Custom HUD Widgets enabled and a blueprint that previously violated the schema (e.g. force the LLM to emit 3+ pressureClocks or pressureClock.steps > 12): widgets should now persist and the warn log should appear in server output if anything still slips past preprocessing.
  • Manually verify on a fresh Game Mode setup with a valid blueprint and Custom HUD Widgets enabled: clicking Start Game on the ready screen should now open GameWidgetSessionPrepModal (previously the click was a no-op).
  • Manually verify the existing "next session" prep flow (concluded session -> Start New Session with widgets) still opens its modal — the main-return <GameWidgetSessionPrepModal> instance is untouched, but worth sanity-checking that the two instances don't conflict.

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)

UI evidence (if applicable)

No visual change to the Start Game screen itself — the fix re-enables the existing prep modal that was already styled in the codebase but unreachable from this branch.

Summary by CodeRabbit

  • New Features

    • Added a widget preparation modal that displays on the game start screen before launching your session.
  • Improvements

    • Enhanced game setup data validation to accept more configuration variations by automatically adjusting out-of-range values.
    • Improved recovery process when setup validation encounters issues—now preserves valid game widgets when possible.
    • Refined campaign structure rules with more explicit sizing constraints.

Review Change Stack


🔄 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/679 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/11/2026 **Status:** ✅ Merged **Merged:** 5/11/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/hud-widget-setup-recovery` --- ### 📝 Commits (2) - [`3b3b79d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3b3b79d1e0f42bf68f1f36d612d22ca2b8eb3d38) fix(game-setup): recover HUD widgets through schema slips and mount prep modal on Start Game - [`891b9da`](https://github.com/Pasta-Devs/Marinara-Engine/commit/891b9dae6786cb7e9eeae4d560d9e8d55057bb5c) fix(gm-prompts): disambiguate pressureClock current bound wording ### 📊 Changes **3 files changed** (+77 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/game/GameSurface.tsx` (+14 -0) 📝 `packages/server/src/routes/game.routes.ts` (+61 -27) 📝 `packages/server/src/services/game/gm-prompts.ts` (+2 -1) </details> ### 📄 Description ## Linked issue Closes #664 ## Why this change Setting up a Game Mode game with **Custom HUD Widgets** enabled has two related failure modes (originally reported on Discord by `jasonwocky`): - When the generated setup blueprint violates the Zod schema (typically too many `pressureClocks` / `factions` / `questSeeds` / `encounterPrinciples`, or a `pressureClock.steps` value above 12), `blueprintSchema.safeParse()` rejects the whole payload and the `if (parsed.success)` branch is a no-op — so `updates.gameBlueprint` never gets persisted and the user's HUD widgets vanish without any log line or UI feedback. - When the blueprint *does* satisfy the schema, the Start Game button on the "ready" screen appears to do nothing: `handleStartGameRequest` sets `prepareInitialWidgetsOpen=true` to open `GameWidgetSessionPrepModal`, but the modal element is only rendered inside the main game-surface return — the `sessionStatus === "ready" && !introPresented` early-return branch (the Start Game screen itself) never mounts it, so the state flip goes nowhere visible. ## What changed - `packages/server/src/routes/game.routes.ts` — wrapped the offending `campaignPlan` fields in `z.preprocess(...)` to coerce LLM slips into the documented ranges (slice arrays to the max, clamp `steps` to 1-12 and `current` to 0-12) instead of rejecting them. Added a `logger.warn({ issues }, ...)` plus a hudWidgets-only retry parse as a last-ditch recovery so the user keeps their widgets even when the rest of the blueprint is malformed beyond preprocessing. - `packages/client/src/components/game/GameSurface.tsx` — mounted `<GameWidgetSessionPrepModal mode="initial">` inside the `sessionStatus === "ready"` early-return branch with the same props the existing main-return instance uses, so the modal can actually open when `handleStartGameRequest` flips `prepareInitialWidgetsOpen` on the Start Game screen. - `packages/server/src/services/game/gm-prompts.ts` — tightened the `campaign_structure_rules` wording so the LLM is told the hard caps explicitly (max 2 `pressureClocks` / 2 factions / 3 quest seeds / 2 encounter principles; `pressureClock.steps` 1-12). Defense in depth: even with the new permissive schema, fewer retries / coercion are needed if the LLM stays in range. ## 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 - Manually verify on a fresh Game Mode setup with Custom HUD Widgets enabled and a blueprint that previously violated the schema (e.g. force the LLM to emit 3+ `pressureClocks` or `pressureClock.steps > 12`): widgets should now persist and the warn log should appear in server output if anything still slips past preprocessing. - Manually verify on a fresh Game Mode setup with a valid blueprint and Custom HUD Widgets enabled: clicking **Start Game** on the ready screen should now open `GameWidgetSessionPrepModal` (previously the click was a no-op). - Manually verify the existing "next session" prep flow (concluded session -> Start New Session with widgets) still opens its modal — the main-return `<GameWidgetSessionPrepModal>` instance is untouched, but worth sanity-checking that the two instances don't conflict. ## 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) ## UI evidence (if applicable) No visual change to the Start Game screen itself — the fix re-enables the existing prep modal that was already styled in the codebase but unreachable from this branch. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a widget preparation modal that displays on the game start screen before launching your session. * **Improvements** * Enhanced game setup data validation to accept more configuration variations by automatically adjusting out-of-range values. * Improved recovery process when setup validation encounters issues—now preserves valid game widgets when possible. * Refined campaign structure rules with more explicit sizing constraints. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/679) <!-- 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-22 04:10:09 +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#4728
No description provided.