Skip to content

fix: preserve RetryConfig when Stream.as_async builds the async client - #324

Open
pcbeingused333 wants to merge 1 commit into
GetStream:mainfrom
pcbeingused333:fix/as-async-preserves-retry
Open

pcbeingused333 wants to merge 1 commit into
GetStream:mainfrom
pcbeingused333:fix/as-async-preserves-retry

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 15, 2026 •

Copy link
Copy Markdown

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 new AsyncStream and copies the pool limits, timeouts, logger and log_bodies, but it does not pass retry. The new client stores retry as None. The request loop treats a missing policy as a single attempt, so the first 429 becomes StreamRateLimitException instead of a retry. Constructing AsyncStream with the same RetryConfig retries, and so does the original sync client.

Fix: pass retry=self.retry from as_async(), the same way the other caller-supplied settings are copied. RetryConfig is frozen, so the converted client shares that policy object.

Test: TestAsAsyncPreservesRetry.test_as_async_retries_rate_limit points a Stream with RetryConfig(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 raises StreamRateLimitException after one request (retry is None). After the change that call performs both requests and returns the 200. ruff check and ruff format --check are clean on getstream/stream.py and tests/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 forwards retry=self.retry when it constructs AsyncStream, matching how timeouts, pool settings, and logging options are already copied.

Before this change, a sync client configured with RetryConfig could retry HTTP 429 responses, but the async client from as_async() treated retry as 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 raise StreamRateLimitException.

Reviewed by Cursor Bugbot for commit a820dae. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Async clients created from a stream now retain its retry settings, allowing configured retries to be applied to requests after conversion. For example, requests can be retried after a rate-limit response instead of failing immediately.

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.
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Stream.as_async() now passes the client’s retry configuration to AsyncStream. A test verifies that the converted client retries after a rate-limit response and completes the request.

Changes: Async retry policy

Layer / File(s) Summary
Retry policy propagation and validation
getstream/stream.py, tests/test_http_client.py
Stream.as_async() passes its retry configuration to AsyncStream. The test server returns 429 on the first request and 200 on the next; the test checks the retry, request count, and preserved policy.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: itsmeadi, tbarbugli

Merge Risk: Minimal · up to a820d

Converted async clients now keep the configured retry policy and retry after rate-limit responses, matching the sync client. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: Stream.as_async() now keeps the configured RetryConfig when it builds the AsyncStream. The raw summary says as_async() passes the client's retry configuration to Async…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: Stream.as_async() now keeps the configured RetryConfig when it builds the AsyncStream. The raw summary says as_async() passes the client's retry configuration to AsyncStream, and the test checks that the converted client retries a 429 and keeps the same policy. The title is specific and matches the changeset, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 13ce9f90-e3fd-44b7-bd24-59355b316058
Commits

Reviewing files that changed from the base of the PR and between 7140b69 and a820dae.

Files selected for processing: 2

  • getstream/stream.py
  • tests/test_http_client.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant