[PR #4408] Graph visualization fix #3805

Closed
opened 2026-02-20 17:49:11 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/4408

State: closed
Merged: No


Related to #4394

Fix for Unexpected Conditional Edges in Graph Visualization

Issue Description

This PR addresses a regression introduced in v0.3.32 where the graph visualization incorrectly added unexpected conditional edges to the END node. Specifically, nodes that had conditional outgoing edges to other nodes were erroneously receiving an additional conditional edge to END in the Mermaid visualization, even though no such edge was defined in the graph structure.

Root Cause

The issue was in the draw_graph function in langgraph/pregel/draw.py, where the code was adding conditional edges to END for all nodes in step_sources (nodes with conditional edges) that weren't in termini (terminal nodes):

for src in sorted(termini.union(step_sources)):
    graph.add_edge(graph.nodes[src], end, conditional=src not in termini)

This meant any node with conditional outgoing edges would incorrectly receive an automatic conditional edge to END.

Fix

This PR modifies the edge creation logic to:

  1. Only add non-conditional edges from terminal nodes to END
  2. Only add conditional edges to END when they are explicitly defined in the graph structure
  3. Properly identify and handle any explicitly defined conditional routes to END

Tests Added

Comprehensive tests were added in test_conditional_edges_visualization.py to:

  • Verify nodes with conditional edges do not incorrectly receive an edge to END
  • Document that explicitly defined conditional edges to END aren't shown (current limitation)
  • Test mixed graphs with both terminal nodes and conditional edges to END

Notes

  • The fix preserves the current behavior where terminal nodes (with no outgoing edges) receive a non-conditional edge to END
  • The test docstrings document a current limitation: explicit conditional edges to END aren't displayed in the Mermaid visualization, which could be addressed in a future update

This change restores the visualization behavior to match v0.3.31, ensuring that Mermaid diagrams accurately represent the graph structure without unexpected edges.

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/4408 **State:** closed **Merged:** No --- Related to #4394 # Fix for Unexpected Conditional Edges in Graph Visualization ## Issue Description This PR addresses a regression introduced in v0.3.32 where the graph visualization incorrectly added unexpected conditional edges to the END node. Specifically, nodes that had conditional outgoing edges to other nodes were erroneously receiving an additional conditional edge to END in the Mermaid visualization, even though no such edge was defined in the graph structure. ## Root Cause The issue was in the `draw_graph` function in `langgraph/pregel/draw.py`, where the code was adding conditional edges to END for all nodes in `step_sources` (nodes with conditional edges) that weren't in `termini` (terminal nodes): ```python for src in sorted(termini.union(step_sources)): graph.add_edge(graph.nodes[src], end, conditional=src not in termini) ``` This meant any node with conditional outgoing edges would incorrectly receive an automatic conditional edge to END. ## Fix This PR modifies the edge creation logic to: 1. Only add non-conditional edges from terminal nodes to END 2. Only add conditional edges to END when they are explicitly defined in the graph structure 3. Properly identify and handle any explicitly defined conditional routes to END ## Tests Added Comprehensive tests were added in `test_conditional_edges_visualization.py` to: - Verify nodes with conditional edges do not incorrectly receive an edge to END - Document that explicitly defined conditional edges to END aren't shown (current limitation) - Test mixed graphs with both terminal nodes and conditional edges to END ## Notes - The fix preserves the current behavior where terminal nodes (with no outgoing edges) receive a non-conditional edge to END - The test docstrings document a current limitation: explicit conditional edges to END aren't displayed in the Mermaid visualization, which could be addressed in a future update This change restores the visualization behavior to match v0.3.31, ensuring that Mermaid diagrams accurately represent the graph structure without unexpected edges.
yindo added the pull-request label 2026-02-20 17:49:11 -05:00
yindo closed this issue 2026-02-20 17:49:11 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#3805