[GH-ISSUE #2753] [Issue]: Stability v2 img2img always 400 (aspect_ratio + image-to-image) and ComfyUI failures hang for the full timeout #1394

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Two image providers have generation-path defects: every Stability v2 reference-image request is rejected by the API, and several ComfyUI failure modes turn into a 5-minute hang plus a misleading generic timeout that discards the real error. The ComfyUI poll loop also can't be cancelled and never reaches its own per-backend budget.

Sub-bug 1: Stability v2 img2img always 400s (#52) [primary]

  • How it breaks: generateStability (v2 branch) appends aspect_ratio unconditionally when width/height exist (1040-1041), then for a reference image also appends mode=image-to-image + image + strength (1042-1058). Stability's v2beta sd3/ultra/core endpoints accept aspect_ratio only in text-to-image mode; in image-to-image the dimensions come from the input image and aspect_ratio is disallowed -> 400.
  • Repro: Configure Stability AI (v2beta) as the image provider; generate any image with a reference/character-consistency/avatar reference (callers always pass width/height). Fails with 'Stability image generation failed (400)'. Text-to-image works.
  • Trace: referenceImage set + width/height -> sd3 endpoint -> 1041 append aspect_ratio -> 1049 append mode=image-to-image -> both present -> 400 -> thrown at ~1077.

Sub-bug 2: ComfyUI execution error hangs (#53)

  • How it breaks: The poll loop only inspects entry?.outputs (1937-1938 if (!entry?.outputs) continue;) and never reads entry.status. A failed workflow (bad checkpoint, OOM, missing node) returns a status: { status_str: 'error', messages: [...] } with no outputs, indistinguishable from in-progress; the loop spins the full COMFYUI_GEN_TIMEOUT (300s) then throws a generic timeout, discarding status.messages. Same for terminal nodes that emit no images/gifs (e.g. SaveImageWebsocket).
  • Repro: Run a ComfyUI workflow that errors during execution. Wait 5 minutes; get 'ComfyUI generation timed out' instead of the real error.

Sub-bug 3: Missing prompt_id hang (#23)

  • How it breaks: const { prompt_id } = await queueResp.json() (1924) is unguarded. On an HTTP 200 body lacking prompt_id (auth gateway / reverse proxy / fork), the poll URL becomes /history/undefined, every iteration continues, and the loop runs the full timeout then throws the generic message.
  • Repro: Point ComfyUI base URL at a proxy that returns 200 without prompt_id. 5-minute hang, misleading error.

Sub-bug 4: Unreachable per-backend timeout + orphaned loop (#19)

  • How it breaks: The outer withImageGenerationDeadline race (300s) always preempts the 300-iteration poll loop (each iteration sleeps 1s + fetches), so COMFYUI_GEN_TIMEOUT_SECONDS is effectively dead and a job finishing near 290-300s is reported as a timeout. Promise.race doesn't cancel the loser and imageRequestSignal rebuilds a fresh 300s signal each call, so after the deadline rejects the loop keeps polling the local backend (result discarded).

Suggested Fix

  • Stability: only append aspect_ratio when no reference image is present (if (aspectRatio && !hasReference)).
  • ComfyUI: read entry.status; if status_str === 'error' (or completed with no image outputs) throw immediately with joined status.messages via sanitizeErrorText. Validate prompt_id is a non-empty string after parsing the queue response and surface node_errors/error if absent. Make the deadline abort the work via a shared AbortController and derive the poll bound from elapsed wall-clock (or set COMFYUI timeout below IMAGE_GEN_TIMEOUT).

Verification checklist (all manual)

  • Manually verify Stability v2 img2img / character-consistency / avatar-reference generation succeeds after the fix
  • Verify Stability v2 text-to-image still works
  • Verify a failing ComfyUI workflow surfaces the real error promptly instead of a 5-minute timeout
  • Verify a ComfyUI queue response missing prompt_id errors immediately
  • Verify cancelling/timeout stops the ComfyUI poll loop rather than leaving it polling
  • Run pnpm check

Affected files

  • packages/server/src/services/image/image-generation.ts

Audit provenance

Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged staging tree. Severity: HIGH.

AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2753 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Two image providers have generation-path defects: every Stability v2 reference-image request is rejected by the API, and several ComfyUI failure modes turn into a 5-minute hang plus a misleading generic timeout that discards the real error. The ComfyUI poll loop also can't be cancelled and never reaches its own per-backend budget. ## Sub-bug 1: Stability v2 img2img always 400s (#52) [primary] - **How it breaks:** `generateStability` (v2 branch) appends `aspect_ratio` unconditionally when width/height exist (1040-1041), then for a reference image also appends `mode=image-to-image` + image + strength (1042-1058). Stability's v2beta sd3/ultra/core endpoints accept `aspect_ratio` only in text-to-image mode; in image-to-image the dimensions come from the input image and `aspect_ratio` is disallowed -> 400. - **Repro:** Configure Stability AI (v2beta) as the image provider; generate any image with a reference/character-consistency/avatar reference (callers always pass width/height). Fails with 'Stability image generation failed (400)'. Text-to-image works. - **Trace:** referenceImage set + width/height -> sd3 endpoint -> 1041 append aspect_ratio -> 1049 append mode=image-to-image -> both present -> 400 -> thrown at ~1077. ## Sub-bug 2: ComfyUI execution error hangs (#53) - **How it breaks:** The poll loop only inspects `entry?.outputs` (1937-1938 `if (!entry?.outputs) continue;`) and never reads `entry.status`. A failed workflow (bad checkpoint, OOM, missing node) returns a `status: { status_str: 'error', messages: [...] }` with no outputs, indistinguishable from in-progress; the loop spins the full COMFYUI_GEN_TIMEOUT (300s) then throws a generic timeout, discarding `status.messages`. Same for terminal nodes that emit no images/gifs (e.g. SaveImageWebsocket). - **Repro:** Run a ComfyUI workflow that errors during execution. Wait 5 minutes; get 'ComfyUI generation timed out' instead of the real error. ## Sub-bug 3: Missing prompt_id hang (#23) - **How it breaks:** `const { prompt_id } = await queueResp.json()` (1924) is unguarded. On an HTTP 200 body lacking prompt_id (auth gateway / reverse proxy / fork), the poll URL becomes `/history/undefined`, every iteration `continue`s, and the loop runs the full timeout then throws the generic message. - **Repro:** Point ComfyUI base URL at a proxy that returns 200 without `prompt_id`. 5-minute hang, misleading error. ## Sub-bug 4: Unreachable per-backend timeout + orphaned loop (#19) - **How it breaks:** The outer `withImageGenerationDeadline` race (300s) always preempts the 300-iteration poll loop (each iteration sleeps 1s + fetches), so `COMFYUI_GEN_TIMEOUT_SECONDS` is effectively dead and a job finishing near 290-300s is reported as a timeout. `Promise.race` doesn't cancel the loser and `imageRequestSignal` rebuilds a fresh 300s signal each call, so after the deadline rejects the loop keeps polling the local backend (result discarded). ## Suggested Fix - Stability: only append `aspect_ratio` when no reference image is present (`if (aspectRatio && !hasReference)`). - ComfyUI: read `entry.status`; if `status_str === 'error'` (or completed with no image outputs) throw immediately with joined `status.messages` via `sanitizeErrorText`. Validate `prompt_id` is a non-empty string after parsing the queue response and surface `node_errors`/`error` if absent. Make the deadline abort the work via a shared AbortController and derive the poll bound from elapsed wall-clock (or set COMFYUI timeout below IMAGE_GEN_TIMEOUT). ## Verification checklist (all manual) - [ ] Manually verify Stability v2 img2img / character-consistency / avatar-reference generation succeeds after the fix - [ ] Verify Stability v2 text-to-image still works - [ ] Verify a failing ComfyUI workflow surfaces the real error promptly instead of a 5-minute timeout - [ ] Verify a ComfyUI queue response missing prompt_id errors immediately - [ ] Verify cancelling/timeout stops the ComfyUI poll loop rather than leaving it polling - [ ] Run `pnpm check` --- ### Affected files - `packages/server/src/services/image/image-generation.ts` ### Audit provenance Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged `staging` tree. Severity: **HIGH**. > AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.
Author
Owner

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

Addressed on PR #2747. Stability v2 now omits aspect_ratio for reference/image-to-image requests while preserving it for text-to-image. Image generation uses one deadline-scoped abort signal for provider work, so ComfyUI polling is cancelled by timeout/abort instead of continuing in the background. ComfyUI now validates prompt_id immediately, surfaces workflow status errors from history, treats completed workflows without image outputs as failures, and uses elapsed-time polling with abortable sleeps. Validated with git diff --check for the touched file; full pnpm validation is deferred until the end of the issue sweep per maintainer request.

<!-- gh-comment-id:4763293593 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed on PR #2747. Stability v2 now omits aspect_ratio for reference/image-to-image requests while preserving it for text-to-image. Image generation uses one deadline-scoped abort signal for provider work, so ComfyUI polling is cancelled by timeout/abort instead of continuing in the background. ComfyUI now validates prompt_id immediately, surfaces workflow status errors from history, treats completed workflows without image outputs as failures, and uses elapsed-time polling with abortable sleeps. Validated with git diff --check for the touched file; full pnpm validation is deferred until the end of the issue sweep per maintainer request.
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#1394
No description provided.