[Partner Nodes] Stop adding an opaque alpha channel to API node images - #15369
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (9)
🧰 Additional context used📓 Path-based instructions (6)**/*📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{py,json}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{py,md,txt,json}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**⚙️ CodeRabbit configuration file
Files:
comfy_api_nodes/**⚙️ CodeRabbit configuration file
Files:
🧠 Learnings (8)📚 Learning: 2026-02-21T14:01:41.482ZApplied to files:
📚 Learning: 2026-04-18T16:55:46.724ZApplied to files:
📚 Learning: 2026-05-07T17:59:26.050ZApplied to files:
📚 Learning: 2026-07-14T20:09:03.091ZApplied to files:
📚 Learning: 2026-07-16T16:29:35.022ZApplied to files:
📚 Learning: 2026-08-04T18:49:57.785ZApplied to files:
📚 Learning: 2026-08-11T17:33:31.657ZApplied to files:
📚 Learning: 2026-08-13T17:36:37.574ZApplied to files:
🔇 Additional comments (1)
📝 WalkthroughWalkthroughThe image conversion utility selects RGB for opaque images and RGBA for images with transparency when no mode is specified. Explicit conversion modes remain supported. The new padding utility adds opaque alpha channels before concatenation when image tensors have different channel counts. Gemini and Recraft normalize mixed-channel outputs. Recraft decodes remove-background results as RGBA. ByteDance decodes downloaded layers as RGBA. Unit tests cover these conversion and response paths. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@comfy_api_nodes/util/conversions.py`:
- Around line 36-37: Update get_image_from_response to inspect decoded image
channels before concatenating and promote RGB tensors to RGBA whenever any
response image includes alpha, ensuring all tensors share the same channel
count. Add a regression test covering a response with mixed RGB and RGBA image
parts.
In `@tests-unit/comfy_api_nodes_test/image_conversions_test.py`:
- Around line 43-48: Update test_palette_png_with_transparency_keeps_its_alpha
to set at least one image pixel to palette index 0 before encoding, then assert
that the corresponding tensor pixel has alpha 0.0 while a palette index 1 pixel
remains opaque. Retain the existing four-channel shape assertion and keep the
test focused on palette transparency.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 5d6bb3fd-7fa4-464f-9a45-07d8ddd2fa9a
📒 Files selected for processing (4)
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.pytests-unit/comfy_api_nodes_test/image_conversions_test.py
📜 Review details
⏰ Context from checks skipped due to timeout. (9)
- GitHub Check: test (ubuntu-latest)
- GitHub Check: Run Pylint
- GitHub Check: test (windows-latest)
- GitHub Check: test (windows-2022)
- GitHub Check: test
- GitHub Check: test (macos-latest)
- GitHub Check: test (ubuntu-latest)
- GitHub Check: test (macos-latest)
- GitHub Check: Run Pylint
🧰 Additional context used
📓 Path-based instructions (6)
**/*
📄 CodeRabbit inference engine (AGENTS.md)
**/*: Keep changes small, direct, and limited to the narrowest necessary code path and smallest number of files.
Prefer practical fixes, minimal dependencies, and existing repository patterns; remove obsolete, dead, unreachable, or unused code.
Preserve existing APIs, node names, model-loading behavior, file layout, and workflow compatibility unless replacement is explicitly intended.
Core ComfyUI must not add outbound internet requests, telemetry, tracking, reporting, remote configuration, or background network activity. User-authorized model downloads are limited to the requested artifact and must exclude telemetry and unrelated metadata.
Files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.pytests-unit/comfy_api_nodes_test/image_conversions_test.py
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py: Keep state and capability flags on the object that owns the behavior. Prefer explicit parent-owned attributes over probing child objects withgetattr; use child checks only when the child owns the delegated behavior.
Preserve shared method signatures, argument order, return shapes, side effects, and error behavior unless every affected caller and interface is intentionally updated.
Do not add unused compatibility parameters, flags, attributes, constructor options, or model-specific options to shared helpers; keep one-off behavior at the integration boundary.
Normalize third-party return conventions at integration boundaries so core code receives the expected type and shape; avoid undocumented caller-side unwrapping.
Do not addtorch.no_grad,torch.inference_mode, or inference-mode wrappers. Do not add model freeze/unfreeze toggles; only disable globally enabled inference mode when a training path requires gradients.
Remove inference-only training behavior such as dropout while preserving checkpoint and state-dict compatibility; usenn.Identitywhen deleting a module would alter keys or ordering.
Keep imports at module scope except established optional-backend probes or imports required to avoid cycles; avoid unnecessarytry/exceptblocks and use specific exceptions with useful fallbacks.
Do not add workarounds for unsupported library versions, especially PyTorch exception-and-float-cast retries, unless a comment names the exact versions still requiring them.
Let unsupported model formats, invalid quantization metadata, and bad states fail with clear errors instead of silently degrading output.
Match local style, keep comments sparse and useful, and remove comments that merely restate obvious code.
Treat dtype, device placement, VRAM use, and offloading as correctness concerns across CPU, CUDA, ROCm, MPS, DirectML, XPU, NPU, and low-VRAM environments.
Prefer existing ComfyUI and Comfy Kitchen operations, quantization helpers, cast/offload helpe...
Files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.pytests-unit/comfy_api_nodes_test/image_conversions_test.py
**/*.{py,json}
📄 CodeRabbit inference engine (AGENTS.md)
Treat legacy combo,
io.Combo, andio.DynamicCombovalues affecting filesystem access as untrusted; revalidate them at load/save boundaries withfolder_paths, containment checks, or fixed allowlists.
Files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.pytests-unit/comfy_api_nodes_test/image_conversions_test.py
**/*.{py,md,txt,json}
📄 CodeRabbit inference engine (AGENTS.md)
Keep warning and info messages short and actionable, remove noisy or misleading logging, and make documentation edits concise, factual, and tied to changed behavior.
Files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.pytests-unit/comfy_api_nodes_test/image_conversions_test.py
**
⚙️ CodeRabbit configuration file
**: IMPORTANT: Only comment on issues directly introduced by this PR's code changes.
Treat AGENTS.md as mandatory repository policy, not optional style guidance.
Flag PR changes that violate AGENTS.md even when the code is otherwise functional.
In particular, enforce architecture boundaries, dtype/device/memory rules,
interface contracts, import style, no unnecessary try/except blocks, no inline
imports, no outbound internet paths in core ComfyUI, and narrow scoped fixes.
Prefer direct findings over suggestions when a rule is violated. Only ignore
AGENTS.md when it clearly conflicts with a newer explicit maintainer instruction
in the PR.
Do NOT flag pre-existing issues in code that was merely moved, re-indented,
de-indented, or reformatted without logic changes. If code appears in the diff
only due to whitespace or structural reformatting (e.g., removing awith:block),
treat it as unchanged. Contributors should not feel obligated to address
pre-existing issues outside the scope of their contribution.
Files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.pytests-unit/comfy_api_nodes_test/image_conversions_test.py
comfy_api_nodes/**
⚙️ CodeRabbit configuration file
comfy_api_nodes/**: Third-party API integration nodes. Focus on:
- No hardcoded API keys or secrets
- Proper error handling for API failures (timeouts, rate limits, auth errors)
- Correct Pydantic model usage
- Security of user data passed to external APIs
Files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.py
🧠 Learnings (6)
📚 Learning: 2026-02-21T14:01:41.482Z
Learnt from: pythongosssss
Repo: Comfy-Org/ComfyUI PR: 12555
File: comfy_extras/nodes_glsl.py:719-724
Timestamp: 2026-02-21T14:01:41.482Z
Learning: In PyOpenGL, bare Python scalars can be accepted for 1-element array parameters by NumberHandler. This means you can pass an int/float directly to OpenGL texture deletion (e.g., glDeleteTextures(tex)) without wrapping in a list. Verify function-specific expectations and ensure types match what the OpenGL call expects; use explicit lists only when the API requires an array.
Applied to files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.pytests-unit/comfy_api_nodes_test/image_conversions_test.py
📚 Learning: 2026-04-18T16:55:46.724Z
Learnt from: bigcat88
Repo: Comfy-Org/ComfyUI PR: 13465
File: comfy_api_nodes/nodes_bytedance.py:1496-1506
Timestamp: 2026-04-18T16:55:46.724Z
Learning: In `comfy_api_nodes` Python async node implementations (e.g., `async def execute`), synchronous CPU/IO-heavy helpers (such as video/audio trim/resize and base64/MP3 conversion) may be called directly without offloading to a thread executor (e.g., `asyncio.to_thread`). Treat this as an existing, broader refactor concern rather than a new PR regression: if the PR does not introduce additional synchronous blocking calls, reviewers should not flag it as a new issue. However, if the PR adds new synchronous CPU/IO work inside `async def execute`, prefer offloading with `asyncio.to_thread` (or an equivalent background executor) to avoid blocking the event loop.
Applied to files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.py
📚 Learning: 2026-05-07T17:59:26.050Z
Learnt from: bigcat88
Repo: Comfy-Org/ComfyUI PR: 13753
File: comfy_api_nodes/nodes_gemini.py:1148-1157
Timestamp: 2026-05-07T17:59:26.050Z
Learning: In ComfyUI node implementations under `comfy_api_nodes/`, when building JSONata expressions that use `IO.PriceBadge` for `$lookup` against a price map keyed in lowercase, do not add an explicit `$lowercase()` around widget values (e.g., combo options like "1K", "2K", "4K"). The ComfyUI frontend automatically lowercases widget values before evaluating the JSONata expression, so the lookup keys will already match the lowercase map entries.
Applied to files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.py
📚 Learning: 2026-07-14T20:09:03.091Z
Learnt from: bigcat88
Repo: Comfy-Org/ComfyUI PR: 14928
File: comfy_api_nodes/nodes_sync_so.py:168-202
Timestamp: 2026-07-14T20:09:03.091Z
Learning: In the `comfy_api_nodes/` package, partner/API node `execute` implementations should keep the full submit → poll → status-check → download flow written inline within each node (even if similar logic appears across multiple nodes). This is an intentional repo convention to optimize per-node readability and independent editability, so during reviews you should generally not recommend refactoring this pattern into a shared helper function for these nodes (unless there’s a concrete correctness/security issue).
Applied to files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.py
📚 Learning: 2026-07-16T16:29:35.022Z
Learnt from: bigcat88
Repo: Comfy-Org/ComfyUI PR: 14958
File: comfy_api_nodes/nodes_heygen.py:554-558
Timestamp: 2026-07-16T16:29:35.022Z
Learning: When implementing ComfyUI API nodes in this repo, for any billable HTTP POST operations, follow the established policy: keep the existing default retry behavior. Do not add idempotency keys or disable retries. The rationale is to prevent failures from aborting the entire workflow; when reviewing new API nodes, check that POST billing requests preserve the default retry configuration and remain consistent with this policy.
Applied to files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.py
📚 Learning: 2026-08-04T18:49:57.785Z
Learnt from: bigcat88
Repo: Comfy-Org/ComfyUI PR: 15295
File: comfy_api_nodes/nodes_bfl.py:1037-1051
Timestamp: 2026-08-04T18:49:57.785Z
Learning: When consuming dictionaries produced by IO.Autogrow.Type, rely on their iteration order to match the configured template-slot order. This ordering is preserved by _expand_schema_for_dynamic, parse_class_inputs, and build_nested_inputs, so consumers should iterate the dictionary directly when processing dynamic slots.
Applied to files:
comfy_api_nodes/nodes_gemini.pycomfy_api_nodes/nodes_recraft.pycomfy_api_nodes/util/conversions.py
🔇 Additional comments (4)
comfy_api_nodes/util/conversions.py (1)
19-26: LGTM!tests-unit/comfy_api_nodes_test/image_conversions_test.py (1)
1-40: LGTM!Also applies to: 51-54
comfy_api_nodes/nodes_gemini.py (1)
236-236: LGTM!comfy_api_nodes/nodes_recraft.py (1)
998-998: LGTM!
|
Both CodeRabbit findings addressed in 400b041. Mixed channel counts across image parts — real, and new: before this PR every part decoded to RGBA so Palette test had no transparent pixel — correct, the image was filled with index 1 while |
6dc0d4a to
230be4e
Compare
bytesio_to_image_tensor converted every downloaded image to RGBA, so nodes whose API returns no transparency still emitted a 4 channel IMAGE. Keep the alpha when the decoded image has one, stay RGB when it does not.
A multi part response can now decode to a mix of RGB and RGBA, which torch.cat rejects. Widen the narrower parts with an opaque alpha, the same way ImageBatch does.
230be4e to
f64722d
Compare
Signed-off-by: bigcat88 <bigcat88@icloud.com>
3c92268
33d9813 to
3c92268
Compare
Signed-off-by: bigcat88 <bigcat88@icloud.com>
3c92268 to
d2a99f6
Compare
bytesio_to_image_tensordefaulted tomode="RGBA"and ranimage.convert(mode)unconditionally, so every image downloaded by an API node came back as 4 channels — including from the many APIs that return no transparency at all. The 4th channel was a constant 1.0 that no vendor sent.That costs real behavior downstream, because a 4-channel IMAGE is not interchangeable with a 3-channel one:
ImageUpscaleWithModelfeeds the tensor to a 3-channel spandrel model.ColorTransfercallskornia.color.rgb_to_lab, which requires exactly 3 channels.ImageQuantizebuilds a PIL image withmode='RGB'and reinterprets the buffer.ImageInvertis1.0 - image, which turns the opaque alpha transparent.comfy_api_nodes/nodes_bria.pyalready carries# Bria's replace_background 500s on RGBA, so drop the alpha channel before upload., and four sites incomfy_api_nodes/nodes_bfl.pystrip with# make sure image will have alpha channel removed.Now the mode defaults to whatever the decoded image actually has: RGBA if it carries transparency, RGB if it does not. Callers that pass an explicit
modeare unaffected. Nodes that return genuinely transparent images — RecraftremoveBackground, OpenAIbackground="transparent"— keep their alpha, and it now means something instead of always being present.Two call sites needed to move with it:
nodes_gemini.py— the no-image placeholder wastorch.zeros((1, 1024, 1024, 4)), now 3, matching what the node returns on the normal path.nodes_recraft.py—RecraftRemoveBackgroundNodereads its MASK out of the last channel, so it asks formode="RGBA"explicitly rather than relying on the old default.On Gemini specifically: the image generation docs (https://ai.google.dev/gemini-api/docs/image-generation) never mention alpha or transparency,
response_formatexposes onlymime_type/aspect_ratio/image_size, and the community models that do sell a transparent Nano Banana produce the alpha by rendering twice and matting. So nothing was being discarded there — a channel was being invented.Not included:
comfy_api_nodes/nodes_openai.pyhas its ownImage.open(img_io).convert("RGBA")invalidate_and_cast_responsewith the same issue. It needs slightly different handling becausebackground="auto"can vary per image within one response and the images aretorch.stacked, so it wants a batch-level normalization rather than a per-image default. Left for a separate change.Tests:
tests-unit/comfy_api_nodes_test/image_conversions_test.pycovers RGB PNG, JPEG, grayscale, RGBA, palette-with-transparency, and explicitmode=.python -m pytest tests-unit/comfy_api_nodes_test/passes;ruff check .andpylint comfy_api_nodesclean.API Node PR Checklist
Scope
Pricing & Billing
If Need pricing update:
QA
Comms