Skip to content

Mermaid output wiring ignores input-root output sources #263

@spinje

Description

@spinje

Summary

_connect_sources_to_output in src/pflow/core/workflow/mermaid/_io.py only recognizes node IDs as output source roots. When an output source references a workflow input (e.g., source: ${data.field} where data is a declared input), the output node renders with no incoming edge — disconnected in the diagram.

Root cause

_io.py:195-197:

for src_node, field in _SOURCE_NODE_FIELD_RE.findall(source):
    if src_node not in node_ids:
        continue  # Input names are silently dropped

_SOURCE_NODE_FIELD_RE captures name.field patterns. When src_node is a workflow input name (not a node ID), it's filtered out. The output node has no edge connecting it to the input.

Additionally, bare input references (source: ${data} without a dot) don't even match the regex (requires name.field format), so they're also disconnected.

Reproducer

from pflow.core.workflow.mermaid import generate_mermaid

ir = {
    "ir_version": "0.1.0",
    "nodes": [{"id": "process", "type": "shell", "params": {"command": "echo ${data.field}"}}],
    "inputs": {"data": {"type": "dict", "description": "Input data"}},
    "outputs": {"result": {"source": "${data.field}"}},
}

print(generate_mermaid(ir))
# Output node "result" has no incoming edge — should connect from input "data"

Fix direction

In _connect_sources_to_output, when src_node not in node_ids, check if it's in the workflow inputs. If so, connect the output to the corresponding input parallelogram node instead of skipping.

Discovered during

Code review of GH #247 fix (validator now allows input-root output sources). The validator and runtime handle these correctly, but Mermaid rendering was never updated to match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions