simplify delta overwrite fix

This commit is contained in:
Sydney Runkle
2026-06-17 14:07:19 -04:00
parent 941c170c58
commit 4210feccd9
7 changed files with 18 additions and 194 deletions
@@ -24,11 +24,7 @@ from __future__ import annotations
from collections.abc import Mapping, Sequence
from typing import Any
from langgraph.checkpoint.base import (
DeltaChannelHistory,
PendingWrite,
_apply_delta_history_overwrite_semantics,
)
from langgraph.checkpoint.base import DeltaChannelHistory, PendingWrite
# Stage 1 streams ancestors of `target_cid` newest-first. The `<=`
# predicate keeps target itself in the stream so we can read its
@@ -165,11 +161,10 @@ def build_delta_channels_writes_history(
collected: list[PendingWrite] = []
# Chain is newest-first; iterate oldest-first for the public order.
for cid in reversed(chain_cids):
step_writes: list[PendingWrite] = [
(task_id, ch, serde.loads_typed((type_tag, value_blob)))
for type_tag, value_blob, task_id, _idx in cid_writes.get(cid, [])
]
collected.extend(_apply_delta_history_overwrite_semantics(step_writes))
for type_tag, value_blob, task_id, _idx in cid_writes.get(cid, []):
collected.append(
(task_id, ch, serde.loads_typed((type_tag, value_blob)))
)
entry: DeltaChannelHistory = {"writes": collected}
if ch in seeded:
entry["seed"] = seed_val_by_ch[ch]
@@ -33,8 +33,6 @@ pytest.importorskip("langgraph.channels.delta", reason="langgraph core not insta
pytest.importorskip("langgraph.graph", reason="langgraph core not installed")
from langgraph.channels.delta import DeltaChannel # type: ignore[import-untyped] # noqa: E402,I001
from langgraph.checkpoint.base import Checkpoint # noqa: E402
from langgraph.checkpoint.base.id import uuid6 # noqa: E402
from langgraph.checkpoint.serde.types import _DeltaSnapshot # noqa: E402
from langgraph.graph import END, START, StateGraph # type: ignore[import-untyped] # noqa: E402
from typing_extensions import TypedDict # noqa: E402
@@ -215,42 +213,6 @@ def test_seed_omitted_when_walk_reaches_root_sync() -> None:
assert entry["writes"] == []
def test_overwrite_bypasses_same_step_writes_sync() -> None:
with SqliteSaver.from_conn_string(":memory:") as saver:
config: RunnableConfig = {
"configurable": {"thread_id": "overwrite-sync", "checkpoint_ns": ""}
}
cp1 = Checkpoint(
v=1,
id=str(uuid6(clock_seq=-1)),
ts="",
channel_values={},
channel_versions={},
versions_seen={},
updated_channels=None,
)
cfg1 = saver.put(config, cp1, {"source": "loop", "step": 0}, {})
cp2 = Checkpoint(
v=1,
id=str(uuid6(clock_seq=-1)),
ts="",
channel_values={},
channel_versions={},
versions_seen={},
updated_channels=None,
)
cfg2 = saver.put(cfg1, cp2, {"source": "loop", "step": 1}, {})
saver.put_writes(
cfg1,
[("items", [1]), ("items", {"__overwrite__": [50]}), ("items", [2])],
"task",
)
result = saver.get_delta_channel_history(config=cfg2, channels=["items"])
values = [w[2] for w in result["items"]["writes"]]
assert values == [{"__overwrite__": [50]}]
# ---------------------------------------------------------------------------
# Async: AsyncSqliteSaver
# ---------------------------------------------------------------------------