Skip to content

Retry Policy

Bounded retry policies for remote integrations, decided by the normalized error.

The loops here take their limits from a core RetryConfig and decide with is_transient_error, which reads the error's exported recovery.retryable, so the retry decision and the guidance a caller sees cannot disagree. Each attempt must raise a normalized error; anything else stops the loop unchanged. needs_caller_correction decides whether a failed batch may be repeated row by row.

is_transient_error(error)

Returns whether another attempt of the same idempotent request can succeed after this failure.

Parameters:

Name Type Description Default
error BaseException

The normalized failure of one attempt.

required

Returns:

Name Type Description
bool bool

True when the error's recovery says it is retryable: connection failures, throttling and HTTP 500, 502, 503 and 504. False otherwise, including every timeout.

needs_caller_correction(error)

Returns whether a normalized failure can only be fixed by the caller, so repeating the work cannot help.

Used where a failed batch would otherwise be repeated row by row: a wrong setting, missing dependency, denied access or unknown model fails the same way for every row. An input or unsupported-operation failure can belong to one row, so it is not listed and the rows are evaluated one by one.

Parameters:

Name Type Description Default
error BaseException

The normalized failure.

required

Returns:

Name Type Description
bool bool

True for configuration, dependency and access failures, and for gllm-inference authentication, billing and model-not-found errors.

retry_delay(attempt, config, error)

Computes the wait before the next attempt, honoring a reported retry_after_seconds up to max_delay.

The loops never call it for a reported wait longer than max_delay: they raise instead of retrying early.

Parameters:

Name Type Description Default
attempt int

The failed attempt number (0-based).

required
config RetryConfig

Backoff settings.

required
error BaseException

The normalized failure of the attempt.

required

Returns:

Name Type Description
float float

Seconds to wait.

retry_transient_async(operation, config, *, label, context, should_retry=is_transient_error) async

Runs an async operation with a bounded attempt budget and an optional overall deadline.

The operation runs at most config.max_retries + 1 times. A failure is retried only when it is a BaseEvalError accepted by should_retry. config.timeout, when set, bounds every attempt and wait together and is never restarted. config.retry_on_exceptions and config.non_retryable_exceptions are not used.

Parameters:

Name Type Description Default
operation Callable[[], Awaitable[T]]

One attempt. It must raise normalized errors.

required
config RetryConfig

Attempt budget, backoff and overall deadline.

required
label str

Static name of the operation for retry logs.

required
context ErrorContext

Where the operation runs, attached to a deadline error.

required
should_retry Callable[[BaseException], bool]

Decides whether a normalized failure is retried. Defaults to is_transient_error.

is_transient_error

Returns:

Name Type Description
T T

The result of the first successful attempt.

Raises:

Type Description
EvalTimeoutError

If the overall deadline expires.

Exception

The failure of the last attempt, the first failure that is not retried, or a failure whose reported retry_after_seconds exceeds config.max_delay.

retry_transient_sync(operation, *, total_attempts, config, label, should_retry=is_transient_error)

Runs a blocking operation with a bounded attempt budget.

Parameters:

Name Type Description Default
operation Callable[[], T]

One attempt. It must raise normalized errors.

required
total_attempts int

Maximum number of attempts, at least 1.

required
config RetryConfig

Backoff settings; its max_retries, timeout and exception tuples are not used.

required
label str

Static name of the operation for retry logs.

required
should_retry Callable[[BaseException], bool]

Decides whether a normalized failure is retried. Defaults to is_transient_error.

is_transient_error

Returns:

Name Type Description
T T

The result of the first successful attempt.

Raises:

Type Description
Exception

The failure of the last attempt, the first failure that is not retried, or a failure whose reported retry_after_seconds exceeds config.max_delay.