Repository navigation
feat(integration/langgraph): implement put_writes, delete_thread, and async context manager - #49
Merged
Zhiyue-Wang merged 1 commit intoAug 28, 2026
Conversation
- saver.py: implement put_writes/aput_writes to persist pending writes in a dedicated UUID5-derived session (auto-recreate on 404) - saver.py: rename delete/adelete to delete_thread/adelete_thread per the current LangGraph BaseCheckpointSaver interface - saver.py: attach pending_writes to CheckpointTuple in get_tuple, aget_tuple, list, alist - saver.py: add aclose/__aenter__/__aexit__ async context management - test_langgraph.py: assert delete_thread/adelete_thread methods exist
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #49 +/- ##
=======================================
Coverage ? 53.31%
=======================================
Files ? 95
Lines ? 7959
Branches ? 1224
=======================================
Hits ? 4243
Misses ? 3423
Partials ? 293 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Description
This PR completes the LangGraph
BaseCheckpointSaverimplementation by filling in four stub/outdated methods:put_writes/aput_writes,delete_thread/adelete_thread, and adds async context manager support (aclose/__aenter__/__aexit__).Background
put_writesandaput_writeswere stubs that only logged warnings, which meant LangGraph's interrupt/resume and crash-recovery flows (Pregel) could not function.deleteandadeleteused an outdated signature (delete(config)) that no longer matched the currentBaseCheckpointSaverinterface (delete_thread(thread_id)), so LangGraph never called them.Changes
src/agentarts/sdk/integration/langgraph/saver.pyput_writes/aput_writes: Serialize writes viaserde.dumps_typed+ base64, pack into aTextMessage(role="system", content="pending_writes", meta=...)and store in a dedicated writes session (UUID5-derived from the main session ID). If the writes session does not exist (HTTP 404), it is automatically created and the write is retried. Non-404 errors are logged but do not crash the caller.delete_thread/adelete_thread: Delete both the main session and the writes session viadelete_session. Writes session deletion failure is logged at debug level (it may not exist)._persisted_countis cleaned up._writes_session_id(session_id): Static helper that returnsstr(uuid.uuid5(DNS_NAMESPACE, session_id)), ensuring the writes session ID is a valid 36-char UUID as required by the backend._extract_pending_writes(messages, checkpoint_id): Reads write messages from the writes session, filters bycheckpoint_id, and deduplicates by(task_id, write_idx)— regular writes (idx >= 0) first-wins (idempotent skip), special writes (ERROR/INTERRUPT/RESUME/SCHEDULED, idx < 0) last-wins (always overwrite), matchingInMemorySaversemantics.get_tuple/aget_tuple/list/alist: Retrieve pending writes from the writes session and attach toCheckpointTuple. Retrieval failure is logged at debug level and does not break main checkpoint retrieval.aclose/__aenter__/__aexit__: Async context manager support.aclose()closes both the sync and async clients. Symmetric with the existing syncclose()/__enter__/__exit__.tests/unit/sdk/integration/test_langgraph.pytest_saver_methods_existto assertdelete_threadandadelete_threadinstead of the olddeleteandadelete.Design rationale: separate writes session
Writes are stored in a dedicated
{session_id}__writessession (UUID5-derived) rather than the main session because: (1) delta tracking integrity —_persisted_counttracks conversation messages only, mixed writes would inflateget_last_k_messagestotal and cause duplicate message writes input(); (2) metadata extraction —get_tupleusesmessages[-1]to extract checkpoint metadata, mixed writes would corrupt that; (3) no filter needed — conversation and writes are cleanly separated.Verification
The implementation was verified against the
BaseCheckpointSaverinterface contract with 14 mock-based tests coveringput_writes,aput_writes,delete_thread,adelete_thread, pending_writes roundtrip serialization/deserialization, dedup semantics for regular and special writes, APIException 404 auto-retry (both sync and async), and sync/async context managers. All 14 tests pass, and the full official test suite (23 tests) passes without regression. Ruff lint is clean.