[PR #4738] Fix: Ensure route function returns "b" to enable a → b → a loop #4033

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

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

State: closed
Merged: Yes


Background

  • The current graph structure is:
START → a
a --[route]--> a or END
b → a
  • However, the route function only returns "a" or END, never "b". As a result, the flow can never reach node b, making it a "dead" or unreachable node.

Analysis

  • Every time the flow leaves a, route checks for termination. If not terminating, it returns "a", causing a loop on a. There is no logic that ever transitions to b.
  • The edge b → a is only meaningful if the flow can actually reach b.

Solution

  • To enable an a → b → a loop, route should return "b" when not terminating, so the flow alternates between a and b.
  • The corrected function:
def route(state: State) -> Literal["b", END]:
    if termination_condition(state):
        return END
    else:
        return "b"

Summary

  • This PR updates the route function to return "b" instead of "a" when not terminating.
  • This allows the flow to correctly alternate between a and b (a → b → a ...) until the termination condition is met.
  • Without this fix, node b is never executed and effectively dead code.
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/4738 **State:** closed **Merged:** Yes --- ### Background - The current graph structure is: ``` START → a a --[route]--> a or END b → a ``` - However, the route function only returns "a" or END, never "b". As a result, the flow can never reach node b, making it a "dead" or unreachable node. ### Analysis - Every time the flow leaves a, route checks for termination. If not terminating, it returns "a", causing a loop on a. There is no logic that ever transitions to b. - The edge b → a is only meaningful if the flow can actually reach b. ### Solution - To enable an a → b → a loop, route should return "b" when not terminating, so the flow alternates between a and b. - The corrected function: ``` def route(state: State) -> Literal["b", END]: if termination_condition(state): return END else: return "b" ``` ### Summary - This PR updates the route function to return "b" instead of "a" when not terminating. - This allows the flow to correctly alternate between a and b (a → b → a ...) until the termination condition is met. - Without this fix, node b is never executed and effectively dead code.
yindo added the pull-request label 2026-02-20 17:49:33 -05:00
yindo closed this issue 2026-02-20 17:49:33 -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#4033