pub struct ModelRetryPolicy { /* private fields */ }Expand description
Deterministic provider-neutral model retry policy.
The policy is jitter-free for test determinism: next_delay is a pure
exponential backoff base * 2^(attempt-1) capped at max_delay. Retries
are bounded by max_attempts.
Implementations§
Source§impl ModelRetryPolicy
impl ModelRetryPolicy
Sourcepub fn new(
max_attempts: u32,
base_delay: Duration,
max_delay: Duration,
) -> Result<Self, KernelError>
pub fn new( max_attempts: u32, base_delay: Duration, max_delay: Duration, ) -> Result<Self, KernelError>
Creates a validated retry policy.
§Errors
Returns an error for zero attempts, zero base delay, a base greater than max, or values above the supported bounds.
Sourcepub const fn max_attempts(self) -> u32
pub const fn max_attempts(self) -> u32
Returns the maximum attempts including the first try.
Sourcepub const fn base_delay(self) -> Duration
pub const fn base_delay(self) -> Duration
Returns the base backoff delay applied to the first retry.
Sourcepub fn next_delay(self, attempt: u32) -> Duration
pub fn next_delay(self, attempt: u32) -> Duration
Returns the deterministic delay to wait before the next attempt.
attempt is 1-indexed: the first retry (attempt 1) waits base_delay.
Sourcepub fn delay_for_failure(self, failure: &ModelFailure, attempt: u32) -> Duration
pub fn delay_for_failure(self, failure: &ModelFailure, attempt: u32) -> Duration
Returns the bounded delay selected for one retryable failure.
A provider-requested delay takes precedence over local exponential
backoff. Both sources are capped by max_delay.
Sourcepub fn should_retry(self, failure: &ModelFailure) -> Option<ModelFailureCode>
pub fn should_retry(self, failure: &ModelFailure) -> Option<ModelFailureCode>
Returns the failure code when a retry is permitted, else None.
Never failures (invalid request, auth, permission, malformed, or
cancellation) are never retried. Immediate and AfterBackoff failures
are retryable within the policy attempt bound; the caller checks the
attempt count separately.