[GH-ISSUE #3828] [Issue]: ComfyUI Engine loop skips indexed reference placeholders — Tauri fix from PR #1319 was never ported to packages/server #2064

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

Originally created by @GetBeholder on GitHub (Jul 19, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3828

Originally assigned to: @SpicyMarinara on GitHub.

Summary

packages/server/src/services/image/image-generation.ts still exhibits the exact bug described in #1275 — indexed ComfyUI reference placeholders (%reference_image_name_02%, %reference_image_name_03%, …) are never substituted when the scene has fewer reference images than the workflow declares slots for. They leak to ComfyUI as literal text and the queue rejects the workflow with Invalid image file: %reference_image_name_02% (or similar).

That bug was already fixed on the Tauri side in PR #1319 (src-tauri/src/commands/storage/images/providers.rs — collect_comfy_reference_name_tokens + missing-slot placeholder padding) and #1275 was closed accordingly. However the fix was never mirrored to the Marinara Engine's Node/TypeScript codebase (packages/server/src/services/image/image-generation.ts and runpod-comfyui.service.ts), where the same loop still stops at references.length without padding remaining indexed placeholders.

Expected behavior

For any ComfyUI workflow that uses indexed reference placeholders, every %reference_image_NN% / %reference_image_name_NN% should be substituted:

  • Slots 1..N where refs are available → filled with the corresponding uploaded reference.
  • Slots N+1..COMFYUI_MAX_REFERENCE_IMAGES that the workflow still references → filled with the built-in COMFYUI_PLACEHOLDER_REFERENCE_BASE64 (subject to defaults.uploadPlaceholderOnMissingReference).

Matches the Tauri behavior from PR #1319.

Actual behavior

Current image-generation.ts (Engine v2.3.3, staging branch as of $(date -u +%Y-%m-%d)):

```ts
const references = collectComfyReferenceImages(request, defaults);
for (let i = 0; i < references.length; i++) {
// fills only slots 1..references.length
}
const resolvedWorkflow = replaceComfyUiPlaceholders(workflow, replacements);
```

The loop is bound by references.length. If the workflow uses %reference_image_name_02% and the scene supplies 1 reference, that placeholder stays literal and ComfyUI rejects the payload.

runpod-comfyui.service.ts has the same shape (line ~111) and the same defect.

collectComfyReferenceImages's placeholder fallback (line ~2422) fires only when references.length === 0 and then only fills slot 1 — it never pads slots 2..N.

Steps to reproduce

  1. Configure a ComfyUI connection in Engine v2.3.3 with a workflow that declares three LoadImage nodes using %reference_image_name_01%, _02%, _03%.
  2. In a chat with one active character, run the Illustrator [selfie] command (only one reference image is available).
  3. ComfyUI queue call returns 400 prompt_outputs_failed_validation with details: "image - Invalid image file: %reference_image_name_02%".

Prior art

  • Original bug: #1275 (Beholder, May 2026)
  • Rust/Tauri fix: PR #1319 (cha1latte, merged) — src-tauri/src/commands/storage/images/providers.rs
  • Closely related: #3769 (1x1 placeholder crashing ComfyUI fillborders — separate concern; that fix has its own PR pending)

Suggested fix

Port the Tauri logic to the Engine's Node/TS side. Concretely, after the existing for (let i = 0; i < references.length; i++) loop in generateComfyUI:

  • Iterate i from references.length up to COMFYUI_MAX_REFERENCE_IMAGES.
  • For each i, if workflowJson.includes("%reference_image_${padded}%") set replacements[...] = COMFYUI_PLACEHOLDER_REFERENCE_BASE64.
  • For each i, if workflowJson.includes("%reference_image_name_${padded}%"), upload the placeholder image once (memoize) via uploadComfyReferenceImage and use the returned filename for every unfilled name slot.
  • Gate the whole padding block on defaults.uploadPlaceholderOnMissingReference so the opt-out semantics stay consistent.

Mirror the same in runpod-comfyui.service.ts (string-substitution flavor, no separate upload step).

Happy to author the port if useful — flagging first so we don't double-work if a mirror-port PR is already in flight.

Environment

  • Marinara Engine version: 2.3.3 (and current staging HEAD)
  • Install type: local dev (pnpm)
  • OS + version: Linux (CachyOS, kernel 7.0.10)
  • Backend: ComfyUI-ImageEditing on port 8189, Qwen-Image-Edit workflow with 3 LoadImage slots
Originally created by @GetBeholder on GitHub (Jul 19, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3828 Originally assigned to: @SpicyMarinara on GitHub. ## Summary `packages/server/src/services/image/image-generation.ts` still exhibits the exact bug described in #1275 — indexed ComfyUI reference placeholders (`%reference_image_name_02%`, `%reference_image_name_03%`, …) are never substituted when the scene has fewer reference images than the workflow declares slots for. They leak to ComfyUI as literal text and the queue rejects the workflow with `Invalid image file: %reference_image_name_02%` (or similar). That bug was already fixed on the **Tauri side** in PR #1319 (`src-tauri/src/commands/storage/images/providers.rs` — `collect_comfy_reference_name_tokens` + missing-slot placeholder padding) and #1275 was closed accordingly. However the fix was **never mirrored to the Marinara Engine's Node/TypeScript codebase** (`packages/server/src/services/image/image-generation.ts` and `runpod-comfyui.service.ts`), where the same loop still stops at `references.length` without padding remaining indexed placeholders. ## Expected behavior For any ComfyUI workflow that uses indexed reference placeholders, every `%reference_image_NN%` / `%reference_image_name_NN%` should be substituted: - Slots 1..N where refs are available → filled with the corresponding uploaded reference. - Slots N+1..COMFYUI_MAX_REFERENCE_IMAGES that the workflow still references → filled with the built-in `COMFYUI_PLACEHOLDER_REFERENCE_BASE64` (subject to `defaults.uploadPlaceholderOnMissingReference`). Matches the Tauri behavior from PR #1319. ## Actual behavior Current `image-generation.ts` (Engine v2.3.3, `staging` branch as of $(date -u +%Y-%m-%d)): \`\`\`ts const references = collectComfyReferenceImages(request, defaults); for (let i = 0; i < references.length; i++) { // fills only slots 1..references.length } const resolvedWorkflow = replaceComfyUiPlaceholders(workflow, replacements); \`\`\` The loop is bound by `references.length`. If the workflow uses `%reference_image_name_02%` and the scene supplies 1 reference, that placeholder stays literal and ComfyUI rejects the payload. `runpod-comfyui.service.ts` has the same shape (line ~111) and the same defect. `collectComfyReferenceImages`'s placeholder fallback (line ~2422) fires only when `references.length === 0` and then only fills slot 1 — it never pads slots 2..N. ## Steps to reproduce 1. Configure a ComfyUI connection in Engine v2.3.3 with a workflow that declares three `LoadImage` nodes using `%reference_image_name_01%`, `_02%`, `_03%`. 2. In a chat with one active character, run the Illustrator `[selfie]` command (only one reference image is available). 3. ComfyUI queue call returns `400 prompt_outputs_failed_validation` with `details: "image - Invalid image file: %reference_image_name_02%"`. ## Prior art - Original bug: #1275 (Beholder, May 2026) - Rust/Tauri fix: PR #1319 (`cha1latte`, merged) — `src-tauri/src/commands/storage/images/providers.rs` - Closely related: #3769 (1x1 placeholder crashing ComfyUI `fillborders` — separate concern; that fix has its own PR pending) ## Suggested fix Port the Tauri logic to the Engine's Node/TS side. Concretely, after the existing `for (let i = 0; i < references.length; i++)` loop in `generateComfyUI`: - Iterate `i` from `references.length` up to `COMFYUI_MAX_REFERENCE_IMAGES`. - For each `i`, if `workflowJson.includes("%reference_image_${padded}%")` set `replacements[...] = COMFYUI_PLACEHOLDER_REFERENCE_BASE64`. - For each `i`, if `workflowJson.includes("%reference_image_name_${padded}%")`, upload the placeholder image **once** (memoize) via `uploadComfyReferenceImage` and use the returned filename for every unfilled name slot. - Gate the whole padding block on `defaults.uploadPlaceholderOnMissingReference` so the opt-out semantics stay consistent. Mirror the same in `runpod-comfyui.service.ts` (string-substitution flavor, no separate upload step). Happy to author the port if useful — flagging first so we don't double-work if a mirror-port PR is already in flight. ## Environment - Marinara Engine version: 2.3.3 (and current `staging` HEAD) - Install type: local dev (pnpm) - OS + version: Linux (CachyOS, kernel 7.0.10) - Backend: ComfyUI-ImageEditing on port 8189, Qwen-Image-Edit workflow with 3 LoadImage slots
bsakaguchi 2026-10-21 05:45:03 +07:00
  • closed this issue
  • added the
    in-pr
    label
Author
Owner

@SpicyMarinara commented on GitHub (Jul 19, 2026):

Claimed by @SpicyMarinara in draft PR #3835 for this assigned issue sweep.

<!-- gh-comment-id:5016973227 --> @SpicyMarinara commented on GitHub (Jul 19, 2026): Claimed by @SpicyMarinara in draft PR #3835 for this assigned issue sweep.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 19, 2026):

Addressed in #3835: local and RunPod ComfyUI workflows now pad only declared missing indexed reference slots using the existing placeholder behavior, with focused regression coverage.

<!-- gh-comment-id:5017046353 --> @SpicyMarinara commented on GitHub (Jul 19, 2026): Addressed in #3835: local and RunPod ComfyUI workflows now pad only declared missing indexed reference slots using the existing placeholder behavior, with focused regression coverage.
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#2064
No description provided.