Skip to content

fix(graph): validate convergence targets in addParallelConditionalEdges#4455

Open
YuqiGuo105 wants to merge 1 commit intoalibaba:mainfrom
YuqiGuo105:fix/parallel-conditional-edge-convergence-validation-4411
Open

fix(graph): validate convergence targets in addParallelConditionalEdges#4455
YuqiGuo105 wants to merge 1 commit intoalibaba:mainfrom
YuqiGuo105:fix/parallel-conditional-edge-convergence-validation-4411

Conversation

@YuqiGuo105
Copy link
Copy Markdown

@YuqiGuo105 YuqiGuo105 commented Mar 23, 2026

Summary

Fixes #4411

When using addParallelConditionalEdges(), if different route branches' mapped nodes have edges pointing to different convergence targets, findParallelNodeTargets() returns a Set with multiple elements. HashSet.iterator().next() then silently picks one non-deterministically, causing the ConditionalParallelNode to route to an unpredictable next node after parallel execution.

Root Cause

In CompiledGraph constructor, when processing conditional parallel edges:

  1. findParallelNodeTargets() collects each route branch node's edge target into a Set<String>
  2. If node_a -> convergence and node_b -> some_other_node, the Set contains 2 elements
  3. parallelNodeTargets.iterator().next() picks whichever element HashSet happens to return first - this is non-deterministic

Fix

Added compile-time validation in CompiledGraph: when parallelNodeTargets.size() > 1, throw GraphStateException with a clear error message listing the conflicting convergence targets, rather than silently picking a random one.

This approach aligns with the issue reporter's suggestion: 'findParallelNodeTargets returns multiple targets should throw GraphStateException'

Changes

File Change
CompiledGraph.java Added size() > 1 validation check before iterator().next()
Errors.java Added inconsistentConvergenceTargetsOnConditionalParallelEdge error constant
StateGraphTest.java Added regression test with inconsistent convergence targets

Test

All 4 testAddParallelConditionalEdges* tests pass (BUILD SUCCESS).

…alEdges (alibaba#4411)

When using addParallelConditionalEdges, if different route branches' nodes
have edges pointing to different convergence targets, findParallelNodeTargets()
returns a Set with multiple elements. Previously, iterator().next() on a
HashSet would silently pick one non-deterministically, causing the
ConditionalParallelNode to route to an unpredictable next node.

This fix adds compile-time validation: when parallelNodeTargets.size() > 1,
a GraphStateException is thrown with a clear error message listing the
conflicting convergence targets.

Changes:
- CompiledGraph.java: Add size > 1 check before iterator().next()
- Errors.java: Add inconsistentConvergenceTargetsOnConditionalParallelEdge error
- StateGraphTest.java: Add test for inconsistent convergence targets

Closes alibaba#4411
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 23, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the area/graph SAA Grpah module label Mar 23, 2026
@YuqiGuo105 YuqiGuo105 changed the title fix(graph-core): validate convergence targets in addParallelConditionalEdges fix(graph): validate convergence targets in addParallelConditionalEdges Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/graph SAA Grpah module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] addParallelConditionalEdges — routeMap value 节点出边必须统一 convergence

2 participants