[langgraph]: graph.get_state_history(config) cannot output the complete snapshot history #1003

Closed
opened 2026-02-20 17:42:41 -05:00 by yindo · 3 comments
Owner

Originally created by @wanjundegithub on GitHub (Oct 9, 2025).

Type of issue

issue / bug

Language

Python

Description

`class State(TypedDict):
foo:str
bar:Annotated[list[str], add]

def node_a(state:State):
return {"foo":"a", "bar":["a"]}

def node_b(state:State):
return {"foo":"b", "bar":["b"]}

persistence_builder = StateGraph(State)
persistence_builder.add_edge(START, "node_a")
persistence_builder.add_node(node_a)
persistence_builder.add_node(node_b)
persistence_builder.add_edge("node_a", "node_b")
persistence_builder.add_edge("node_b", END)

check_pointer = InMemorySaver()
persistence_graph = persistence_builder.compile(checkpointer=check_pointer)

config:RunnableConfig = {"configurable": {"thread_id": "1"}}

state = persistence_graph.invoke({"foo":""}, config)

print(list(persistence_graph.get_state_history(config)))
`

output: [StateSnapshot(values={'foo': 'b', 'bar': ['a', 'b']}, next=(), config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f508-6445-8002-701f70e8f22a'}}, metadata={'source': 'loop', 'step': 2, 'parents': {}}, created_at='2025-10-10T03:21:44.486179+00:00', parent_config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4f8-67af-8001-ce8aef2b5253'}}, tasks=(), interrupts=()), StateSnapshot(values={'foo': 'a', 'bar': ['a']}, next=('node_b',), config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4f8-67af-8001-ce8aef2b5253'}}, metadata={'source': 'loop', 'step': 1, 'parents': {}}, created_at='2025-10-10T03:21:44.479705+00:00', parent_config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4e7-6fb6-8000-87ba2ef2d74a'}}, tasks=(PregelTask(id='102ccb05-ebba-0be7-a94a-43774140780c', name='node_b', path=('__pregel_pull', 'node_b'), error=None, interrupts=(), state=None, result={'foo': 'b', 'bar': ['b']}),), interrupts=()), StateSnapshot(values={'foo': '', 'bar': []}, next=('node_a',), config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4e7-6fb6-8000-87ba2ef2d74a'}}, metadata={'source': 'loop', 'step': 0, 'parents': {}}, created_at='2025-10-10T03:21:44.472932+00:00', parent_config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4e3-640a-bfff-8ec73f5fda2a'}}, tasks=(PregelTask(id='bb822f24-ead6-bb34-ad7a-bae03c77ac0f', name='node_a', path=('__pregel_pull', 'node_a'), error=None, interrupts=(), state=None, result={'foo': 'a', 'bar': ['a']}),), interrupts=()), StateSnapshot(values={'bar': []}, next=('start',), config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4e3-640a-bfff-8ec73f5fda2a'}}, metadata={'source': 'input', 'step': -1, 'parents': {}}, created_at='2025-10-10T03:21:44.471016+00:00', parent_config=None, tasks=(PregelTask(id='e406c385-4665-8ad2-ed2c-4fb5200cc0bb', name='start', path=('__pregel_pull', 'start'), error=None, interrupts=(), state=None, result={'foo': ''}),), interrupts=())]
Client disconnected

only this code works:
for event in persistence_graph.stream({"foo": ""}, config): if isinstance(event, dict): for node_name, result in event.items(): print(f"Node: {node_name}") print("Partial:", result) print("Merged:", persistence_graph.get_state(config).values) print("-----")

Originally created by @wanjundegithub on GitHub (Oct 9, 2025). ### Type of issue issue / bug ### Language Python ### Description `class State(TypedDict): foo:str bar:Annotated[list[str], add] def node_a(state:State): return {"foo":"a", "bar":["a"]} def node_b(state:State): return {"foo":"b", "bar":["b"]} persistence_builder = StateGraph(State) persistence_builder.add_edge(START, "node_a") persistence_builder.add_node(node_a) persistence_builder.add_node(node_b) persistence_builder.add_edge("node_a", "node_b") persistence_builder.add_edge("node_b", END) check_pointer = InMemorySaver() persistence_graph = persistence_builder.compile(checkpointer=check_pointer) config:RunnableConfig = {"configurable": {"thread_id": "1"}} state = persistence_graph.invoke({"foo":""}, config) print(list(persistence_graph.get_state_history(config))) ` output: [StateSnapshot(values={'foo': 'b', 'bar': ['a', 'b']}, next=(), config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f508-6445-8002-701f70e8f22a'}}, metadata={'source': 'loop', 'step': 2, 'parents': {}}, created_at='2025-10-10T03:21:44.486179+00:00', parent_config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4f8-67af-8001-ce8aef2b5253'}}, tasks=(), interrupts=()), StateSnapshot(values={'foo': 'a', 'bar': ['a']}, next=('node_b',), config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4f8-67af-8001-ce8aef2b5253'}}, metadata={'source': 'loop', 'step': 1, 'parents': {}}, created_at='2025-10-10T03:21:44.479705+00:00', parent_config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4e7-6fb6-8000-87ba2ef2d74a'}}, tasks=(PregelTask(id='102ccb05-ebba-0be7-a94a-43774140780c', name='node_b', path=('__pregel_pull', 'node_b'), error=None, interrupts=(), state=None, result={'foo': 'b', 'bar': ['b']}),), interrupts=()), StateSnapshot(values={'foo': '', 'bar': []}, next=('node_a',), config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4e7-6fb6-8000-87ba2ef2d74a'}}, metadata={'source': 'loop', 'step': 0, 'parents': {}}, created_at='2025-10-10T03:21:44.472932+00:00', parent_config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4e3-640a-bfff-8ec73f5fda2a'}}, tasks=(PregelTask(id='bb822f24-ead6-bb34-ad7a-bae03c77ac0f', name='node_a', path=('__pregel_pull', 'node_a'), error=None, interrupts=(), state=None, result={'foo': 'a', 'bar': ['a']}),), interrupts=()), StateSnapshot(values={'bar': []}, next=('__start__',), config={'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1f0a5883-f4e3-640a-bfff-8ec73f5fda2a'}}, metadata={'source': 'input', 'step': -1, 'parents': {}}, created_at='2025-10-10T03:21:44.471016+00:00', parent_config=None, tasks=(PregelTask(id='e406c385-4665-8ad2-ed2c-4fb5200cc0bb', name='__start__', path=('__pregel_pull', '__start__'), error=None, interrupts=(), state=None, result={'foo': ''}),), interrupts=())] Client disconnected only this code works: `for event in persistence_graph.stream({"foo": ""}, config): if isinstance(event, dict): for node_name, result in event.items(): print(f"Node: {node_name}") print("Partial:", result) print("Merged:", persistence_graph.get_state(config).values) print("-----") `
yindo closed this issue 2026-02-20 17:42:41 -05:00
Author
Owner

@casparb commented on GitHub (Oct 14, 2025):

Hi @wanjundegithub, I'm not sure what you are asking? The complete state history is included in the output you pasted above. get_state_history(config) returns a list of StateSnapshot objects in order from newest to the oldest. I'm not sure what you mean when you say "only this code works". Closing this issue as expected behavior, but if you're still having issues, tag me in a reply on this thread explaining your problem in more detail and I would be happy to help.

@casparb commented on GitHub (Oct 14, 2025): Hi @wanjundegithub, I'm not sure what you are asking? The complete state history is included in the output you pasted above. `get_state_history(config)` returns a list of `StateSnapshot` objects in order from newest to the oldest. I'm not sure what you mean when you say "only this code works". Closing this issue as expected behavior, but if you're still having issues, tag me in a reply on this thread explaining your problem in more detail and I would be happy to help.
Author
Owner

@wanjundegithub commented on GitHub (Oct 14, 2025):

Hi @casparb , Thanks, I got it. It returns an Iterator[StateSnapshot], so we have to iterate over the data.

@wanjundegithub commented on GitHub (Oct 14, 2025): Hi @casparb , Thanks, I got it. It returns an Iterator[StateSnapshot], so we have to iterate over the data.
Author
Owner

@casparb commented on GitHub (Oct 15, 2025):

Aha @wanjundegithub yes it returns an iterator not a list, you're right. You can use list(graph.get_state_history(config) to turn it into a list.

@casparb commented on GitHub (Oct 15, 2025): Aha @wanjundegithub yes it returns an iterator not a list, you're right. You can use `list(graph.get_state_history(config)` to turn it into a list.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#1003