Skip to content

feat(cosmosdb): fast-path delta channel history for LangGraph checkpointer - #840

Open
Cory Gwin (gwincr11) wants to merge 2 commits into
langchain-ai:mainfrom
gwincr11:cg-delta-channel-history
Open

feat(cosmosdb): fast-path delta channel history for LangGraph checkpointer#840
Cory Gwin (gwincr11) wants to merge 2 commits into
langchain-ai:mainfrom
gwincr11:cg-delta-channel-history

Conversation

@gwincr11

Copy link
Copy Markdown
Contributor

Override get_delta_channel_history / aget_delta_channel_history to replace the base per-ancestor get_tuple walk (O(N) serial round trips) with two bulk queries, walking the parent chain in memory. Consolidate the shared "parse writes keys -> sort by idx -> load" logic into a single _load_sorted_writes helper reused by _group_pending_writes and both _load_pending_writes methods.

Bump langgraph-checkpoint to >=4.1.0,<5.0.0 for DeltaChannelHistory and add sync/async parity unit tests plus integration tests.

https://www.langchain.com/blog/delta-channels-evolving-agent-runtime

Cory Gwin (gwincr11) and others added 2 commits July 15, 2026 18:28
…inter

Override get_delta_channel_history / aget_delta_channel_history to replace
the base per-ancestor get_tuple walk (O(N) serial round trips) with two
bulk queries, walking the parent chain in memory. Consolidate the shared
"parse writes keys -> sort by idx -> load" logic into a single
_load_sorted_writes helper reused by _group_pending_writes and both
_load_pending_writes methods.

Bump langgraph-checkpoint to >=4.1.0,<5.0.0 for DeltaChannelHistory and
add sync/async parity unit tests plus integration tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply two hardening improvements to the delta-channel-history fast path,
learned from a downstream reimplementation:

- Resolve the target checkpoint from the already-fetched partition docs
  via _resolve_target_checkpoint_id (max() of checkpoint ids) instead of
  a separate SELECT TOP 1 query, keeping the "latest" path to two round
  trips instead of three.
- Read channel_values defensively (checkpoint.get(...) or {}) so a
  malformed checkpoint doc cannot raise KeyError during reconstruction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the CosmosDB LangGraph checkpointer’s delta-channel-history performance by replacing the base per-ancestor tuple walk (serial round trips) with two bulk Cosmos queries and an in-memory parent-chain walk, and adds parity tests to ensure the override matches BaseCheckpointSaver semantics.

Changes:

  • Add fast-path overrides for get_delta_channel_history / aget_delta_channel_history that bulk-load checkpoints + writes, then reconstruct delta history in memory.
  • Consolidate writes parsing/sorting/decoding into _load_sorted_writes and reuse it across pending-writes loaders/groupers.
  • Bump langgraph-checkpoint to >=4.1.0,<5.0.0 and add sync/async unit parity tests plus integration parity tests.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
libs/azure-cosmosdb/src/langchain_azure_cosmosdb/_langgraph_checkpoint_store.py Adds sync fast-path delta history + shared helpers for bulk reconstruction and sorted write loading.
libs/azure-cosmosdb/src/langchain_azure_cosmosdb/aio/_langgraph_checkpoint_store.py Adds async fast-path delta history and reuses shared sorted write loading.
libs/azure-cosmosdb/tests/unit_tests/_delta_common.py Introduces shared fake containers + helpers for delta-history parity testing.
libs/azure-cosmosdb/tests/unit_tests/test_langgraph_checkpoint_delta.py Adds sync parity unit tests vs BaseCheckpointSaver.get_delta_channel_history.
libs/azure-cosmosdb/tests/unit_tests/aio/test_langgraph_checkpoint_delta.py Adds async parity unit tests vs BaseCheckpointSaver.aget_delta_channel_history.
libs/azure-cosmosdb/tests/integration_tests/test_langgraph_checkpointer.py Adds integration parity tests for sync/async delta history behavior.
libs/azure-cosmosdb/pyproject.toml Bumps langgraph-checkpoint version range for runtime + test groups.
libs/azure-cosmosdb/uv.lock Updates lockfile to reflect dependency changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +803 to +809
writes_prefix = _make_writes_partition_prefix(thread_id, checkpoint_ns)
write_docs = list(
self.container.query_items(
query=("SELECT * FROM c WHERE STARTSWITH(c.partition_key, @prefix)"),
parameters=[{"name": "@prefix", "value": writes_prefix}],
)
)
Comment on lines +100 to +107
def query_items(
self,
*,
query: str,
parameters: list[dict[str, Any]] | None = None,
partition_key: str | None = None,
) -> list[dict[str, Any]]:
return run_query(self.store, query, parameters, partition_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants