Nodes/ComfyUI-DAELab-Custom-Nodes-Library/Badge Lazy Image Switch V1
ComfyUI Node

Badge Lazy Image Switch V1

An A/B image switch that refuses to run the branch you didn't pick

By TeutonicMepheles·Created 4 months ago·Updated 3 days ago· 0
Badge Lazy Image Switch V1
  • false_image
  • true_image
  • image
  • status
◄conditionfalse►

What this is for

ComfyUI is full of image switches. Most of them share one flaw: both branches upstream of the switch get executed, because the engine only knows a node is needed if a wire points at it. If one of those branches is a paid API call, or a 40-second local render, you've just paid for the branch you switched away from.

Badge Lazy Image Switch V1 doesn't do that. It's a boolean A/B image switch built on the V3 lazy-input contract: it declares which input it wants at execution time, based on the condition, so the branch that loses is never evaluated. Flip the boolean and the expensive side simply doesn't run.

This is the plain-vanilla member of the DAELab router family - no badge assumptions, no 1024 canvas check, no mask validation. If you want a switch that also validates a route and hands you a support mask, that's Badge Entry Route V1. If you just want "run the cheap path unless I say otherwise", this is it.

How it works

The schema declares condition as a boolean, then false_image and true_image as lazy, optional image inputs. That combination is the trick. check_lazy_status looks at condition, and if the selected input's value is still None, returns just that one name. ComfyUI evaluates that branch and only that branch, then calls execute again.

execute picks true_image when the condition is set, false_image when it isn't, and raises The selected lazy image input is unavailable. if the chosen one is missing. So a switch with an unwired input isn't a silent None downstream - it fails loudly at the switch, naming the problem.

The output is the selected tensor unchanged, plus a small status JSON - {"selected":"true_image"} or {"selected":"false_image"} - which sounds trivial until you're looking at a saved workflow six hours later trying to remember which side was live.

The mechanics underneath are the ones comfyui-node-plumbing.md lays out: unconnected optional inputs arrive as nothing, the engine caches aggressively, and a node can influence what gets executed only by declaring its needs up front. Lazy inputs are the modern, sanctioned version of that, and they're much less hostile to the cache than the old float("NaN") always-rerun hack.

The inputs and outputs

  • condition - boolean, default false. This is the one you convert to an input or drive from another boolean node.
  • false_image - lazy, optional. Taken when the condition is false.
  • true_image - lazy, optional. Taken when the condition is true.

Outputs: image and status.

Both image inputs being optional means a half-wired switch still loads and still renders - that's convenient while building and a quiet trap once you ship it, because only the branch you happen to be on gets checked.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/TeutonicMepheles/ComfyUI-DAELab-Custom-Nodes-Library.git
# restart ComfyUI

This one is a pure V3 node, so it needs a ComfyUI core that ships comfy_api.latest. Because the class is defined inside an if comfy_io is not None: guard, an older core doesn't crash the pack - the node just isn't there. That's a confusing failure mode: everything else from the pack shows up, one node silently doesn't. If Badge Lazy Image Switch V1 is missing from the search while its siblings exist, update ComfyUI instead of hunting for a pip package.

Where people get burned

Assuming "lazy" means "never cached". It means not executed, which is what saves the money. The switch itself still caches like any node, and it re-runs when condition changes. That's correct - just don't expect it to force re-render a branch whose inputs didn't change.

A condition driven from a widget you didn't convert. Every switch tutorial says it and every switch gets it wrong once: a widget value isn't a wire. Right-click → Convert to input if you want something else to drive it.

Leaving both inputs unwired while testing. Loads fine, errors at run time with the message above. If that error surprises you, it's because the branch you weren't on was the one you'd forgotten to connect.

Using it as a mask or text switch. It's image-only, no * wildcard socket. For other types you want a different switch node; the pack's other routers each handle their own specific types.

If you need branch selection to also avoid re-running a validation chain, note this node only gates evaluation of the two image inputs - anything you've wired into the condition itself is still evaluated. Keep the cheap logic on the condition side, the expensive logic on the branches.

CategoryDAELab/Badge/App

Inputs (3)

NameTypeDefaultDescription
conditionBOOLEANfalse—
false_imageoptIMAGE—
true_imageoptIMAGE—

Outputs (2)

NameTypeDescription
imageIMAGE—
statusSTRING—