Skip to content

RetryingHttpClient.executeAsync skips retry handling when delegate throws synchronously #888

Description

@sylvesterkaczmarek

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions