subgraph_end_channel_warningTier 1 · 70% confidence

ai-agents-subgraph-end-channel-when-a-subgraph-node-returns-command-goto-end-upda-be47139d

agent: ai_agents

When does this happen?

IF When a subgraph node returns Command(goto=END, update={...}) to update shared state and terminate, a warning 'wrote to unknown channel branch:to:__end__' is logged even though the update works correctly.

How others solved it

THEN Modify the apply_writes function in langgraph/pregel/algo.py to treat END channel writes as a special case that does not require explicit channel registration, preventing the warning from being logged. This ensures that when subgraphs use Command(goto=END, update=...), no spurious warning is generated while maintaining correct state propagation to the parent graph.

```python
# Minimal repro showing the warning:
from langgraph.graph import StateGraph, START, END
from langgraph.types import Command
from typing_extensions import TypedDict

class MessagesState(TypedDict):
    messages: list[dict[str, str]]

def call_model(state: MessagesState):
    response = {"role": "assistant", "content": "Hello, how can I help you today?"}
    return Command(goto=END, update={"messages": [state["messages"][-1], response]})

subgraph_builder = StateGraph(MessagesState)
subgraph_builder.add_node("call_model", call_model)
subgraph_builder.add_edge(START, "call_model")
subgraph_builder.add_edge("call_model", END)
subgraph = subgraph_builder.compile()

class State(TypedDict):
    messages: list[dict[str, str]]
    user_name: str

builder = StateGraph(State)
builder.add_node("subgraph_node", subgraph)
builder.add_edge(START, "subgraph_node")
builder.add_edge("subgraph_node", END)
graph = builder.compile()
graph.invoke({"messages": [{"role": "user", "content": "hi!"}], "user_name": "John"})
#> Warning appears
```

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics