openai / openai/openai-java

RetryingHttpClient.executeAsync skips retry handling when delegate throws synchronously

Open
#888 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
1.5k
Forks
264
Avg merge
9h 46m
Merged PRs (30d)
96

Description

Description

RetryingHttpClient.executeAsync() calls the delegate before it has a CompletableFuture to attach its retry policy to:

val responseFuture = httpClient.executeAsync(requestWithRetryCount, requestOptions)

A custom HttpClient implementation is allowed by the SDK surface and can throw synchronously from executeAsync() instead of returning an exceptionally completed future.

When that happens, the exception escapes RetryingHttpClient.executeAsync() immediately. The existing handleAsync branch never sees it, so even retryable synchronous failures such as IOException, OpenAIIoException, or OpenAIRetryableException bypass the configured retry policy.

Expected behavior

Synchronous failures from the async delegate should enter the same retry decision path as exceptionally completed futures. Retryable failures should retry up to maxRetries; non-retryable failures should surface through the returned future.

Suggested fix

Wrap the delegate call and convert a synchronous throwable into an exceptionally completed CompletableFuture<HttpResponse> before applying the existing retry handler.

Add regression coverage for:

  • a synchronous OpenAIRetryableException followed by a successful async response;
  • a synchronous non-retryable exception completing the returned future exceptionally without a retry;
  • retry-count headers remaining correct across the synchronous-failure retry.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at RetryingHttpClient.executeAsync() and inspect the existing handleAsync retry path around the delegate call. Run the current retry-related tests, then add regression coverage for synchronous retryable and non-retryable failures and verify retry-count headers remain correct; done means synchronous failures follow the same policy as exceptional futures.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
api, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.