fix: retry synchronous failures from async delegates - #891
Open
sylvesterkaczmarek wants to merge 2 commits into
Open
fix: retry synchronous failures from async delegates#891sylvesterkaczmarek wants to merge 2 commits into
sylvesterkaczmarek wants to merge 2 commits into
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.
Summary
Route synchronous exceptions thrown by
HttpClient.executeAsync()throughRetryingHttpClient's existing async retry machinery instead of letting them escape before retry handling is attached.Fixes #888.
Problem
RetryingHttpClient.executeAsync()currently calls its delegate directly:A custom
HttpClientcan throw synchronously fromexecuteAsync()rather than returning an exceptionally completed future. In that case, the exception escapes before the existinghandleAsyncretry path runs.That means synchronous
IOException,OpenAIIoException, andOpenAIRetryableExceptionfailures bypassmaxRetriesentirely, even though the same failures are retryable when delivered asynchronously.Fix
Wrap the delegate call and convert a synchronous throwable into an exceptionally completed
CompletableFuture<HttpResponse>.The resulting future then flows through the existing retry handler unchanged, so:
Regression coverage
Added focused tests for:
OpenAIRetryableExceptionfollowed by a successful response, verifying two attempts and retry-count headers0then1;executeAsync()itself returns normally with an exceptionally completed future and no retry/backoff occurs.Validation
mainatcf942a40074291290634321ad9fe21e514030b4c;RetryingHttpClient.kt;execute()behavior are unchanged.Full repository validation is left to GitHub Actions.
Risk
Low. Existing delegates that already return futures are unaffected. The behavior changes only when an async delegate throws before returning a future.