[GH-ISSUE #2706] [Issue]: Game Mode hangs forever on creation/turn — /game/setup, new-session recap & scene-wrap await generations with no timeout/abort/SSE #1351

Closed
opened 2026-10-21 05:32:00 +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/2706

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Several Game Mode request paths await a model generation with no timeout, no AbortSignal, and no SSE/keepalive, so a provider that sends headers then stalls mid-body wedges the request forever. This is the canonical "infinite loading on game creation" report, and it has three confirmed instances: world-gen setup, the new-session recap (which also poisons an in-memory lock for the whole game), and the per-turn scene-wrap (gated behind a 25s Spotify fetch).

Expected behavior

Long-running game generations should have a bounded deadline + cancellation, surface a clear error on timeout, and never strand the UI on a perpetual spinner or wedge a shared in-flight lock.

Actual behavior

  1. POST /game/setup builds the world-gen prompt and awaits provider.chatComplete(...) then returns one JSON body. Despite the client passing streaming: true, the route opens no SSE — chatComplete buffers the whole response. setupOptions carries no signal; undici's bodyTimeout is 0 (only headersTimeout 5min), Fastify has no requestTimeout, and the client api.post fetch has no AbortController. A GM that stalls after headers → the wizard spins forever (gameSetup.isPending never flips), no error, no cancel.
  2. New-session recap (/game/session/start, session N>1) runs a non-streaming chatComplete with no signal/timeout; the try/catch converts a thrown error to a stub recap but does not bound a hang. The call lives inside startSessionRequest, memoized in pendingSessionStarts and returned to every subsequent caller; its cleanup finally runs only when the promise settles. A mid-body stall → the promise never settles → every later /session/start for that game returns the same never-resolving promise until process restart. Worse, the session chat is already committed gameSessionStatus:'ready' before the recap await, so reloading drops the user into a half-initialized session.
  3. Scene-wrap gates runSceneAnalysis behind fetchSpotifySceneCandidates(...) (a /game/spotify/candidates POST with a 25s timeout). When gameUseSpotifyMusic is on, a slow/429 Spotify holds the narration behind "preparing scene" for up to 25s every turn before scene analysis even starts.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • (1) packages/server/src/routes/game.routes.ts:3634 (await provider.chatComplete), :3693 (reply.send), setup options :3602-3623 (no signal); base-provider.ts:13-14 (bodyTimeout:0); app.ts:48-56 (no requestTimeout); client api-client.ts:102-119 (no AbortController); spinner bound at GameSurface.tsx:7972.
  • (2) game.routes.ts:3996-4006 (recap chatComplete, no signal), :3829-3832/:4086-4094 (pendingSessionStarts map + finally), :3918-3974 (chat committed 'ready' before recap), :4013-4016 (catch handles throw not hang).
  • (3) client/src/components/game/GameSurface.tsx:4063-4071 (gating), :3108-3140 (25s candidates fetch), :3663-3672 (scene-preparing gate).

Steps to reproduce

  1. Point the GM connection at a backend that returns 200 + headers then stalls the body (a local sidecar under load / a proxy holding the socket). Create a game → /game/setup never resolves; the wizard spins forever with no timeout or cancel.
  2. Conclude session 1, then /game/session/start against the same stalling backend → the request hangs and every retry returns the same wedged promise; the session-2 chat exists 'ready' with no recap.
  3. Enable Spotify scene music and make api.spotify.com slow → every turn holds narration ~25s.

Suggested fix

  • Give the setup and recap chatComplete calls an explicit deadline (AbortController + setTimeout, ~3-4 min) threaded through the options signal, returning a clear error on timeout; convert /setup to a real SSE stream (like the generate route) so the client gets keepalive and can detect a dead stream; add a client AbortController/timeout to api.post for long calls.
  • For the recap, treat a timeout exactly like the existing thrown-error stub path (recap is non-essential), and harden the pendingSessionStarts dedup so a hung promise can't poison the game (watchdog/clear on timeout); generate the recap after committing the session.
  • Don't gate scene analysis on the Spotify fetch — run with empty candidates and play the track asynchronously when they arrive; lower the 25s timeout.

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 for 2.0.0. This is the single highest-leverage fix for the long-standing "infinite loading 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/2706 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Several Game Mode request paths `await` a model generation with **no timeout, no AbortSignal, and no SSE/keepalive**, so a provider that sends headers then stalls mid-body wedges the request forever. This is the canonical "infinite loading on game creation" report, and it has three confirmed instances: world-gen setup, the new-session recap (which also poisons an in-memory lock for the whole game), and the per-turn scene-wrap (gated behind a 25s Spotify fetch). ## Expected behavior Long-running game generations should have a bounded deadline + cancellation, surface a clear error on timeout, and never strand the UI on a perpetual spinner or wedge a shared in-flight lock. ## Actual behavior 1. **`POST /game/setup`** builds the world-gen prompt and `await`s `provider.chatComplete(...)` then returns one JSON body. Despite the client passing `streaming: true`, the route opens no SSE — `chatComplete` buffers the whole response. `setupOptions` carries **no `signal`**; undici's `bodyTimeout` is `0` (only `headersTimeout` 5min), Fastify has no `requestTimeout`, and the client `api.post` `fetch` has no AbortController. A GM that stalls after headers → the wizard spins forever (`gameSetup.isPending` never flips), no error, no cancel. 2. **New-session recap** (`/game/session/start`, session N>1) runs a non-streaming `chatComplete` with no signal/timeout; the `try/catch` converts a *thrown* error to a stub recap but does **not** bound a *hang*. The call lives inside `startSessionRequest`, memoized in `pendingSessionStarts` and returned to every subsequent caller; its cleanup `finally` runs only when the promise settles. A mid-body stall → the promise never settles → every later `/session/start` for that game returns the same never-resolving promise until process restart. Worse, the session chat is already committed `gameSessionStatus:'ready'` before the recap await, so reloading drops the user into a half-initialized session. 3. **Scene-wrap** gates `runSceneAnalysis` behind `fetchSpotifySceneCandidates(...)` (a `/game/spotify/candidates` POST with a **25s** timeout). When `gameUseSpotifyMusic` is on, a slow/429 Spotify holds the narration behind "preparing scene" for up to 25s every turn before scene analysis even starts. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - (1) `packages/server/src/routes/game.routes.ts:3634` (`await provider.chatComplete`), `:3693` (`reply.send`), setup options `:3602-3623` (no `signal`); `base-provider.ts:13-14` (`bodyTimeout:0`); `app.ts:48-56` (no `requestTimeout`); client `api-client.ts:102-119` (no AbortController); spinner bound at `GameSurface.tsx:7972`. - (2) `game.routes.ts:3996-4006` (recap `chatComplete`, no signal), `:3829-3832`/`:4086-4094` (`pendingSessionStarts` map + finally), `:3918-3974` (chat committed `'ready'` before recap), `:4013-4016` (catch handles throw not hang). - (3) `client/src/components/game/GameSurface.tsx:4063-4071` (gating), `:3108-3140` (25s candidates fetch), `:3663-3672` (scene-preparing gate). ## Steps to reproduce 1. Point the GM connection at a backend that returns 200 + headers then stalls the body (a local sidecar under load / a proxy holding the socket). Create a game → `/game/setup` never resolves; the wizard spins forever with no timeout or cancel. 2. Conclude session 1, then `/game/session/start` against the same stalling backend → the request hangs and every retry returns the same wedged promise; the session-2 chat exists `'ready'` with no recap. 3. Enable Spotify scene music and make `api.spotify.com` slow → every turn holds narration ~25s. ## Suggested fix - Give the setup and recap `chatComplete` calls an explicit deadline (AbortController + `setTimeout`, ~3-4 min) threaded through the options `signal`, returning a clear error on timeout; convert `/setup` to a real SSE stream (like the generate route) so the client gets keepalive and can detect a dead stream; add a client AbortController/timeout to `api.post` for long calls. - For the recap, treat a timeout exactly like the existing thrown-error stub path (recap is non-essential), and harden the `pendingSessionStarts` dedup so a hung promise can't poison the game (watchdog/clear on timeout); generate the recap after committing the session. - Don't gate scene analysis on the Spotify fetch — run with empty candidates and play the track asynchronously when they arrive; lower the 25s timeout. ## 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 for 2.0.0. This is the single highest-leverage fix for the long-standing "infinite loading 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.

Scope note (not a correction — the three cited instances are all real and verified in the current tree): the same root cause (gameGenOptions called without a signal, then await provider.chatComplete(...) against the shared agent's bodyTimeout: 0, returning a buffered JSON reply with no SSE) also exists in three adjacent game routes this issue does not name in its code trace or repro steps. A fixer who patches only setup/recap/scene-wrap will leave these hanging identically:\n\n- /game/session/conclude — game.routes.ts: conclusionOptions at 4155-4165 (no signal), await provider.chatComplete(...) at 4189, plain return { summary } at 4310. Drives a persistent toast.loading(\"Ending session and generating summary...\") (use-game.ts:294) with no signal on api.post and no AbortController — a post-headers body stall hangs it forever, same UX as the setup spinner.\n- /game/session/regenerate-conclusion — conclusionOptions at 4535-4545 (no signal), await provider.chatComplete(...) at 4569.\n- /game/session/update-campaign-progression — progressionOptions at 4782-4792 (no signal), await provider.chatComplete(...) at 4840, plain return { ..., campaignProgression } at 4901.\n\nNone thread a signal and Fastify has no requestTimeout (app.ts:48-56), so each hangs indefinitely on a mid-body stall. When applying the deadline/AbortController fix, apply it to these three too — ideally by threading a default timeout signal through gameGenOptions/the shared LLM call site so every game generation is bounded, rather than patching call sites one at a time.\n\nMinor wording on the suggested fix: "generate the recap after committing the session" is already true in code — the new session chat is committed gameSessionStatus: 'ready' at game.routes.ts:3974, before the recap await at 3996. The load-bearing parts of the recap fix remain: treat a timeout exactly like the existing thrown-error stub path, and harden the pendingSessionStarts dedup (set 4086, settle-only finally 4090-4094, return-existing 3831) with a watchdog/clear-on-timeout so a hung promise can't poison the lock for the whole game until restart.

<!-- gh-comment-id:4761102504 --> @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._ Scope note (not a correction — the three cited instances are all real and verified in the current tree): the same root cause (gameGenOptions called without a `signal`, then `await provider.chatComplete(...)` against the shared agent's `bodyTimeout: 0`, returning a buffered JSON reply with no SSE) also exists in three adjacent game routes this issue does not name in its code trace or repro steps. A fixer who patches only setup/recap/scene-wrap will leave these hanging identically:\n\n- `/game/session/conclude` — `game.routes.ts`: `conclusionOptions` at 4155-4165 (no signal), `await provider.chatComplete(...)` at 4189, plain `return { summary }` at 4310. Drives a persistent `toast.loading(\"Ending session and generating summary...\")` (use-game.ts:294) with no signal on `api.post` and no AbortController — a post-headers body stall hangs it forever, same UX as the setup spinner.\n- `/game/session/regenerate-conclusion` — `conclusionOptions` at 4535-4545 (no signal), `await provider.chatComplete(...)` at 4569.\n- `/game/session/update-campaign-progression` — `progressionOptions` at 4782-4792 (no signal), `await provider.chatComplete(...)` at 4840, plain `return { ..., campaignProgression }` at 4901.\n\nNone thread a signal and Fastify has no `requestTimeout` (app.ts:48-56), so each hangs indefinitely on a mid-body stall. When applying the deadline/AbortController fix, apply it to these three too — ideally by threading a default timeout signal through `gameGenOptions`/the shared LLM call site so every game generation is bounded, rather than patching call sites one at a time.\n\nMinor wording on the suggested fix: \"generate the recap after committing the session\" is already true in code — the new session chat is committed `gameSessionStatus: 'ready'` at game.routes.ts:3974, before the recap `await` at 3996. The load-bearing parts of the recap fix remain: treat a timeout exactly like the existing thrown-error stub path, and harden the `pendingSessionStarts` dedup (set 4086, settle-only `finally` 4090-4094, return-existing 3831) with a watchdog/clear-on-timeout so a hung promise can't poison the lock for the whole game until restart.
Author
Owner

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

Fixed on the issue sweep branch. All game.routes provider.chatComplete calls that use gameGenOptions now go through a shared 4-minute AbortController deadline, including setup, session recap, conclude/regenerate conclusion, campaign progression, lorebook keeper, party recruit card, map generation, party turn, and scene-wrap. Recap timeouts now hit the existing fallback stub path and the pendingSessionStarts finally cleanup can run instead of poisoning the in-memory lock. The client scene processor no longer waits for Spotify candidates before starting sidecar/scene-connection analysis, and the Spotify candidate timeout was reduced to 8s; candidates now only trigger async fallback playback when they arrive. I did not convert /game/setup to SSE in this sweep; the bounded abort path prevents the reported forever-spinner with lower risk. Final pnpm validation is deferred until the full sweep is complete.

<!-- gh-comment-id:4761596585 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed on the issue sweep branch. All game.routes provider.chatComplete calls that use gameGenOptions now go through a shared 4-minute AbortController deadline, including setup, session recap, conclude/regenerate conclusion, campaign progression, lorebook keeper, party recruit card, map generation, party turn, and scene-wrap. Recap timeouts now hit the existing fallback stub path and the pendingSessionStarts finally cleanup can run instead of poisoning the in-memory lock. The client scene processor no longer waits for Spotify candidates before starting sidecar/scene-connection analysis, and the Spotify candidate timeout was reduced to 8s; candidates now only trigger async fallback playback when they arrive. I did not convert /game/setup to SSE in this sweep; the bounded abort path prevents the reported forever-spinner with lower risk. Final pnpm validation is deferred until the full sweep is complete.
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#1351
No description provided.