Arcana::AI::RetryPolicy
Retrying calls that failed for a reason that may pass: rate limits (429), server errors (500, 502, 503, 504, and Anthropic's 529 overloaded) and network errors.
- Waits as long as the provider asks (
Retry-After,retry-after-ms, or Gemini'sretryDelay), up tomax_wait; a longer requested wait fails at once rather than stalling the caller. - Otherwise backs off
base_delay, doubling each time, capped atmax_delay, with ±25% jitter so many clients don't retry in step. - Never retries what can't pass soon: OpenAI's
insufficient_quota(a spending cap, sent as 429) or a per-day quota. - A network error is retried only before the response has started
(see
Attempt#started!): a stream that already sent events to the caller can't be replayed.
Constants
RETRY_STATUSES = {429, 500, 502, 503, 504, 529}
Constructors
new(max_retries : Int32 = 3, base_delay : Time::Span = 500.milliseconds, max_delay : Time::Span = 8.seconds, max_wait : Time::Span = 30.seconds)
SourceClass methods
The wait a failed response asks for, if it names one.
Instance methods
base_delay
SourceThe wait before retrying after ex, or nil to give up.
max_delay
Sourcemax_retries
Sourcemax_wait
Sourcerun(ctx : Context | Nil = nil, on_retry : Proc(Int32, Time::Span, String, Nil) | Nil = nil, & : Attempt -> T) : Tuple(T, RetryStats) forall T
Run the block (one try per call) until it returns, fails for good,
or ctx is cancelled. on_retry hears of each retry before the
wait: (retry number, delay, reason).