Repository navigation
fix: preserve RetryConfig when Stream.as_async builds the async client - #324
pcbeingused333 wants to merge 1 commit into
Conversation
Stream.as_async copied pool limits, timeouts and the logger onto the new AsyncStream but left retry unset. A client configured to recover a GET from HTTP 429 then made one attempt after conversion and raised StreamRateLimitException.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Stream.as_async()drops a configured retry policy, so a GET that recovers from HTTP 429 on the sync client fails after conversion.Cause:
Stream.as_async()builds a newAsyncStreamand copies the pool limits, timeouts, logger andlog_bodies, but it does not passretry. The new client storesretryasNone. The request loop treats a missing policy as a single attempt, so the first 429 becomesStreamRateLimitExceptioninstead of a retry. ConstructingAsyncStreamwith the sameRetryConfigretries, and so does the original sync client.Fix: pass
retry=self.retryfromas_async(), the same way the other caller-supplied settings are copied.RetryConfigis frozen, so the converted client shares that policy object.Test:
TestAsAsyncPreservesRetry.test_as_async_retries_rate_limitpoints aStreamwithRetryConfig(enabled=True, max_attempts=2, max_backoff=0)at a local HTTP server. The first GET answers 429 and the next answers 200. Before the change the converted client raisesStreamRateLimitExceptionafter one request (retryisNone). After the change that call performs both requests and returns the 200.ruff checkandruff format --checkare clean ongetstream/stream.pyandtests/test_http_client.py.This change was prepared with an AI coding assistant.
Note
Low Risk
Single-line constructor forwarding plus HTTP retry tests; no auth, data, or API contract changes.
Overview
Stream.as_async()now forwardsretry=self.retrywhen it constructsAsyncStream, matching how timeouts, pool settings, and logging options are already copied.Before this change, a sync client configured with
RetryConfigcould retry HTTP 429 responses, but the async client fromas_async()treatedretryas missing and failed on the first rate limit. After the fix, the converted client keeps the same policy object and retries the same way.A new integration test drives a local server that returns 429 then 200 and asserts
as_async()performs two requests and does not raiseStreamRateLimitException.Reviewed by Cursor Bugbot for commit a820dae. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit