retry

package
v0.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package retry decorates an inference.Client with bounded, classified retry and exponential backoff. It retries Invoke calls and Stream establishment only; once a StreamReader is handed out, a mid-stream failure is terminal for the wrapper exactly as for the inner client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retryable

func Retryable(err error) bool

Retryable reports whether err is worth another attempt: a transient transport/network failure or a provider status that signals pressure (408, 429, 5xx). Context cancellation is never retryable, even when it wraps a retryable cause. Exported so other callers (hustleruntime holds a private copy of this predicate today) can converge on one definition.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client decorates an inner inference.Client with the Policy's schedule.

func New

func New(inner inference.Client, policy Policy) (*Client, error)

New validates policy and returns the decorated client.

func (*Client) Invoke

func (c *Client) Invoke(ctx context.Context, req inference.Request) (*inference.Response, error)

func (*Client) Stream

type ConfigError

type ConfigError struct {
	Field  string
	Reason string
}

ConfigError reports an invalid retry configuration at construction.

func (*ConfigError) Error

func (e *ConfigError) Error() string

type ExhaustedError

type ExhaustedError struct {
	Attempts int
	Cause    error
}

ExhaustedError reports that every permitted attempt failed. Unwrap exposes the final attempt's failure so typed inspection (errors.As on *failure.APIError / *failure.NetworkError) keeps working.

func (*ExhaustedError) Error

func (e *ExhaustedError) Error() string

func (*ExhaustedError) Unwrap

func (e *ExhaustedError) Unwrap() error

type InvalidResponseError

type InvalidResponseError struct{}

InvalidResponseError reports an inner client that returned no response and no error. A retry decorator cannot classify or replay this malformed result.

func (*InvalidResponseError) Error

func (*InvalidResponseError) Error() string

type Policy

type Policy struct {
	StableRetries int           // retries at fixed StableDelay
	StableDelay   time.Duration // delay for the stable retry leg
	MaxAttempts   int           // total attempts including the first
	MaxDelay      time.Duration // cap on the exponential retry leg
}

Policy is the immutable retry schedule: StableRetries retries at StableDelay, then exponential doubling (starting at 2*StableDelay) capped at MaxDelay, until MaxAttempts total attempts have been made.

func (Policy) Validate

func (p Policy) Validate() error

Validate reports the first structural defect. The zero value is invalid: this package never invents a schedule the caller did not state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL