Bound Anthropic stream retries to one transport budget - #181
Open
Anteriousis wants to merge 1 commit into
Open
Conversation
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.
Repeated Anthropic connection/read failures could submit one streamed generation 18 times: three SDK transport attempts inside each of six application attempts. This change makes the existing application loop own stream retries, limiting a generation to six actual transport attempts.
SDK retries are disabled on the streaming client only after model capability retrieval. Metadata retrieval and the separate compaction client retain their existing SDK retry policy. HTTP status failures retain a three-failure allowance within the six-attempt total; transient 408/409/429/5xx responses and explicit server retry directives are handled by the outer loop. Retry-After seconds, milliseconds, and HTTP dates are honored within the SDK's existing 60-second range.
Retry progress now includes the transport attempt count and whether response content was observed, alongside the existing turn/attempt fields. Connection/read failures retain the existing short backoff; HTTP failures use bounded exponential backoff. Retries do not execute partially received CAD tool calls.
Verification
Test environment: Windows, the repository-pinned Anthropic SDK 0.116.0, and httpx.MockTransport. The full provider child executes against the actual SDK; no HTTP request reaches the network. In the commands below,
$pythonand$gitdenote the absolute executable paths used; machine-specific paths are omitted.Red baseline:
6 failed, 11 passed. Connection/read failures produced 18 transport attempts instead of 6; SDK-internal status retries were absent from the application retry events.
Additional telemetry red tests:
7 failed, 2 passed, 68 deselected before adding the telemetry fields. Parent cancellation/deadline termination tests already passed.
Final green:
85 passed, 1 skipped; compilation and whitespace checks passed. The skip is Linux-specific.
Coverage includes persistent and mixed failures, recovery on the sixth attempt, interruption after streamed content, permanent errors, server backoff and malformed headers, and unchanged metadata/compaction retry policies. Parent cancellation/deadline tests use a simulated waiting child and verify termination before the parent continues waiting.
No paid model requests or full GUI/C++ build were performed. This is a Python provider orchestration change. Fewer failed transport attempts do not imply that every avoided attempt would have been billable.
Issues
Closes #177.
Before and After Images
Not applicable: no GUI layout changes. Under persistent connection/read failures, the observed request count changes from 18 to 6.
Compatibility
The deliberate behavior change is removal of nested transport retries. Status errors share the overall budget while retaining their existing three-failure ceiling. This PR is independent of the Gemini fix in #180.