ErrorRecovery

org.llm4s.error.ErrorRecovery
@Stable
object ErrorRecovery

Advanced pattern matching for error recovery and intelligent retry logic.

Uses Scala's powerful pattern matching to implement sophisticated error handling strategies with type-safe recovery patterns.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

class CircuitBreaker[A](failureThreshold: Int, recoveryTimeout: FiniteDuration, clock: () => Instant)

Circuit breaker pattern for service resilience.

Circuit breaker pattern for service resilience.

Value parameters

clock

the current time; injectable for tests

Attributes

Supertypes
class Object
trait Matchable
class Any
sealed trait CircuitState

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Closed
object HalfOpen
object Open
case object Closed extends CircuitState

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait CircuitState
class Object
trait Matchable
class Any
Show all
Self type
Closed.type
case object HalfOpen extends CircuitState

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait CircuitState
class Object
trait Matchable
class Any
Show all
Self type
HalfOpen.type
case object Open extends CircuitState

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait CircuitState
class Object
trait Matchable
class Any
Show all
Self type
Open.type

Value members

Concrete methods

def recoverWithBackoff[A](operation: () => Result[A], maxAttempts: Int, baseDelay: FiniteDuration): Result[A]

Binary-compatible overload — delegates to the full version, sleeping the calling thread.

Binary-compatible overload — delegates to the full version, sleeping the calling thread.

Attributes

def recoverWithBackoff[A](operation: () => Result[A], maxAttempts: Int, baseDelay: FiniteDuration, sleepFn: FiniteDuration => Unit): Result[A]

Retries operation while it fails with a transient error, up to maxAttempts calls in all.

Retries operation while it fails with a transient error, up to maxAttempts calls in all.

What is retried is the library's one rule for automatic retry, org.llm4s.reliability.RetryPolicy.isRetryable, which ReliableClient, LLMClientRetry and the agent graph's node retries use too: a RecoverableError, except a ServiceError or an APIError with a client-error status (any 4xx but 408 and 429) and an OptimisticLockFailure. Each retried error waits on its own schedule:

Every other error, including a CancelledError, is returned unchanged at once, whatever the attempt count. An interrupt during a wait returns a CancelledError. When the last attempt fails with a retried error, the result is an ExecutionError (itself a retried RecoverableError) whose message names the number of attempts made and the last error's message, and whose operation is the last error's formatted text. The operation is always called at least once, even when maxAttempts is below 1.

Value parameters

sleepFn

pauses between attempts (default: sleeps the calling thread); override for testing

Attributes