mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[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
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1351
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
awaita 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
POST /game/setupbuilds the world-gen prompt andawaitsprovider.chatComplete(...)then returns one JSON body. Despite the client passingstreaming: true, the route opens no SSE —chatCompletebuffers the whole response.setupOptionscarries nosignal; undici'sbodyTimeoutis0(onlyheadersTimeout5min), Fastify has norequestTimeout, and the clientapi.postfetchhas no AbortController. A GM that stalls after headers → the wizard spins forever (gameSetup.isPendingnever flips), no error, no cancel./game/session/start, session N>1) runs a non-streamingchatCompletewith no signal/timeout; thetry/catchconverts a thrown error to a stub recap but does not bound a hang. The call lives insidestartSessionRequest, memoized inpendingSessionStartsand returned to every subsequent caller; its cleanupfinallyruns only when the promise settles. A mid-body stall → the promise never settles → every later/session/startfor that game returns the same never-resolving promise until process restart. Worse, the session chat is already committedgameSessionStatus:'ready'before the recap await, so reloading drops the user into a half-initialized session.runSceneAnalysisbehindfetchSpotifySceneCandidates(...)(a/game/spotify/candidatesPOST with a 25s timeout). WhengameUseSpotifyMusicis 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):packages/server/src/routes/game.routes.ts:3634(await provider.chatComplete),:3693(reply.send), setup options:3602-3623(nosignal);base-provider.ts:13-14(bodyTimeout:0);app.ts:48-56(norequestTimeout); clientapi-client.ts:102-119(no AbortController); spinner bound atGameSurface.tsx:7972.game.routes.ts:3996-4006(recapchatComplete, no signal),:3829-3832/:4086-4094(pendingSessionStartsmap + finally),:3918-3974(chat committed'ready'before recap),:4013-4016(catch handles throw not hang).client/src/components/game/GameSurface.tsx:4063-4071(gating),:3108-3140(25s candidates fetch),:3663-3672(scene-preparing gate).Steps to reproduce
/game/setupnever resolves; the wizard spins forever with no timeout or cancel./game/session/startagainst the same stalling backend → the request hangs and every retry returns the same wedged promise; the session-2 chat exists'ready'with no recap.api.spotify.comslow → every turn holds narration ~25s.Suggested fix
chatCompletecalls an explicit deadline (AbortController +setTimeout, ~3-4 min) threaded through the optionssignal, returning a clear error on timeout; convert/setupto a real SSE stream (like the generate route) so the client gets keepalive and can detect a dead stream; add a client AbortController/timeout toapi.postfor long calls.pendingSessionStartsdedup so a hung promise can't poison the game (watchdog/clear on timeout); generate the recap after committing the session.Environment
b826f8f4)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:
@kolacheee commented on GitHub (Jun 21, 2026):
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, thenawait provider.chatComplete(...)against the shared agent'sbodyTimeout: 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:conclusionOptionsat 4155-4165 (no signal),await provider.chatComplete(...)at 4189, plainreturn { summary }at 4310. Drives a persistenttoast.loading(\"Ending session and generating summary...\")(use-game.ts:294) with no signal onapi.postand no AbortController — a post-headers body stall hangs it forever, same UX as the setup spinner.\n-/game/session/regenerate-conclusion—conclusionOptionsat 4535-4545 (no signal),await provider.chatComplete(...)at 4569.\n-/game/session/update-campaign-progression—progressionOptionsat 4782-4792 (no signal),await provider.chatComplete(...)at 4840, plainreturn { ..., campaignProgression }at 4901.\n\nNone thread a signal and Fastify has norequestTimeout(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 throughgameGenOptions/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 committedgameSessionStatus: 'ready'at game.routes.ts:3974, before the recapawaitat 3996. The load-bearing parts of the recap fix remain: treat a timeout exactly like the existing thrown-error stub path, and harden thependingSessionStartsdedup (set 4086, settle-onlyfinally4090-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.@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.