MemorySaver doesn't store checkpoints in descending order by timestamp #126

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

Originally created by @labdmitriy on GitHub (Jun 23, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

from pprint import pprint

from langgraph.checkpoint.memory import MemorySaver
from langgraph.graph import StateGraph

builder = StateGraph(int)
builder.add_node("add_one", lambda x: x + 1)
builder.set_entry_point("add_one")
builder.set_finish_point("add_one")

memory = MemorySaver()
graph = builder.compile(checkpointer=memory)
config = {"configurable": {"thread_id": "thread-1"}}

pprint(graph.invoke(1, config))
pprint(list(graph.get_state_history(config)))
pprint(list(memory.list(config)))
print(memory.list.__doc__)

Error Message and Stack Trace (if applicable)

No response

Description

  • I'm trying to reproduce the example from the home page of the LangGraph documentation
  • I expect to see that MemorySaver stores checkpoints in descending order by timestamp as described in the docstring of the list method
  • Instead, it is not stored in descending order by timestamp, but probably insertion order of defaultdict is used, because MemorySaver's storage is currently based on defaultdict and there is no explicit sorting of the states (which is used, for example, by SqliteSaver)

System Info

Package Information

langchain_core: 0.2.9
langchain: 0.2.5
langchain_community: 0.2.5
langsmith: 0.1.81
langchain_experimental: 0.0.61
langchain_text_splitters: 0.2.1
langchainhub: 0.1.20
langgraph: 0.1.1
langserve: 0.2.2

Originally created by @labdmitriy on GitHub (Jun 23, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangGraph/LangChain rather than my code. - [X] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. ### Example Code ```python from pprint import pprint from langgraph.checkpoint.memory import MemorySaver from langgraph.graph import StateGraph builder = StateGraph(int) builder.add_node("add_one", lambda x: x + 1) builder.set_entry_point("add_one") builder.set_finish_point("add_one") memory = MemorySaver() graph = builder.compile(checkpointer=memory) config = {"configurable": {"thread_id": "thread-1"}} pprint(graph.invoke(1, config)) pprint(list(graph.get_state_history(config))) pprint(list(memory.list(config))) print(memory.list.__doc__) ``` ### Error Message and Stack Trace (if applicable) _No response_ ### Description - I'm trying to reproduce the [example](https://langchain-ai.github.io/langgraph/#example) from the home page of the LangGraph documentation - I expect to see that `MemorySaver` stores checkpoints in descending order by timestamp as described in the [docstring](https://github.com/langchain-ai/langgraph/blob/main/libs/langgraph/langgraph/checkpoint/memory.py#L101) of the `list` method - Instead, it is not stored in descending order by timestamp, but probably insertion order of `defaultdict` is used, because MemorySaver's storage is currently based on `defaultdict` and there is no explicit sorting of the states (which is used, for example, by [SqliteSaver](https://github.com/langchain-ai/langgraph/blob/73e39fcba962aa23ba7740ad69ee407aeaa41fb5/libs/langgraph/langgraph/checkpoint/sqlite.py#L324-L327)) ### System Info Package Information ------------------- > langchain_core: 0.2.9 > langchain: 0.2.5 > langchain_community: 0.2.5 > langsmith: 0.1.81 > langchain_experimental: 0.0.61 > langchain_text_splitters: 0.2.1 > langchainhub: 0.1.20 > langgraph: 0.1.1 > langserve: 0.2.2
yindo closed this issue 2026-02-20 17:27:24 -05:00
Author
Owner

@hinthornw commented on GitHub (Jul 8, 2024):

Acknowledged. It indeed is saving them in insertion order

@hinthornw commented on GitHub (Jul 8, 2024): Acknowledged. It indeed is saving them in insertion order
Author
Owner

@nfcampos commented on GitHub (Aug 23, 2024):

This has been fixed

@nfcampos commented on GitHub (Aug 23, 2024): This has been fixed
Author
Owner

@labdmitriy commented on GitHub (Aug 26, 2024):

@hinthornw @nfcampos Thank you!

Then probably here is the wrong (ascending) order of the states in the history:
https://langchain-ai.github.io/langgraph/how-tos/human_in_the_loop/time-travel/#checking-history

@labdmitriy commented on GitHub (Aug 26, 2024): @hinthornw @nfcampos Thank you! Then probably here is the wrong (ascending) order of the states in the history: https://langchain-ai.github.io/langgraph/how-tos/human_in_the_loop/time-travel/#checking-history
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#126