Repository navigation
fix(service): correct network error classification in memory HTTP clients and make delete_thread cleanup robust - #64
Merged
Zhiyue-Wang merged 2 commits intoOct 12, 2026
Conversation
…ents Network errors (timeout, connection refused, etc.) were previously wrapped as MemoryAPIException with status_code=503, falsely implying a server response. They now use status_code=0 to signal "no HTTP response", and the original exception is preserved via __cause__. 2xx responses with a non-JSON body are now classified as PARSE_ERROR instead of falling into the network-error bucket. MemoryAPIException was defined twice (sync and async modules); it is now defined once in http_client.py and exported from the service package so the new is_network_error / retryable helper properties are usable from the public API surface.
delete_thread / adelete_thread now delete the writes session before the main session, and _persisted_count cleanup runs in a finally block so it always executes even when delete_session raises. The swallow-exception contract is unchanged. Adds a formal unit test suite for AgentArtsMemorySessionSaver (put_writes / aput_writes, get_tuple / aget_tuple, list / alist, delete_thread / adelete_thread, and context managers).
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64 +/- ##
=======================================
Coverage ? 61.66%
=======================================
Files ? 108
Lines ? 9566
Branches ? 1495
=======================================
Hits ? 5899
Misses ? 3213
Partials ? 454 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Sep 10, 2026
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
Summary
This PR fixes two related issues in the SDK.
First, network errors in the memory HTTP clients were previously wrapped as
MemoryAPIExceptionwithstatus_code=503, which falsely implies the server returned a "Service Unavailable" response. In reality these failures (timeouts, connection refused, DNS errors) never produced an HTTP response at all. They are now reported withstatus_code=0to signal "no HTTP response", and the original exception is preserved through the standard exception chain so callers can inspect the root cause via__cause__. As a related cleanup, 2xx responses with a non-JSON body are no longer mislabeled as network errors; they now raiseMemoryAPIExceptionwith a dedicatedPARSE_ERRORerror code while keeping the actual HTTP status code.Second,
MemoryAPIExceptionwas defined twice, once in each of the sync and async memory service modules, which made the two classes distinct despite sharing a name. It is now defined once in the shared HTTP client module and exported from the public service package, together with two new helper properties (is_network_errorandretryable) that let callers classify errors without string matching on error codes.Third,
delete_threadandadelete_threadin the LangGraph checkpoint saver were restructured so that the writes session is deleted before the main session, and the in-memory persisted-count cleanup always runs via afinallyblock even when session deletion fails. The existing swallow-exception contract is preserved: deletion failures are logged but not propagated, and idempotent behavior is unchanged.Behavior changes
status_codechanges from503to0(no server response).PARSE_ERRORerror code for 2xx responses with invalid JSON bodies.MemoryAPIExceptionis now importable from the public service package (is_network_error/retryableproperties added).delete_thread/adelete_thread: writes session deleted first; persisted-count cleanup guaranteed viatry/finally; swallow-exception contract unchanged.Backward compatibility is maintained:
MemoryAPIExceptionremains a subclass ofAPIException, so existingexcept APIExceptionhandlers continue to work, and the package export is purely additive.Verification
Verified with unit tests covering both synchronous and asynchronous client paths. The tests exercise the full error classification flow: timeouts and connection errors surface as network errors with no HTTP status and preserve the original exception for inspection; real HTTP 503 and 404 responses keep their actual status codes and are correctly distinguished from network-level failures; 2xx responses with non-JSON bodies are classified as parse errors rather than network errors; and successful 2xx responses pass through unchanged. The new classification properties were also asserted across network, rate-limit, server-error, and client-error cases to confirm retry semantics. For the checkpoint saver, tests verify that deleting a thread removes the writes session before the main session, that the persisted-count tracking is always cleaned up even when deletion fails, and that both sync and async paths behave identically without propagating deletion errors. A simulated end-to-end data flow exercise covering these same scenarios was run successfully to confirm the changes work together in practice.