Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(triage): extract rejection delay and pass retry state to clear_outage

Steven Enamakel1218f424a441
diff --git a/crates/openhuman-core/src/triage/evaluator/chain.rs b/crates/openhuman-core/src/triage/evaluator/chain.rs
index 2bcec0c700..7c74c647f1 100644
--- a/crates/openhuman-core/src/triage/evaluator/chain.rs
+++ b/crates/openhuman-core/src/triage/evaluator/chain.rs
@@ -135,12 +135,7 @@ where
match state.try_acquire(retry_key.clone(), monotonic_ms()) {
Ok(attempt) => Some(attempt),
Err(rejection) => {
- let delta_ms = match rejection {
- BreakerRejection::Backoff {
- next_attempt_ms, ..
- } => next_attempt_ms.saturating_sub(monotonic_ms()),
- BreakerRejection::InFlight => 1_000,
- };
+ let delta_ms = rejection_delay_ms(rejection, monotonic_ms());
return Ok(TriageOutcome::Deferred {
defer_until_ms: now_ms().saturating_add(delta_ms as i64),
reason: "managed backend paused; retry window not reached".to_string(),
@@ -168,11 +163,11 @@ where
// ── Cloud arm ──────────────────────────────────────────────────
match try_arm(&cloud, envelope, TriageResolutionPath::Cloud).await {
Ok(run) => {
- clear_outage(outage_attempt.as_mut());
+ clear_outage(retry_state, &retry_key, outage_attempt.as_mut());
return Ok(TriageOutcome::Decision(run));
}
Err(ArmError::Fatal(err)) => {
- clear_outage(outage_attempt.as_mut());
+ clear_outage(retry_state, &retry_key, outage_attempt.as_mut());
return Err(err);
}
Err(ArmError::BudgetExhausted(err)) => {
@@ -236,11 +231,11 @@ where
match try_arm(&cloud, envelope, TriageResolutionPath::CloudAfterRetry).await {
Ok(run) => {
- clear_outage(outage_attempt.as_mut());
+ clear_outage(retry_state, &retry_key, outage_attempt.as_mut());
return Ok(TriageOutcome::Decision(run));
}
Err(ArmError::Fatal(err)) => {
- clear_outage(outage_attempt.as_mut());
+ clear_outage(retry_state, &retry_key, outage_attempt.as_mut());
return Err(err);
}
Err(ArmError::BudgetExhausted(err)) => {
@@ -313,7 +308,7 @@ where
"cloud retry exhausted; local arm unavailable".to_string()
};
if cloud_budget_exhausted.is_some() || cloud_safety_flagged.is_some() {
- clear_outage(outage_attempt.as_mut());
+ clear_outage(retry_state, &retry_key, outage_attempt.as_mut());
return Ok(TriageOutcome::Terminal { reason });
}
@@ -337,7 +332,7 @@ where
match try_arm(&local, envelope, TriageResolutionPath::LocalFallback).await {
Ok(run) => {
- clear_outage(outage_attempt.as_mut());
+ clear_outage(retry_state, &retry_key, outage_attempt.as_mut());
Ok(TriageOutcome::Decision(run))
}
Err(ArmError::Fatal(err))
@@ -386,12 +381,25 @@ fn now_ms() -> i64 {
chrono::Utc::now().timestamp_millis()
}
-fn clear_outage(attempt: Option<&mut PersistentFailoverAttempt<String>>) {
+fn clear_outage(
+ _state: Option<&RetryState>,
+ _key: &str,
+ attempt: Option<&mut PersistentFailoverAttempt<String>>,
+) {
if let Some(attempt) = attempt {
attempt.record_success();
}
}
+fn rejection_delay_ms(rejection: BreakerRejection, now_ms: u64) -> u64 {
+ match rejection {
+ BreakerRejection::Backoff {
+ next_attempt_ms, ..
+ } => next_attempt_ms.saturating_sub(now_ms),
+ BreakerRejection::InFlight => 1_000,
+ }
+}
+
pub(crate) fn begin_outage_attempt(
state: Option<&RetryState>,
key: &str,