[GH-ISSUE #2709] [Issue]: Game creation robustness — null startingNpcs 500s with no rollback (stuck setup); createGame failure swallowed silently #1354

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Two robustness gaps make game-creation failures opaque and unrecoverable: a malformed startingNpcs element (e.g. a null array hole) passes validation and then throws a 500 mid-apply with no rollback of the already-created chat (leaving a game stuck in setup); and a /game/create failure is silently swallowed on the client (no toast, no error) so the user sees the button do nothing.

Expected behavior

A bad setup payload should route to the repair modal (or fail cleanly and reset/rollback the chat), and any creation failure should surface a clear error to the user — never a silent no-op or a half-created, stuck game.

Actual behavior

  1. Null-NPC 500, no rollback. validateGameSetupPayload only checks Array.isArray(startingNpcs) && length > 0 — never the element shape. applyGameSetupPayload then does n.name on each element; a [null] (or sparse) array throws TypeError: Cannot read properties of null. The /setup route awaits applyGameSetupPayload with no try/catch, so it 500s (not the 422 repair path). Meanwhile /game/create already persisted the chat with gameSessionStatus:"setup" and never rolls back, so on reload the client re-enters the setup wizard — a half-created game the user can't escape without manual deletion.
  2. Silent create failure. useCreateGame.onError only console.errors (no toast); the wizard's createGame.mutate has an onSuccess chaining gameSetup.mutate but no onError; there's no global MutationCache error handler. So if POST /game/create fails (bad connection, server/validation error), isPending clears and the button reverts to "Start Game" with no feedback — the user perceives the button as broken.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • (1) packages/server/src/routes/game.routes.ts:2445-2454 (validation, no element check); :3062-3077 (map dereferences n.name); :3686-3693 (apply awaited with no try/catch → 500); chat committed setup at :3336, no rollback; client re-enters wizard via use-game.ts:706; 422-repair path only at :3670-3683 (skipped).
  • (2) packages/client/src/hooks/use-game.ts:185-188 (onError console-only); GameSurface.tsx:7937 (createGame.mutate has no onError); main.tsx:13-21 (no MutationCache handler); gameSetup does toast on error (use-game.ts:210-217).

Steps to reproduce

  1. Have the GM return setup JSON where startingNpcs is [null] or [{...}, null] → /setup returns 500, no repair modal, chat stuck in setup.
  2. Make /game/create return a 4xx/5xx → click Start Game → spinner blinks, then the wizard silently returns to idle with no error.

Suggested fix

  • In validateGameSetupPayload, verify every startingNpcs entry is a non-null object with a string name; harden the map (const obj = (n && typeof n==="object") ? n : {}); on bad shape, return the "incomplete — repair the JSON" string so the 422/repair path fires. Wrap applyGameSetupPayload in try/catch that returns 422 (or resets gameSessionStatus) so the chat isn't left half-created.
  • Add an onError toast to the createGame.mutate call (like the startGame handler), or to useCreateGame.onError, or install a global MutationCache.onError in main.tsx.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of Game Mode. Turns recoverable failures into stuck games and silent no-ops — a big chunk of "failed on game creation" reports. Part of a set of game-mode issues filed together.

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 (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2709 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Two robustness gaps make game-creation failures opaque and unrecoverable: a malformed `startingNpcs` element (e.g. a `null` array hole) passes validation and then throws a 500 mid-apply with **no rollback** of the already-created chat (leaving a game stuck in `setup`); and a `/game/create` failure is **silently swallowed** on the client (no toast, no error) so the user sees the button do nothing. ## Expected behavior A bad setup payload should route to the repair modal (or fail cleanly and reset/rollback the chat), and any creation failure should surface a clear error to the user — never a silent no-op or a half-created, stuck game. ## Actual behavior 1. **Null-NPC 500, no rollback.** `validateGameSetupPayload` only checks `Array.isArray(startingNpcs) && length > 0` — never the element shape. `applyGameSetupPayload` then does `n.name` on each element; a `[null]` (or sparse) array throws `TypeError: Cannot read properties of null`. The `/setup` route `await`s `applyGameSetupPayload` with **no try/catch**, so it 500s (not the 422 repair path). Meanwhile `/game/create` already persisted the chat with `gameSessionStatus:"setup"` and never rolls back, so on reload the client re-enters the setup wizard — a half-created game the user can't escape without manual deletion. 2. **Silent create failure.** `useCreateGame.onError` only `console.error`s (no toast); the wizard's `createGame.mutate` has an `onSuccess` chaining `gameSetup.mutate` but **no `onError`**; there's no global `MutationCache` error handler. So if `POST /game/create` fails (bad connection, server/validation error), `isPending` clears and the button reverts to "Start Game" with no feedback — the user perceives the button as broken. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - (1) `packages/server/src/routes/game.routes.ts:2445-2454` (validation, no element check); `:3062-3077` (map dereferences `n.name`); `:3686-3693` (apply `await`ed with no try/catch → 500); chat committed `setup` at `:3336`, no rollback; client re-enters wizard via `use-game.ts:706`; 422-repair path only at `:3670-3683` (skipped). - (2) `packages/client/src/hooks/use-game.ts:185-188` (`onError` console-only); `GameSurface.tsx:7937` (`createGame.mutate` has no `onError`); `main.tsx:13-21` (no `MutationCache` handler); `gameSetup` does toast on error (`use-game.ts:210-217`). ## Steps to reproduce 1. Have the GM return setup JSON where `startingNpcs` is `[null]` or `[{...}, null]` → `/setup` returns 500, no repair modal, chat stuck in `setup`. 2. Make `/game/create` return a 4xx/5xx → click Start Game → spinner blinks, then the wizard silently returns to idle with no error. ## Suggested fix - In `validateGameSetupPayload`, verify every `startingNpcs` entry is a non-null object with a string name; harden the map (`const obj = (n && typeof n==="object") ? n : {}`); on bad shape, return the "incomplete — repair the JSON" string so the 422/repair path fires. Wrap `applyGameSetupPayload` in try/catch that returns 422 (or resets `gameSessionStatus`) so the chat isn't left half-created. - Add an `onError` toast to the `createGame.mutate` call (like the startGame handler), or to `useCreateGame.onError`, or install a global `MutationCache.onError` in `main.tsx`. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of Game Mode. Turns recoverable failures into stuck games and silent no-ops — a big chunk of "failed on game creation" reports. Part of a set of game-mode issues filed together. ## 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.
Author
Owner

@kolacheee commented on GitHub (Jun 21, 2026):

Veracity self-review — correction / clarification
Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it.

Two clarifications for fixers (core defect, trace, and primary fix are all confirmed present in the current tree):

  1. Scope — there is a SECOND unguarded apply call site the trace omits. The "How it breaks the pipeline" trace cites only the /setup route (line ~3687) for the unguarded await applyGameSetupPayload(...). The identical pattern — await applyGameSetupPayload(...) with no try/catch, immediately after validateGameSetupPayload(...) — also exists in the /setup/apply-json repair-apply route (validate at ~3726, apply at ~3743). This is the post-repair path: if a user edits the JSON in the repair modal but leaves a bad-shape entry (e.g. startingNpcs still [null]), it passes validation and 500s at the same n.name deref, just at the apply-json call site. Note the primary fix (the validateGameSetupPayload element-shape check) already covers BOTH routes automatically because both validate before applying — so the [null] case is fixed on both paths with that single change. But the secondary suggestion ("wrap applyGameSetupPayload in try/catch") must be applied to BOTH sites (~3687 in /setup AND ~3743 in /setup/apply-json), not just /setup, so a genuine apply-time throw (e.g. a DB write failure) never escapes as a raw 500 on either path.

  2. UX precision — the stuck game is escapable, just not cleanly recoverable. The re-entered setup wizard's onCancel handler (GameSurface.tsx ~7964-7971) calls deleteChat.mutate(activeChatId) when sessionStatus === "setup", so the user is not literally trapped "without manual deletion" — they can hit Cancel, which discards the half-created game (and loses all setup progress). The real defect is that the only recovery is abandon-and-restart with no clean repair path, not that the chat is unremovable.

<!-- gh-comment-id:4761102580 --> @kolacheee commented on GitHub (Jun 21, 2026): > **Veracity self-review — correction / clarification** > _Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it._ Two clarifications for fixers (core defect, trace, and primary fix are all confirmed present in the current tree): 1) Scope — there is a SECOND unguarded apply call site the trace omits. The "How it breaks the pipeline" trace cites only the /setup route (line ~3687) for the unguarded `await applyGameSetupPayload(...)`. The identical pattern — `await applyGameSetupPayload(...)` with no try/catch, immediately after `validateGameSetupPayload(...)` — also exists in the /setup/apply-json repair-apply route (validate at ~3726, apply at ~3743). This is the post-repair path: if a user edits the JSON in the repair modal but leaves a bad-shape entry (e.g. startingNpcs still `[null]`), it passes validation and 500s at the same `n.name` deref, just at the apply-json call site. Note the primary fix (the validateGameSetupPayload element-shape check) already covers BOTH routes automatically because both validate before applying — so the `[null]` case is fixed on both paths with that single change. But the secondary suggestion ("wrap applyGameSetupPayload in try/catch") must be applied to BOTH sites (~3687 in /setup AND ~3743 in /setup/apply-json), not just /setup, so a genuine apply-time throw (e.g. a DB write failure) never escapes as a raw 500 on either path. 2) UX precision — the stuck game is escapable, just not cleanly recoverable. The re-entered setup wizard's onCancel handler (GameSurface.tsx ~7964-7971) calls deleteChat.mutate(activeChatId) when sessionStatus === "setup", so the user is not literally trapped "without manual deletion" — they can hit Cancel, which discards the half-created game (and loses all setup progress). The real defect is that the only recovery is abandon-and-restart with no clean repair path, not that the chat is unremovable.
Author
Owner

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

Fixed in 1ab15210. Setup validation now rejects null/sparse/bad startingNpcs entries before apply, NPC mapping is defensive, both setup apply paths catch apply-time failures into the JSON repair response instead of leaking raw 500s, and create-game failures now show a toast instead of silently resetting the button.

<!-- gh-comment-id:4761630678 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in 1ab15210. Setup validation now rejects null/sparse/bad startingNpcs entries before apply, NPC mapping is defensive, both setup apply paths catch apply-time failures into the JSON repair response instead of leaking raw 500s, and create-game failures now show a toast instead of silently resetting the button.
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#1354
No description provided.