langgraph
langgraph copied to clipboard
MemorySaver doesn't store checkpoints in descending order by timestamp
Checked other resources
- [X] I added a very descriptive title to this issue.
- [X] I searched the 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, 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 thelist
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 ondefaultdict
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