From 96023296e503c20ccf6701fea13615c5afa96c0f Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Wed, 29 Apr 2026 13:53:53 -0400 Subject: [PATCH] refactor: remove unnecessary variable extractions from checkpoint load paths Revert pure-style refactors (local variable hoisting, redundant null guards, Sequence/list annotation change) that cluttered the DeltaChannel PR diff without any semantic change. --- .../langgraph/checkpoint/postgres/__init__.py | 3 +- .../langgraph/checkpoint/postgres/aio.py | 17 ++----- .../langgraph/checkpoint/postgres/base.py | 3 +- .../langgraph/checkpoint/memory/__init__.py | 48 +++++++------------ 4 files changed, 23 insertions(+), 48 deletions(-) diff --git a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py index 5f3e04af7..cd2fb33de 100644 --- a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py +++ b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py @@ -491,7 +491,6 @@ class PostgresSaver(BasePostgresSaver): including its configuration, metadata, parent checkpoint (if any), and pending writes. """ - channel_values = self._load_blobs(value["channel_values"]) return CheckpointTuple( { "configurable": { @@ -504,7 +503,7 @@ class PostgresSaver(BasePostgresSaver): **value["checkpoint"], "channel_values": { **(value["checkpoint"].get("channel_values") or {}), - **channel_values, + **self._load_blobs(value["channel_values"]), }, }, value["metadata"], diff --git a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py index 9b0fd2100..bd3899f78 100644 --- a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py +++ b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py @@ -450,18 +450,11 @@ class AsyncPostgresSaver(BasePostgresSaver): including its configuration, metadata, parent checkpoint (if any), and pending writes. """ - thread_id = value["thread_id"] - checkpoint_ns = value["checkpoint_ns"] - blob_values = value["channel_values"] - channel_values: dict[str, Any] = {} - if blob_values: - channel_values = self._load_blobs(blob_values) - return CheckpointTuple( { "configurable": { - "thread_id": thread_id, - "checkpoint_ns": checkpoint_ns, + "thread_id": value["thread_id"], + "checkpoint_ns": value["checkpoint_ns"], "checkpoint_id": value["checkpoint_id"], } }, @@ -469,15 +462,15 @@ class AsyncPostgresSaver(BasePostgresSaver): **value["checkpoint"], "channel_values": { **(value["checkpoint"].get("channel_values") or {}), - **channel_values, + **self._load_blobs(value["channel_values"]), }, }, value["metadata"], ( { "configurable": { - "thread_id": thread_id, - "checkpoint_ns": checkpoint_ns, + "thread_id": value["thread_id"], + "checkpoint_ns": value["checkpoint_ns"], "checkpoint_id": value["parent_checkpoint_id"], } } diff --git a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/base.py b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/base.py index 3ebafa6e1..50103b7c9 100644 --- a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/base.py +++ b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/base.py @@ -247,8 +247,7 @@ class BasePostgresSaver(BaseCheckpointSaver[str]): ) def _load_blobs( - self, - blob_values: Sequence[tuple[bytes, bytes, bytes]], + self, blob_values: list[tuple[bytes, bytes, bytes]] ) -> dict[str, Any]: if not blob_values: return {} diff --git a/libs/checkpoint/langgraph/checkpoint/memory/__init__.py b/libs/checkpoint/langgraph/checkpoint/memory/__init__.py index 011f871e7..0b8593c3e 100644 --- a/libs/checkpoint/langgraph/checkpoint/memory/__init__.py +++ b/libs/checkpoint/langgraph/checkpoint/memory/__init__.py @@ -9,7 +9,7 @@ from collections import defaultdict from collections.abc import AsyncIterator, Iterator, Sequence from contextlib import AbstractAsyncContextManager, AbstractContextManager, ExitStack from types import TracebackType -from typing import Any, cast +from typing import Any from langchain_core.runnables import RunnableConfig @@ -255,16 +255,13 @@ class InMemorySaver( checkpoint, metadata, parent_checkpoint_id = saved writes = self.writes[(thread_id, checkpoint_ns, checkpoint_id)].values() checkpoint_: Checkpoint = self.serde.loads_typed(checkpoint) - channel_values = self._load_blobs( - thread_id, - checkpoint_ns, - checkpoint_["channel_versions"], - ) return CheckpointTuple( config=config, checkpoint={ **checkpoint_, - "channel_values": channel_values, + "channel_values": self._load_blobs( + thread_id, checkpoint_ns, checkpoint_["channel_versions"] + ), }, metadata=self.serde.loads_typed(metadata), pending_writes=[ @@ -288,26 +285,19 @@ class InMemorySaver( checkpoint, metadata, parent_checkpoint_id = checkpoints[checkpoint_id] writes = self.writes[(thread_id, checkpoint_ns, checkpoint_id)].values() checkpoint_ = self.serde.loads_typed(checkpoint) - resolved_config = cast( - RunnableConfig, - { + return CheckpointTuple( + config={ "configurable": { "thread_id": thread_id, "checkpoint_ns": checkpoint_ns, "checkpoint_id": checkpoint_id, } }, - ) - channel_values = self._load_blobs( - thread_id, - checkpoint_ns, - checkpoint_["channel_versions"], - ) - return CheckpointTuple( - config=resolved_config, checkpoint={ **checkpoint_, - "channel_values": channel_values, + "channel_values": self._load_blobs( + thread_id, checkpoint_ns, checkpoint_["channel_versions"] + ), }, metadata=self.serde.loads_typed(metadata), pending_writes=[ @@ -402,27 +392,21 @@ class InMemorySaver( checkpoint_: Checkpoint = self.serde.loads_typed(checkpoint) - list_config = cast( - RunnableConfig, - { + yield CheckpointTuple( + config={ "configurable": { "thread_id": thread_id, "checkpoint_ns": checkpoint_ns, "checkpoint_id": checkpoint_id, } }, - ) - channel_values = self._load_blobs( - thread_id, - checkpoint_ns, - checkpoint_["channel_versions"], - ) - - yield CheckpointTuple( - config=list_config, checkpoint={ **checkpoint_, - "channel_values": channel_values, + "channel_values": self._load_blobs( + thread_id, + checkpoint_ns, + checkpoint_["channel_versions"], + ), }, metadata=metadata, parent_config=(