feat(cosmosdb): fast-path delta channel history for LangGraph checkpointer - #840
Open
Cory Gwin (gwincr11) wants to merge 2 commits into
Open
feat(cosmosdb): fast-path delta channel history for LangGraph checkpointer#840Cory Gwin (gwincr11) wants to merge 2 commits into
Cory Gwin (gwincr11) wants to merge 2 commits into
Conversation
…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>
Contributor
There was a problem hiding this comment.
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_historythat bulk-load checkpoints + writes, then reconstruct delta history in memory. - Consolidate writes parsing/sorting/decoding into
_load_sorted_writesand reuse it across pending-writes loaders/groupers. - Bump
langgraph-checkpointto>=4.1.0,<5.0.0and 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) |
Facundo Santiago (santiagxf)
requested a review
from Aayush Kataria (aayush3011)
July 24, 2026 14:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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