Documentation
¶
Overview ¶
Package retry classifies provider failures as retryable or terminal and paces the re-attempts.
It exists because "is this worth retrying?" has to be answered identically in two places that cannot import each other: internal/provider, which retries a single failed HTTP request, and internal/agent, which retries a whole run.
The classification is deliberately message-based. Providers hand pi-go their failures as opaque strings — an SSE stream error is a JSON body, not a typed error — so pattern matching on the text is the only signal available at both layers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delay ¶
Delay returns how long to wait before the given retry attempt (0-based).
A server-supplied hint wins over the computed backoff, since the server knows when its window reopens and we do not. Both are clamped to cfg.MaxDelay so a provider cannot park a turn indefinitely.
func IsTerminal ¶
IsTerminal reports whether err describes a failure that will recur identically however long the caller waits.
func IsTransient ¶
IsTransient reports whether err is worth retrying.
func ServerDelay ¶
ServerDelay extracts the wait the provider asked for, if it named one.
A rate-limit body usually carries the exact figure ("Please try again in 9.422s"), and honoring it is the difference between one well-timed retry and a backoff schedule that keeps landing inside the same exhausted window.
Types ¶
type Config ¶
type Config struct {
// MaxRetries is the number of retries after the initial attempt.
MaxRetries int
// InitialDelay is the pause before the first retry.
InitialDelay time.Duration
// MaxDelay caps the exponential backoff, and also caps any delay the
// server itself asked for.
MaxDelay time.Duration
}
Config controls how many times a failed attempt is repeated and how long the pauses between attempts grow.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the shared defaults.
MaxDelay is a minute because the limits that produce a retryable 429 are per-minute windows: a shorter cap would guarantee the retry lands inside the same exhausted window it is waiting out.