pub struct SelfHealingEngine {
pub config: HealingConfig,
/* private fields */
}Expand description
The self-healing engine tracks failures, manages circuit breakers, and provides retry-with-backoff for agent tasks.
This is the central coordination point for all self-healing in RavenClaws.
It is shared across the agent loop, swarm orchestrator, heartbeat agent,
and background task manager via Arc<RwLock<>>.
Fields§
§config: HealingConfigConfiguration
Implementations§
Source§impl SelfHealingEngine
impl SelfHealingEngine
Sourcepub fn with_config(config: HealingConfig) -> Self
pub fn with_config(config: HealingConfig) -> Self
Create a new self-healing engine with custom configuration.
Sourcepub fn record_failure(&mut self, agent_id: &str, error: &str) -> u32
pub fn record_failure(&mut self, agent_id: &str, error: &str) -> u32
Record a failure for an agent.
Returns the updated failure count for that agent.
Sourcepub fn record_success(&mut self, agent_id: &str)
pub fn record_success(&mut self, agent_id: &str)
Record a success for an agent — resets failure tracking.
Sourcepub fn is_healthy(&mut self, agent_id: &str) -> bool
pub fn is_healthy(&mut self, agent_id: &str) -> bool
Check if an agent is healthy.
An agent is healthy if:
- Its circuit breaker allows execution (Closed or HalfOpen)
- It’s not marked as dead
Sourcepub fn failure_count(&self, agent_id: &str) -> u32
pub fn failure_count(&self, agent_id: &str) -> u32
Get the failure count for an agent.
Sourcepub fn circuit_state(&self, agent_id: &str) -> Option<HealingCircuitState>
pub fn circuit_state(&self, agent_id: &str) -> Option<HealingCircuitState>
Get the circuit state for an agent.
Sourcepub fn dead_workers(&self) -> Vec<String>
pub fn dead_workers(&self) -> Vec<String>
Get a list of agent IDs that are marked as dead and past the replacement timeout.
Sourcepub fn all_dead_workers(&self) -> Vec<String>
pub fn all_dead_workers(&self) -> Vec<String>
Get a list of all agent IDs that are currently dead (regardless of timeout).
Sourcepub fn delay_for_attempt(&self, attempt: u32) -> Duration
pub fn delay_for_attempt(&self, attempt: u32) -> Duration
Calculate delay for a retry attempt using exponential backoff with jitter.
Sourcepub async fn retry_with_backoff<F, T>(
&self,
agent_id: &str,
is_transient: impl Fn(&str) -> bool,
operation: F,
) -> Result<T, String>
pub async fn retry_with_backoff<F, T>( &self, agent_id: &str, is_transient: impl Fn(&str) -> bool, operation: F, ) -> Result<T, String>
Execute an async function with retry and exponential backoff.
The function receives the attempt number (0-based) and should return
Ok(T) on success or Err(String) on failure.
Only transient errors should be retried — pass is_transient to classify.
Returns Ok(T) on success, or Err(String) with the last error after
all retries are exhausted.
Sourcepub fn reset_agent(&mut self, agent_id: &str)
pub fn reset_agent(&mut self, agent_id: &str)
Reset failure records for a specific agent.
Sourcepub fn tracked_agents(&self) -> usize
pub fn tracked_agents(&self) -> usize
Get the total number of tracked agents.
Sourcepub fn dead_agent_count(&self) -> usize
pub fn dead_agent_count(&self) -> usize
Get the number of dead agents.
Sourcepub fn open_circuit_count(&self) -> usize
pub fn open_circuit_count(&self) -> usize
Get the number of agents with open circuit breakers.
Trait Implementations§
Source§impl Debug for SelfHealingEngine
impl Debug for SelfHealingEngine
Auto Trait Implementations§
impl Freeze for SelfHealingEngine
impl RefUnwindSafe for SelfHealingEngine
impl Send for SelfHealingEngine
impl Sync for SelfHealingEngine
impl Unpin for SelfHealingEngine
impl UnsafeUnpin for SelfHealingEngine
impl UnwindSafe for SelfHealingEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request