[GH-ISSUE #2707] [Issue]: /game/generate-assets serially generates up to 10 portraits with no abort — zombie work after client timeout (perceived hang) #1352

Closed
opened 2026-10-21 05:32:01 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

POST /game/generate-assets generates all game assets inline and sequentially — one background, one illustration, then up to 10 NPC portraits one-at-a-time — with no request-scoped AbortSignal. Worst case the server blocks for ~50+ minutes on a slow image backend while the client gives up at 240s, and the server keeps generating zombie portraits after no one is waiting (perceived hang, wasted backend, retries queue behind it).

Expected behavior

Asset generation should be bounded, cancellable when the client disconnects, and run with limited concurrency so a slow image backend can't make game creation/scene population appear to hang for many minutes.

Actual behavior

The handler runs one generateBackground, one generateSceneIllustration, then iterates input.npcsNeedingAvatars (Zod .max(10)) in a plain for loop awaiting generateNpcPortrait one at a time. Each generateImage has its own 5-minute deadline (IMAGE_GEN_TIMEOUT = 300_000), but the handler never inspects a request AbortSignal between portraits and passes no request-scoped signal into generateNpcPortrait/generateImage. The client wraps the call in withTimeout(..., 240_000). So when the client aborts at 240s, the server keeps generating every portrait to completion (nothing propagates the abort), and a subsequent /generate-assets retry queues behind the still-running work.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • packages/server/src/routes/game.routes.ts:7466 (generateBackground), ~:7558 (generateSceneIllustration), :7653-7700 (sequential NPC portrait loop); Zod .max(10) at :7054-7064.
  • packages/server/src/services/image/image-generation.ts:226 (IMAGE_GEN_TIMEOUT = 300_000, per-call only).
  • Client GameSurface.tsx:4247-4253 (withTimeout(..., GAME_ASSET_GENERATION_TIMEOUT_MS=240_000) + "continues without assets" toast).

Steps to reproduce

  1. Enable sprite/asset generation with an image connection pointed at a slow/unreachable-but-TCP-open backend (~60-120s/image).
  2. Trigger a first scene that introduces 5+ new NPCs.
  3. The client toasts "continues without assets" at 240s while server logs show portraits still generating one-by-one long after; a retry queues behind the still-running work.

Suggested fix

Pass a request-linked AbortSignal (from req.raw) down through generateNpcPortrait/generateBackground into generateImage, aborting the in-flight fetch on client disconnect and bailing out of the NPC loop when aborted. Generate portraits with bounded concurrency (e.g. p-limit 2-3) instead of fully sequentially, and cap the total handler wall-clock under the client's 240s so server and client agree.

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. A second "infinite loading" source (asset population) distinct from the setup hang. 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/2707 Originally assigned to: @SpicyMarinara on GitHub. ## Summary `POST /game/generate-assets` generates all game assets inline and **sequentially** — one background, one illustration, then up to 10 NPC portraits one-at-a-time — with no request-scoped AbortSignal. Worst case the server blocks for ~50+ minutes on a slow image backend while the client gives up at 240s, and the server keeps generating **zombie** portraits after no one is waiting (perceived hang, wasted backend, retries queue behind it). ## Expected behavior Asset generation should be bounded, cancellable when the client disconnects, and run with limited concurrency so a slow image backend can't make game creation/scene population appear to hang for many minutes. ## Actual behavior The handler runs one `generateBackground`, one `generateSceneIllustration`, then iterates `input.npcsNeedingAvatars` (Zod `.max(10)`) in a plain `for` loop `await`ing `generateNpcPortrait` one at a time. Each `generateImage` has its own 5-minute deadline (`IMAGE_GEN_TIMEOUT = 300_000`), but the handler never inspects a request AbortSignal between portraits and passes no request-scoped signal into `generateNpcPortrait`/`generateImage`. The client wraps the call in `withTimeout(..., 240_000)`. So when the client aborts at 240s, the server keeps generating every portrait to completion (nothing propagates the abort), and a subsequent `/generate-assets` retry queues behind the still-running work. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - `packages/server/src/routes/game.routes.ts:7466` (`generateBackground`), `~:7558` (`generateSceneIllustration`), `:7653-7700` (sequential NPC portrait loop); Zod `.max(10)` at `:7054-7064`. - `packages/server/src/services/image/image-generation.ts:226` (`IMAGE_GEN_TIMEOUT = 300_000`, per-call only). - Client `GameSurface.tsx:4247-4253` (`withTimeout(..., GAME_ASSET_GENERATION_TIMEOUT_MS=240_000)` + "continues without assets" toast). ## Steps to reproduce 1. Enable sprite/asset generation with an image connection pointed at a slow/unreachable-but-TCP-open backend (~60-120s/image). 2. Trigger a first scene that introduces 5+ new NPCs. 3. The client toasts "continues without assets" at 240s while server logs show portraits still generating one-by-one long after; a retry queues behind the still-running work. ## Suggested fix Pass a request-linked AbortSignal (from `req.raw`) down through `generateNpcPortrait`/`generateBackground` into `generateImage`, aborting the in-flight fetch on client disconnect and bailing out of the NPC loop when aborted. Generate portraits with bounded concurrency (e.g. `p-limit` 2-3) instead of fully sequentially, and cap the total handler wall-clock under the client's 240s so server and client agree. ## 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. A second "infinite loading" source (asset population) distinct from the setup hang. 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

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

Fixed on the issue sweep branch. /game/generate-assets now creates a response-tied AbortSignal with a 220s wall-clock cap, passes it into background/illustration/NPC portrait generation, and stops taking new portrait work when the client disconnects or the route deadline fires. Game image helpers now thread that signal into generateImage, and image-generation provider fetches combine the caller signal with their existing per-image timeout so in-flight requests can actually abort. NPC portraits now run with bounded concurrency of 2 instead of serially generating up to 10 portraits. Final pnpm validation is deferred until the full sweep is complete.

<!-- gh-comment-id:4761610120 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed on the issue sweep branch. /game/generate-assets now creates a response-tied AbortSignal with a 220s wall-clock cap, passes it into background/illustration/NPC portrait generation, and stops taking new portrait work when the client disconnects or the route deadline fires. Game image helpers now thread that signal into generateImage, and image-generation provider fetches combine the caller signal with their existing per-image timeout so in-flight requests can actually abort. NPC portraits now run with bounded concurrency of 2 instead of serially generating up to 10 portraits. 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#1352
No description provided.