Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions comfy_cli/cql/promoted.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,15 @@ def deepest_source(sg: dict, pi: PromotedInput, defs: dict[str, dict]) -> tuple[
path.append(current.source_node)
if not current.nested:
return path, str(current.source_widget)
inner = next((n for n in current_sg.get("nodes") or [] if str(n.get("id")) == current.source_node), None)
nodes = current_sg.get("nodes")
inner = next(
(
n
for n in (nodes if isinstance(nodes, list) else [])
if isinstance(n, dict) and str(n.get("id")) == current.source_node
),
None,
)
inner_def = defs.get(str(inner.get("type", ""))) if inner is not None else None
if inner_def is None or current.source_input is None:
return None
Expand Down Expand Up @@ -2186,10 +2194,8 @@ def flush_proxy_migration(
return report


def boundary_widget_targets(sg: dict, pi: PromotedInput, defs: dict[str, dict]) -> list[tuple[list[str], str]]:
"""Every concrete ``(interior node path, widget)`` a promoted input feeds —
all of its boundary links, through nested instances. A repaired primitive
fan-out has several; :func:`deepest_source` reports only the first."""
def boundary_targets(sg: dict, pi: PromotedInput, defs: dict[str, dict]) -> list[tuple[list[str], str]]:
"""Every ``(interior node path, input)`` the input's boundary links reach, sockets included."""
cache = getattr(defs, "promotion_boundaries", None)
cache_key = (id(sg), pi.index)
raw_inputs = sg.get("inputs")
Expand Down Expand Up @@ -2368,15 +2374,18 @@ def _boundary_targets(
)
out.extend(([tid, *path], widget) for path, widget in nested)
continue
# Unmarked sockets count too: the frontend inlines into any input the link reaches (resolveInput).
marker = entry.get("widget")
if marker:
_spend_traversal_budget(
_output_budget,
1,
"promoted widget boundary traversal exceeded its safe limit",
)
widget = marker.get("name") if isinstance(marker, dict) else None
out.append(([tid], str(widget or entry.get("name"))))
widget = marker.get("name") if isinstance(marker, dict) else None
name = widget or entry.get("name")
if name is None:
continue
_spend_traversal_budget(
_output_budget,
1,
"promoted widget boundary traversal exceeded its safe limit",
)
out.append(([tid], str(name)))
_memo[memo_key] = out
frozen_dependencies = frozenset(dependencies)
_dependency_memo[memo_key] = frozen_dependencies
Expand Down
41 changes: 31 additions & 10 deletions comfy_cli/workflow_to_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ def _overlay_promoted_host_values(api_prompt: dict, workflow: dict, subgraph_def
default, so a post-migration save (host prompt filled in, interior
``caption`` still ``''``) would submit the wrong prompt. Precedence, as the
frontend serializes it: a link feeding the instance input wins (already
reattached), else the host value when materialized, else the interior.
reattached), else the host value when materialized, else the interior
source widget's value. The chosen value goes to every interior input the
input feeds, plain sockets included (``ExecutableNodeDTO.resolveInput``).
Inner instances are visited first so an outer host wins over an inner one;
an inner input promoted further (linked from ``-10``) is left to the outer.
"""
Expand Down Expand Up @@ -289,24 +291,28 @@ def is_live(link_id: Any) -> bool:
continue
value = _promoted.host_value(instance, pi)
if value is _promoted.UNSET:
continue
# Every interior widget the input feeds — a repaired primitive
# fan-out links one host value into several targets.
targets = _promoted.boundary_widget_targets(sg, pi, subgraph_defs)
# No host value: the frontend seeds the promoted widget from its interior source widget.
if len(inner_nodes) + 1 > visit_budget[0]:
raise WorkflowConversionError("promoted-value overlay exceeded its safe limit")
visit_budget[0] -= len(inner_nodes) + 1
value = _source_widget_value(api_prompt, prefix, _promoted.deepest_source(sg, pi, subgraph_defs))
if value is _promoted.UNSET:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium — When the host has no value, the fallback reads the seed only from the already-emitted api_prompt. So if the source node is muted, bypassed, or failed _build_api_node, the value comes back UNSET and every plain-socket target (e.g. ComfySwitchNode.on_false) is left empty. That is the same 'encoder gets None' failure this PR fixes, and test_known_divergence_unemitted_source_leaves_the_socket_empty locks it in. Reading the emitted value also means a dynamicPrompts source like TextGenerate.prompt has already been through process_dynamic_prompt, so sockets get the processed string while the host branch writes the raw value. Seeding from the definition's interior widgets_values (as promoted.source_value does) would avoid both problems.

Raised by 3 of 6 reviewers (claude-opus-5-5-xhigh adversarial, claude-opus-5-5-xhigh edge-case, gpt-5.6-sol-xhigh edge-case).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that this diverges from the frontend; it is the Known limitation listed in the PR body. It needs both no saved instance value and a muted or bypassed source (or dynamic-prompt syntax in the source). Across the 735 shipped templates, all 15 socket-feeding inputs without a saved value resolve correctly through the emitted source. Seeding from the definition's raw widget value means threading object_info into the overlay to map widgets_values positionally. That is held for the maintainers' call rather than added here; it will be tracked if they keep it as a limitation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this as a known limitation, now listed in the PR description: with no saved instance value, a muted or bypassed source leaves sibling sockets empty, and a dynamic-prompt source reaches them processed. Neither occurs in any of the 735 templates, and before this change those sockets got nothing. Two test_known_divergence_* tests pin the current behaviour so a future fix shows up as a deliberate test change.

continue
else:
value = _wrap_widget_value(value)
targets = _promoted.boundary_targets(sg, pi, subgraph_defs)
if len(targets) > visit_budget[0]:
raise WorkflowConversionError("promoted-value overlay exceeded its safe limit")
visit_budget[0] -= len(targets)
for path, widget in targets:
for path, input_name in targets:
entry = api_prompt.get(":".join([prefix, *path]))
if not isinstance(entry, dict):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Low — Socket targets on interior nodes that aren't emitted are skipped silently. That covers a bypassed target (e.g. a bypassed ComfySwitchNode 484) and a legacy Reroute. The frontend passes the inlined value through the bypass or reroute to the downstream consumer (e.g. PreviewAny.source). Here, that consumer's orphaned boundary link is stripped and never filled, so it ends up missing a required input. The new 'every interior input the input feeds' guarantee doesn't hold on these paths: either follow bypassed/virtual nodes in _boundary_targets, or record this as a known divergence.

Raised by 1 of 6 reviewers (claude-opus-5-5-xhigh edge-case).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, a remaining gap rather than something this change introduces: widget targets on a bypassed or Reroute hop behaved the same before it. Listed as a Known limitation in the PR body; it will be tracked as a follow-up rather than widening this change into boundary traversal.

continue
inputs = entry.setdefault("inputs", {})
current = inputs.get(widget)
current = inputs.get(input_name)
if isinstance(current, list) and len(current) == 2:
continue # wired from inside the definition: the link wins
# Same wrapping every widget value gets, so a two-item list
# host value is never read back as a ``[node, slot]`` link.
inputs[widget] = _wrap_widget_value(value)
inputs[input_name] = value

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ Nit — The host value is now wrapped once outside the loop, and the fallback reuses the source entry's own object. As a result every target, and on the fallback path the source node itself, shares one dict or list. Any later in-place edit of one node's input would silently change its siblings. Wrapping or copying per target, as the old per-iteration _wrap_widget_value(value) did, keeps them isolated.

Raised by 1 of 6 reviewers (kimi-k3-high adversarial).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining. The overlay is the converter's last step, and nothing mutates input values after it: the prompt is serialized as-is. Sharing one wrapped value across targets is therefore observable only through in-place edits, and no such edit exists. Copying per target would add work on every fan-out for no behavioural difference.


for node in workflow.get("nodes") or []:
if not isinstance(node, dict):
Expand All @@ -317,6 +323,21 @@ def is_live(link_id: Any) -> bool:
visit(node, sg, workflow, str(node.get("id")), 0)


def _source_widget_value(api_prompt: dict, prefix: str, source: tuple[list[str], str] | None) -> Any:
from comfy_cli.cql import promoted as _promoted

if source is None:
return _promoted.UNSET
path, widget = source
entry = api_prompt.get(":".join([prefix, *path]))
inputs = entry.get("inputs") if isinstance(entry, dict) else None
if not isinstance(inputs, dict) or widget not in inputs:
return _promoted.UNSET
value = inputs[widget]
# Emitted widget values are wrapped, so a bare pair is a link: never fan it out.
return _promoted.UNSET if isinstance(value, list) and len(value) == 2 else value


def _has_group_nodes(workflow: dict) -> bool:
"""Legacy 'group nodes' (workflow> types) live under extra.groupNodes."""
extra = workflow.get("extra")
Expand Down
Loading
Loading