Nodes/BV Node Pack/BV LUT While End (Prototype internal)
ComfyUI Node

BV LUT While End (Prototype internal)

Re-running a subgraph

By BlackVortexAI·Created 8 months ago·Updated a day ago· 6
BV LUT While End (Prototype internal)
  • flow
  • initial_value0
  • loop_state
condition

Of all the "(Prototype internal)" nodes in BV Node Pack's LUT loop machinery, this one does the actual heavy lifting. BV LUT While End (Prototype internal) is the node that makes a loop loop: when the loop should continue, it clones the entire subgraph it's part of, re-runs it with the new state, and splices the result back in. That's not a metaphor - it literally builds a fresh graph mid-execution.

ComfyUI's graph executor evaluates nodes once per run; a while loop needs the same body evaluated many times with changing inputs. The pack fakes it by expanding: the While End reads the current graph, figures out which nodes are "inside" the loop, and asks ComfyUI to run a cloned copy of them, over and over, until the condition says stop. This is the same GraphBuilder/expand trick the community uses for more advanced control flow, and it's the reason Loop Start and Loop End can offer a genuine loop instead of a fixed-depth chain.

How it works

Inputs: flow (the FLOW_CONTROL signal from the while-start, marked rawLink so it can read the actual graph), condition (boolean), and initial_value0 (wildcard - the state to pass through when the loop ends). It also reads hidden dynprompt and unique_id inputs to see the surrounding graph.

  • If condition is false: it's done, and it passes initial_value0 through - that's the loop's final state flowing out to BV LUT Loop Result (Prototype internal).
  • If condition is true: it walks the graph dependencies from itself back to the while-start node, collects every node "contained" in the loop body, clones them into a fresh subgraph via GraphBuilder, feeds the next loop state back in as initial_value0 on the re-run, and returns the expansion. ComfyUI executes that expansion, the condition is checked again, and the process repeats until the plan is exhausted.

Output: loop_state (wildcard) - the accumulated state, either passed through at the end or cycling back for another iteration.

When you'd see it

In debug/legacy views of an expanded LUT loop, connecting BV LUT Loop Advance (Prototype internal)'s continue_loop boolean to this node's condition. Understanding it explains every "why does my loop run N+1 times" question: the loop iterates until the advance node reports the job index is past the plan.

How to install

Part of BV Node Pack:

cd ComfyUI/custom_nodes
git clone https://github.com/BlackVortexAI/bv_nodepack.git

Restart ComfyUI, hard-refresh. Or ComfyUI Manager → "BV Node Pack".

Common issues

  • Loop runs too many or too few times - trace the condition source: it comes from the advance node's continue_loop, which is true only while job_index < len(jobs). If the plan is empty or malformed, behavior gets weird - fix the plan, not the loop.
  • Recursion / stack traces mentioning Recurse - that's this node's clone machinery doing its job in an expanded run. If it errors, it's usually an input inside the loop body that doesn't survive cloning (a node that must run once but ended up inside the body). Keep one-shot setup nodes outside the loop.
  • Wiring it by hand - the rawLink flow and hidden dynprompt inputs are internal machinery; hand-wiring is how you get phantom nodes. Let Loop End build it.

It's genuinely clever machinery hiding behind a boring name - the kind of thing that quietly makes a feature possible that the platform didn't natively have.

Category__hidden__

Inputs (3)

NameTypeDefaultDescription
flowFLOW_CONTROL
conditionBOOLEAN
initial_value0opt*

Outputs (1)

NameTypeDescription
loop_state*