diff --git a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py index f3d29c023..c9b9d3d45 100644 --- a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py +++ b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py @@ -469,7 +469,9 @@ class PostgresSaver(BasePostgresSaver): break payloads.reverse() - result[channel] = DiffChainValue(base=base, deltas=[p["d"] for p in payloads]) + result[channel] = DiffChainValue( + base=base, deltas=[p["d"] for p in payloads] + ) return result def _load_checkpoint_tuple(self, value: DictRow) -> CheckpointTuple: diff --git a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py index e8281cd8f..8e07248bf 100644 --- a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py +++ b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py @@ -430,7 +430,9 @@ class AsyncPostgresSaver(BasePostgresSaver): break payloads.reverse() - result[channel] = DiffChainValue(base=base, deltas=[p["d"] for p in payloads]) + result[channel] = DiffChainValue( + base=base, deltas=[p["d"] for p in payloads] + ) return result async def _load_checkpoint_tuple(self, value: DictRow) -> CheckpointTuple: diff --git a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/base.py b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/base.py index 4f7ec4226..82f1f5b59 100644 --- a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/base.py +++ b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/base.py @@ -208,7 +208,9 @@ class BasePostgresSaver(BaseCheckpointSaver[str]): if diff_channel_payloads: result.update( - self._load_diff_chains(thread_id, checkpoint_ns, diff_channel_payloads, cur=cur) + self._load_diff_chains( + thread_id, checkpoint_ns, diff_channel_payloads, cur=cur + ) ) return result diff --git a/libs/checkpoint/langgraph/checkpoint/memory/__init__.py b/libs/checkpoint/langgraph/checkpoint/memory/__init__.py index c0e646ae5..5fe5e0ca5 100644 --- a/libs/checkpoint/langgraph/checkpoint/memory/__init__.py +++ b/libs/checkpoint/langgraph/checkpoint/memory/__init__.py @@ -134,7 +134,7 @@ class InMemorySaver( continue vv = self.blobs[kk] if vv[0] == "diff": - diff_channels[k] = v + diff_channels[k] = str(v) elif vv[0] != "empty": channel_values[k] = self.serde.loads_typed(vv) @@ -163,7 +163,9 @@ class InMemorySaver( break vv = self.blobs[kk] if vv[0] == "diff": - payload = self.serde.loads_typed(vv) # {"d": [...], "p": version|None} + payload = self.serde.loads_typed( + vv + ) # {"d": [...], "p": version|None} chain_deltas.append(payload["d"]) version = payload["p"] else: diff --git a/libs/langgraph/tests/test_pregel.py b/libs/langgraph/tests/test_pregel.py index 8232ff0d7..84e68d653 100644 --- a/libs/langgraph/tests/test_pregel.py +++ b/libs/langgraph/tests/test_pregel.py @@ -9405,8 +9405,9 @@ def test_fork_does_not_apply_pending_writes( async def test_diff_channel_end_to_end_inmemory() -> None: """Full graph run: DiffChannel accumulates correctly across multiple turns.""" from langchain_core.messages import AIMessage, HumanMessage - from langgraph.channels.diff import DiffChannel from langgraph.checkpoint.memory import InMemorySaver + + from langgraph.channels.diff import DiffChannel from langgraph.graph import START, StateGraph from langgraph.graph.message import add_messages @@ -9446,8 +9447,9 @@ async def test_diff_channel_end_to_end_inmemory() -> None: async def test_diff_channel_time_travel() -> None: """Time-travel back to turn-1 checkpoint and resume; continuation must not include turn-2 deltas.""" from langchain_core.messages import AIMessage, HumanMessage - from langgraph.channels.diff import DiffChannel from langgraph.checkpoint.memory import InMemorySaver + + from langgraph.channels.diff import DiffChannel from langgraph.graph import START, StateGraph from langgraph.graph.message import add_messages @@ -9458,7 +9460,11 @@ async def test_diff_channel_time_travel() -> None: def respond(state: State) -> dict: counter["n"] += 1 - return {"messages": [AIMessage(content=f"ai-{counter['n']}", id=f"ai-{counter['n']}")]} + return { + "messages": [ + AIMessage(content=f"ai-{counter['n']}", id=f"ai-{counter['n']}") + ] + } builder = StateGraph(State) builder.add_node("respond", respond) @@ -9488,7 +9494,9 @@ async def test_diff_channel_time_travel() -> None: ) msgs = result["messages"] # Should be: h1, ai-1, h3, ai-N — 4 messages total - assert len(msgs) == 4, f"expected 4 messages after time-travel resume, got {len(msgs)}: {msgs}" + assert len(msgs) == 4, ( + f"expected 4 messages after time-travel resume, got {len(msgs)}: {msgs}" + ) assert msgs[0].content == "h1" assert msgs[1].content == "ai-1" assert msgs[2].content == "h3"