diff --git a/libs/checkpoint/langgraph/store/base/batch.py b/libs/checkpoint/langgraph/store/base/batch.py index 0a4a0eef7..64019d68f 100644 --- a/libs/checkpoint/langgraph/store/base/batch.py +++ b/libs/checkpoint/langgraph/store/base/batch.py @@ -328,6 +328,9 @@ async def _run( store: weakref.ReferenceType[BaseStore], ) -> None: while item := await aqueue.get(): + # don't run batch if the future is done (e.g. cancelled) + if item[0].done(): + continue # check if store is still alive if s := store(): try: @@ -335,6 +338,9 @@ async def _run( items = [item] try: while item := aqueue.get_nowait(): + # don't insert if the future is done (e.g. cancelled) + if item[0].done(): + continue items.append(item) except asyncio.QueueEmpty: pass