Comfy-Org/ComfyUI · error · ValueError
node_id must be provided if not in executing context
Error message
node_id must be provided if not in executing context
What it means
comfy_api.latest's set_progress_bar / progress-reporting API needs to attribute progress to a node. It resolves node_id from the currently executing node's server-side context; when called outside execution (e.g. from a custom script, API request handler, or startup code) there is no executing context and no node_id argument, so it raises.
Source
Thrown at comfy_api/latest/__init__.py:55
value: float,
max_value: float,
node_id: str | None = None,
preview_image: Image.Image | ImageInput | None = None,
ignore_size_limit: bool = False,
) -> None:
"""
Update the progress bar displayed in the ComfyUI interface.
This function allows custom nodes and API calls to report their progress
back to the user interface, providing visual feedback during long operations.
Migration from previous API: comfy.utils.PROGRESS_BAR_HOOK
"""
executing_context = get_executing_context()
if node_id is None and executing_context is not None:
node_id = executing_context.node_id
if node_id is None:
raise ValueError("node_id must be provided if not in executing context")
# Convert preview_image to PreviewImageTuple if needed
to_display: PreviewImageTuple | Image.Image | ImageInput | None = preview_image
if to_display is not None:
# First convert to PIL Image if needed
if isinstance(to_display, ImageInput):
# Convert ImageInput (torch.Tensor) to PIL Image
# Handle tensor shape [B, H, W, C] -> get first image if batch
tensor = to_display
if len(tensor.shape) == 4:
tensor = tensor[0]
# Convert to numpy array and scale to 0-255
image_np = (tensor.cpu().numpy() * 255).astype(np.uint8)
to_display = Image.fromarray(image_np)
if isinstance(to_display, Image.Image):
# Detect image format from PIL ImageView on GitHub (pinned to 1c6d8d45b3)
Solutions
- Pass node_id explicitly: call the API with node_id='<the node being executed>' when outside the executing context
- Move the progress call inside the node's execute path so the executing context supplies node_id
- Guard the call: only report progress when get_executing_context() is not None or you have a real node_id
Example fix
// before
comfy_api.latest.set_progress_bar(0.5) # called from a thread, no context
# after
node_id = getattr(get_executing_context(), 'node_id', None)
if node_id is not None:
comfy_api.latest.set_progress_bar(0.5, node_id=node_id) Defensive patterns
Strategy: validation
Validate before calling
ctx = comfy_api.latest.get_executing_context()
if ctx is None and node_id is None:
skip_progress = True # not inside execution; do not report Prevention
- Always pass node_id explicitly in custom-node progress calls
- Only call progress APIs from within the node's execute function
When it happens
Trigger: Calling the progress/preview API (set_progress_bar-style function in comfy_api/latest/__init__.py) from code that runs outside a node execution — no get_executing_context() and node_id=None in kwargs.
Common situations: Custom nodes calling the progress hook in a background thread spawned at import time; API endpoint code reporting progress; migration from old comfy.utils.PROGRESS_BAR_HOOK usage that did not require node_id.
Related errors
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/22c88b1b63dee91c.
Report an issue: GitHub.