pub fn decide(
policy: &RetryPolicy,
attempt: u32,
server_retry_after: Option<Duration>,
elapsed: Duration,
jitter_unit: f64,
) -> RetryDecisionExpand description
Decide what to do after attempt attempts have failed.
attempt counts completed attempts, so it is 1 after the first failure.
elapsed is the time consumed by the sequence so far. jitter_unit is a
caller-supplied value in [0.0, 1.0); it is clamped defensively so a bad
caller cannot produce a negative or unbounded delay.
§Delay derivation
Without a server hint, this is full jitter — random(0, min(cap, base·2ⁿ)). The failure mode being defended against is several clients
colliding on one model’s startup, and full jitter is the variant that
decorrelates them most aggressively. Fixed backoff would have every waiter
wake together and collide again.
With a Retry-After, the server’s value is treated as a floor rather
than replaced by jitter: retrying earlier than the server asked just burns
an attempt against a resource known to be unready. A small jitter of up to
initial_backoff is added on top, so concurrent clients handed the same
Retry-After still spread out. The floor is clamped to max_backoff first,
so a buggy or hostile upstream cannot park a request indefinitely.
A delay that would overrun total_deadline yields
GiveUpReason::DeadlineExceeded rather than a truncated sleep: waking
early, before the moment the server nominated, is worse than stopping.