fix(model/openai): wrap streaming branch in Flux.defer to make retry re-issue HTTP requests#2079
Open
birdie7761 wants to merge 4 commits into
Open
fix(model/openai): wrap streaming branch in Flux.defer to make retry re-issue HTTP requests#2079birdie7761 wants to merge 4 commits into
birdie7761 wants to merge 4 commits into
Conversation
…re-issue HTTP requests OpenAIChatModel.doStream0's streaming branch returned a Flux tied to a single transport.stream() invocation. For transports whose stream() is backed by a one-shot future (e.g. JdkHttpTransport), retryWhen re- subscriptions replayed the already-failed publisher instead of sending a new HTTP request. This caused 429/5xx retry to exhaust after a single attempt. Wrap the streaming branch in Flux.defer, matching the non-streaming branch, so each retry creates a fresh publisher and re-issues the HTTP request. Add OpenAIChatModelStreamingRetryTest to verify that streaming 429 responses are retried and hit the server maxAttempts times for OkHttpTransport, JdkHttpTransport, and the default transport.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
approved these changes
Jul 10, 2026
oss-maintainer
left a comment
Collaborator
There was a problem hiding this comment.
Summary
Fixes a bug where streaming retry in OpenAIChatModel did not re-issue HTTP requests for retryable errors (e.g. HTTP 429). Root cause: the streaming Flux was returned directly, so re-subscriptions replayed the same one-shot failed future instead of creating a new HTTP request.
Findings
- [Info]
OpenAIChatModel.java:310— Wrapping inFlux.defer()+subscribeOn(Schedulers.boundedElastic())is the correct fix, matching the existing non-streaming branch pattern. - [Info]
OpenAIChatModelStreamingRetryTest.java— Excellent test coverage with MockWebServer: 429 exhaust, 429→success, 400 no-retry, multi-transport verification. The control test for non-streaming is a nice touch.
Verdict
Minimal, correct fix with thorough tests. LGTM.
Automated review by github-manager
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
Fixes a bug where streaming retry in
OpenAIChatModeldid not re-issue HTTP requests for retryable errors such as HTTP 429.Root cause
OpenAIChatModel.doStream0()returned the streamingFluxdirectly:When ModelUtils.applyTimeoutAndRetry() later applied retryWhen, re-subscriptions reused the same publisher. For transports whose stream() is backed by a one-shot future (notably the default JdkHttpTransport), the same failed future was replayed
instead of sending a new HTTP request. As a result, a maxAttempts=3 retry exhausted after a single server hit.
Fix
Wrap the streaming branch in Flux.defer(), matching the existing non-streaming branch, so every retry creates a fresh publisher and re-issues the HTTP request:
Verification
Added OpenAIChatModelStreamingRetryTest with MockWebServer scenarios:
• Streaming 429 exhausts retries and hits the server maxAttempts times.
• Streaming 429 retries then succeeds on the final attempt.
• Streaming 400 does not retry.
• Streaming 429 retry re-issues requests for JdkHttpTransport, OkHttpTransport, and the default transport.
• Non-streaming 429 retry re-issues requests as a control.
All tests pass locally:
mvn spotless:apply mvn test -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-openaiChecklist
• [x] Code has been formatted with mvn spotless:apply
• [x] All tests are passing (mvn test)
• [x] Javadoc comments are complete and follow project conventions
• [ ] Related documentation has been updated (not needed for this internal bug fix)
• [x] Code is ready for review