Documentation
¶
Overview ¶
Package chatretry provides retry logic for transient LLM provider errors. It classifies errors as retryable or permanent and uses exponential backoff with provider retry hints when available.
Index ¶
Constants ¶
const ( // InitialDelay is the backoff duration for the first retry // attempt. InitialDelay = 1 * time.Second // MaxDelay is the upper bound for the exponential backoff // duration. Matches the cap used in coder/mux. MaxDelay = 60 * time.Second // MaxAttempts is the upper bound on retry attempts before // giving up. With a 60s max backoff this allows roughly // 25 minutes of retries, which is reasonable for transient // LLM provider issues. MaxAttempts = 25 )
Variables ¶
This section is empty.
Functions ¶
func Delay ¶
Delay returns the backoff duration for the given 0-indexed attempt. Uses exponential backoff: min(InitialDelay * 2^attempt, MaxDelay). Matches the backoff curve used in coder/mux.
func IsRetryable ¶
IsRetryable determines whether an error from an LLM provider is transient and worth retrying.
func Retry ¶
Retry calls fn repeatedly until it succeeds, returns a non-retryable error, ctx is canceled, or MaxAttempts is reached. Retries use exponential backoff capped at MaxDelay, unless the normalized error includes a longer provider Retry-After hint.
The onRetry callback (if non-nil) is called before each retry attempt, giving the caller a chance to reset state, log, or publish status events.
Types ¶
type ClassifiedError ¶
type ClassifiedError = chaterror.ClassifiedError
type OnRetryFn ¶
type OnRetryFn func(attempt int, err error, classified ClassifiedError, delay time.Duration)
OnRetryFn is called before each retry attempt with the attempt number (1-indexed), the raw error that triggered the retry, the normalized error payload, and the delay before the next attempt.