Skip to content

[bug]: Long node chains into an If branch raise RecursionError #9821

Closed

Description

@lstein

Is there an existing issue for this problem?

  • I have searched the existing issues

Version number

main at aa46003 (7.0.0-alpha.2-post); also on #9789

What happened

A chain of about 480 or more ordinary nodes between an Iterate and an If branch input makes GraphExecutionState.next() raise RecursionError: maximum recursion depth exceeded. The chain below uses 1000 nodes; 400 completes.

What you expected to happen

Graph length should not be limited by the Python recursion limit.

How to reproduce the problem

g = Graph()
g.add_node(CollectionConcatInvocation(id="conditions", first=[True, False]))
g.add_node(IterateInvocation(id="iterate"))
g.add_node(MarkedAnyTypeTestInvocation(id="false_branch", marker="f"))
g.add_node(IfInvocation(id="if"))
g.add_node(CollectInvocation(id="collect"))
g.add_edge(create_edge("conditions", "collection", "iterate", "collection"))
g.add_edge(create_edge("iterate", "item", "if", "condition"))
g.add_edge(create_edge("iterate", "item", "false_branch", "value"))
g.add_edge(create_edge("false_branch", "value", "if", "false_input"))
previous = ("iterate", "item")
for i in range(1000):
    g.add_node(AnyTypeTestInvocation(id=f"n{i}"))
    g.add_edge(create_edge(previous[0], previous[1], f"n{i}", "value"))
    previous = (f"n{i}", "value")
g.add_edge(create_edge(previous[0], previous[1], "if", "true_input"))
g.add_edge(create_edge("if", "value", "collect", "item"))

Additional context

The recursion is in graph_if_runtime._get_effective_iteration_paths_for_edge. It recurses once per unprepared upstream node while inferring an If's frames.

Under the real session processor the caller stack is deeper, so the practical limit is somewhat lower than in tests. An iterative walk (or memoising in topological order, as _get_frame_depths in #9789 does) would remove the limit.

Found while reviewing #9789.

Activity

  1. JPPhoto commented on Oct 18, 2026

    @JPPhoto
    Collaborator

    Resolved in PR #9843. Ordinary dependency traversal into an If branch is iterative, so the reported long AnyType chain completes. The exact 1,000-node regression test passed locally in the current main checkout (1 passed); CI also includes a lower-recursion-depth guard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions