Skip to content

Conversation

@bsbodden
Copy link
Contributor

Add sort_by parameter to FilterQuery in all list/alist implementations
to return checkpoints in descending order (newest first). This matches
SQLite checkpointer behavior and enables efficient lookup of recent/
crashed sessions without fetching all checkpoints into memory.

Updated implementations:

  • AsyncRedisSaver.alist() (aio.py:709)
  • RedisSaver.list() (init.py:279)
  • AsyncShallowRedisSaver.alist() (ashallow.py:384)
  • ShallowRedisSaver.list() (shallow.py:334)

BREAKING CHANGE: Checkpoints are now returned in DESC order (newest
first) instead of ASC order (oldest first). Code that accessed the
most recent checkpoint with list(saver.list(config))[-1] must now
use list(saver.list(config))[0].

Fixes #106

  Add sort_by parameter to FilterQuery in all list/alist implementations
  to return checkpoints in descending order (newest first). This matches
  SQLite checkpointer behavior and enables efficient lookup of recent/
  crashed sessions without fetching all checkpoints into memory.

  Updated implementations:
  - AsyncRedisSaver.alist() (aio.py:709)
  - RedisSaver.list() (__init__.py:279)
  - AsyncShallowRedisSaver.alist() (ashallow.py:384)
  - ShallowRedisSaver.list() (shallow.py:334)

  BREAKING CHANGE: Checkpoints are now returned in DESC order (newest
  first) instead of ASC order (oldest first). Code that accessed the
  most recent checkpoint with `list(saver.list(config))[-1]` must now
  use `list(saver.list(config))[0]`.

  Fixes #106
@bsbodden bsbodden requested review from abrookins and Copilot October 21, 2025 15:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements descending sort order for checkpoint listings by checkpoint ID, ensuring the newest checkpoints appear first in all Redis checkpoint implementations. This change aligns with SQLite checkpointer behavior and enables efficient retrieval of recent or crashed sessions without loading all checkpoints into memory.

Key Changes:

  • Added sort_by=("checkpoint_id", "DESC") parameter to FilterQuery in list/alist methods
  • Updated test assertions to access the first element (newest) instead of the last element (oldest)
  • Added comprehensive test coverage for sort order behavior across multiple scenarios

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
langgraph/checkpoint/redis/init.py Added DESC sort parameter to RedisSaver.list() FilterQuery
langgraph/checkpoint/redis/aio.py Added DESC sort parameter to AsyncRedisSaver.alist() FilterQuery
langgraph/checkpoint/redis/shallow.py Added DESC sort parameter to ShallowRedisSaver.list() FilterQuery
langgraph/checkpoint/redis/ashallow.py Added DESC sort parameter to AsyncShallowRedisSaver.alist() FilterQuery
tests/test_streaming.py Updated test assertions to access newest checkpoint at index [0] instead of [-1]
tests/test_alist_sort_order.py Added new comprehensive test suite validating DESC sort order for both sync and async implementations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@bsbodden bsbodden requested review from Copilot and removed request for abrookins October 21, 2025 15:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@bsbodden bsbodden merged commit 62fd939 into main Oct 21, 2025
19 checks passed
@bsbodden bsbodden deleted the bsb/issue-106 branch October 21, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make alist sort by checkpoint ID DESC

2 participants