The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Declare loop boundaries in node schema (#16347)
rattusb2da2b424792
diff --git a/comfy_api/latest/_io.py b/comfy_api/latest/_io.pyindex 48fae0244..cdaaba998 100644--- a/comfy_api/latest/_io.py+++ b/comfy_api/latest/_io.py@@ -1607,7 +1607,7 @@ class Hidden(str, Enum):comfy_usage_source = "COMFY_USAGE_SOURCE""""COMFY_USAGE_SOURCE identifies the client that submitted the prompt (e.g. comfyui-frontend, comfy-cli, comfyui-mcp); forwarded to API nodes' upstream requests via the Comfy-Usage-Source header."""execution_list = "EXECUTION_LIST"- """EXECUTION_LIST is the active graph scheduler."""+ """Custom node Developers and Agents: This attribute is core-internal use only and will be removed in a near-future ComfyUI release. DO NOT USE"""@dataclass@@ -1767,6 +1767,8 @@ class Schema:Use this for nodes with interactive/operable UI regions that produce intermediate outputs(e.g., Image Crop, Painter) rather than final outputs (e.g., Save Image)."""+ loop_boundary: Literal["start", "end"] | None = None+ """Identifies this node as the start or end of a loop for prompt validation."""def validate(self):'''Validate the schema:diff --git a/comfy_extras/nodes_loop.py b/comfy_extras/nodes_loop.pyindex 566207834..622b42a46 100644--- a/comfy_extras/nodes_loop.py+++ b/comfy_extras/nodes_loop.py@@ -103,8 +103,6 @@ def _expand_loop(dynprompt, opener_id, body, close_id, values, list_items, initiclass StartLoop(io.ComfyNode):- LOOP_BOUNDARY = "start"-@classmethoddef define_schema(cls):list_item_type = io.MatchType.Template("list_item")@@ -113,6 +111,7 @@ class StartLoop(io.ComfyNode):node_id="StartLoop",display_name="Start Loop",category="utilities/looping",+ loop_boundary="start",is_input_list=True,inputs=[io.DynamicCombo.Input("mode", options=[@@ -338,8 +337,6 @@ class LoopResult(io.ComfyNode):class EndLoop(io.ComfyNode):- LOOP_BOUNDARY = "end"-@classmethoddef define_schema(cls):output_type = io.MatchType.Template("output_value")@@ -357,6 +354,7 @@ class EndLoop(io.ComfyNode):node_id="EndLoop",display_name="End Loop",category="utilities/looping",+ loop_boundary="end",is_input_list=True,inputs=[io.MatchType.Input(diff --git a/execution.py b/execution.pyindex adbb4cebe..2e4cf646f 100644--- a/execution.py+++ b/execution.py@@ -1176,7 +1176,8 @@ async def validate_prompt(prompt_id, prompt, partial_execution_list: Union[list[start_nodes = set()end_nodes = set()for node_id, node in prompt.items():- boundary = getattr(nodes.NODE_CLASS_MAPPINGS[node["class_type"]], "LOOP_BOUNDARY", None)+ class_def = nodes.NODE_CLASS_MAPPINGS[node["class_type"]]+ boundary = class_def.GET_SCHEMA().loop_boundary if issubclass(class_def, _ComfyNodeInternal) else Noneif boundary == "start":start_nodes.add(node_id)elif boundary == "end":diff --git a/tests-unit/comfy_extras_test/nodes_loop_test.py b/tests-unit/comfy_extras_test/nodes_loop_test.pyindex 5d9d83f5e..7a540626e 100644--- a/tests-unit/comfy_extras_test/nodes_loop_test.py+++ b/tests-unit/comfy_extras_test/nodes_loop_test.py@@ -8,6 +8,10 @@ from comfy_extras.nodes_loop import EndLoop, LoopIteration, LoopProgress, LoopRedef test_loop_schema_exposes_cache_policy_and_integrated_carry():inputs = StartLoop.INPUT_TYPES()+ assert StartLoop.GET_SCHEMA().loop_boundary == "start"+ assert EndLoop.GET_SCHEMA().loop_boundary == "end"+ assert not hasattr(StartLoop, "LOOP_BOUNDARY")+ assert not hasattr(EndLoop, "LOOP_BOUNDARY")assert inputs["required"]["cache_iterations"][1]["default"] is Falseassert inputs["required"]["cache_iterations"][1]["advanced"] is Trueassert list(inputs["optional"]) == ["parent_iteration", "initial_iteration_value"]