fix: AsyncRedisSaver cannot be constructed outside an async context (…#183
fix: AsyncRedisSaver cannot be constructed outside an async context (…#183
Conversation
There was a problem hiding this comment.
Pull request overview
Addresses Issue #179 by allowing Redis async checkpoint savers to be instantiated in synchronous code (no running event loop) and deferring event-loop capture until async setup.
Changes:
- Defer
loopinitialization inAsyncRedisSaver/AsyncShallowRedisSaverfrom__init__toasetup(). - Add explicit runtime errors when synchronous wrapper methods are called before
asetup()/async with. - Add regression tests covering construction outside an event loop and loop capture during
asetup().
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
langgraph/checkpoint/redis/aio.py |
Defers loop capture to asetup() and adds “must be set up” guards for sync wrappers. |
langgraph/checkpoint/redis/ashallow.py |
Same as above for shallow saver; adds “must be set up” guards for sync wrappers. |
tests/test_async.py |
Adds regression tests for AsyncRedisSaver construction outside a running loop and loop capture in asetup() / context manager. |
tests/test_shallow_async.py |
Adds analogous regression tests for AsyncShallowRedisSaver. |
Comments suppressed due to low confidence (1)
langgraph/checkpoint/redis/aio.py:1343
- The
InvalidStateErrorguidance here points users toawait checkpointer.get_channel_values(...), but that is the synchronous method name. This message should refer to the async API (e.g.,await checkpointer.aget_channel_values(...)) to avoid confusing users who hit this error.
raise asyncio.InvalidStateError(
"Synchronous calls to AsyncRedisSaver are only allowed from a "
"different thread. From the main thread, use the async interface."
"For example, use `await checkpointer.get_channel_values(...)`."
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Also addressed the suppressed low-confidence comment about the wrong method name in the |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
langgraph/checkpoint/redis/ashallow.py:827
- The
InvalidStateErrormessage is constructed from adjacent string literals and is missing a space after "use the async interface.", producing "interface.For example" at runtime. Add a space or merge the literals.
raise asyncio.InvalidStateError(
"Synchronous calls to AsyncShallowRedisSaver are only allowed from a "
"different thread. From the main thread, use the async interface."
"For example, use `await checkpointer.aget_channel_values(...)`."
)
langgraph/checkpoint/redis/ashallow.py:748
- This
InvalidStateErrormessage is split across string literals without a space after "use the async interface.", so it will display as "interface.For example". Add a trailing space to the first literal or combine them.
raise asyncio.InvalidStateError(
"Synchronous calls to AsyncShallowRedisSaver are only allowed from a "
"different thread. From the main thread, use the async interface."
"For example, use `await checkpointer.aget_tuple(...)` or `await "
"graph.ainvoke(...)`."
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
…#179)