Prevent retrying POST requests on network errors - #965
Draft
razor-x wants to merge 1 commit into
Draft
Conversation
axios-retry's default retryCondition, isNetworkOrIdempotentRequestError, retries any network-level failure (timeout, connection reset) regardless of HTTP method. Since the SDK's write endpoints are POST requests, a connection reset or timeout mid-flight caused the same POST to be resent up to 3 times even though the server may have already received and acted on it, e.g., replaying an unlockDoor call. Restrict the default retryCondition to axios-retry's isIdempotentRequestError so only GET/HEAD/OPTIONS/PUT/DELETE are retried, matching the retry semantics already documented for the Ruby and Python SDKs. Callers can still opt back in per-request via axiosRetryOptions. Also corrects the README, which described timeout retries without noting they were previously replayed regardless of method.
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.
Summary
This change restricts automatic retry behavior to only idempotent HTTP methods (
GET,HEAD,OPTIONS,PUT,DELETE), preventingPOSTrequests from being retried when network-level errors occur. This is a critical safety improvement to avoid duplicate side effects (e.g., unlocking a door twice) when the client cannot confirm whether the server received and processed a request before the connection was lost.Key Changes
src/lib/client.ts: Changed from axios-retry's defaultisNetworkOrIdempotentRequestErrortoisIdempotentRequestError, which only retries idempotent HTTP methods. This preventsPOSTrequests from being automatically resent on network errors like connection resets or timeouts.test/seam/connect/retry.test.ts:POSTrequests are not retried on 503 status errorsPOSTrequests are not replayed when the server drops the connection after receiving the requestREADME.md: Clarified the default retry behavior, explaining whyPOSTrequests are excluded and how users can customize this behavior if needed.Implementation Details
The change leverages the
isIdempotentRequestErrorfunction from theaxios-retrylibrary, which safely restricts retries to HTTP methods that are safe to send multiple times. This prevents the dangerous scenario where a non-idempotent request (like aPOSTto unlock a door) could be automatically resent after a network failure, potentially causing the operation to execute twice on the server side.https://claude.ai/code/session_012fyJ8jtTb5MKU12Egz1jAq