Skip to main content

CircuitBreaker

Trait CircuitBreaker 

Source
pub trait CircuitBreaker: Send + Sync {
    // Required methods
    fn check(&self) -> Result<(), BreakerError>;
    fn record_success(&self);
    fn record_failure(&self);
}
Expand description
Unstable (feature: circuit-breaker) — may change or be removed
Behavior contract for circuit-breaking resilience.

SDK owns this trait + DefaultCircuitBreaker; consumers implement it for domain-specific traffic classes (A2A, HTTP, etc.). See docs/oxicode-sdk-ownership.md.

This trait is #[unstable] initially — the surface may evolve as we integrate with the agent loop and learn which signals consumers actually need. It graduates to #[stable] after it proves useful in production.

Required Methods§

Source

fn check(&self) -> Result<(), BreakerError>

Returns Err(BreakerError::Open) if the circuit is open (calls should fail-fast). The check is cheap (atomic load) so callers may invoke it before every retry.

Source

fn record_success(&self)

Record a successful call. Resets the failure count and, if the breaker was in HalfOpen, returns it to Closed.

Source

fn record_failure(&self)

Record a failed call. Increments the failure count; if the count reaches the configured threshold the breaker trips to Open.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§