Skip to content

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

test(triage): handle overlapping outage attempts and terminal state in webhooks

Steven Enamakel648cf16e5f6c
diff --git a/crates/openhuman-core/src/agent/triage/evaluator/chain.rs b/crates/openhuman-core/src/agent/triage/evaluator/chain.rs
index a2413c8df7..1796560695 100644
--- a/crates/openhuman-core/src/agent/triage/evaluator/chain.rs
+++ b/crates/openhuman-core/src/agent/triage/evaluator/chain.rs
@@ -453,3 +453,21 @@ pub(crate) fn record_outage(
reason: format!("managed backend outage; retry {delay_ms}ms backoff"),
})
}
+
+#[cfg(test)]
+mod outage_attempt_tests {
+ use super::*;
+
+ #[test]
+ fn dropped_attempt_releases_in_flight_state() {
+ let state = RetryState::default();
+ let generation = begin_outage_attempt(Some(&state), "stub-cloud").expect("attempt");
+ drop(OutageAttempt {
+ state: &state,
+ key: "stub-cloud",
+ generation,
+ });
+
+ assert!(!state.lock().expect("retry state")["stub-cloud"].in_flight);
+ }
+}
diff --git a/crates/openhuman-core/src/agent/triage/evaluator_deferral_tests.rs b/crates/openhuman-core/src/agent/triage/evaluator_deferral_tests.rs
index d661678777..6e2d23e408 100644
--- a/crates/openhuman-core/src/agent/triage/evaluator_deferral_tests.rs
+++ b/crates/openhuman-core/src/agent/triage/evaluator_deferral_tests.rs
@@ -29,8 +29,30 @@ fn outage_backoff_is_exponential_and_has_terminal_limit() {
let outcome =
record_outage(Some(&state), "stub-cloud", Some(generation)).expect("terminal outcome");
assert!(matches!(outcome, TriageOutcome::Terminal { .. }));
+ let states = state.lock().expect("terminal outage state");
+ let outage = states.get("stub-cloud").expect("terminal outage retained");
+ assert_eq!(outage.consecutive_failures, 8);
+ assert!(outage.next_attempt_ms > chrono::Utc::now().timestamp_millis());
+ assert!(begin_outage_attempt(Some(&state), "stub-cloud").is_none());
}
+#[test]
+fn healthy_attempts_can_overlap_and_stale_failure_is_deferred() {
+ let state = std::sync::Mutex::new(std::collections::HashMap::new());
+ let first = begin_outage_attempt(Some(&state), "stub-cloud").expect("first attempt");
+ let second = begin_outage_attempt(Some(&state), "stub-cloud").expect("overlapping attempt");
+
+ assert!(matches!(
+ record_outage(Some(&state), "stub-cloud", Some(first)),
+ Some(TriageOutcome::Deferred { .. })
+ ));
+ assert!(matches!(
+ record_outage(Some(&state), "stub-cloud", Some(second)),
+ Some(TriageOutcome::Deferred { .. })
+ ));
+}
+
+
#[test]
fn outage_state_isolated_by_model() {
let state = std::sync::Mutex::new(std::collections::HashMap::new());
diff --git a/crates/openhuman-core/src/skills/webhooks/bus.rs b/crates/openhuman-core/src/skills/webhooks/bus.rs
index 932c12a70d..bb90c16222 100644
--- a/crates/openhuman-core/src/skills/webhooks/bus.rs
+++ b/crates/openhuman-core/src/skills/webhooks/bus.rs
@@ -332,7 +332,7 @@ async fn run_agent_trigger(
reason,
} => Ok(format!("Triage deferred until {defer_until_ms}: {reason}")),
crate::agent::triage::TriageOutcome::Terminal { reason } => {
- Err(format!("triage reached terminal state: {reason}"))
+ Ok(format!("Triage reached terminal state: {reason}"))
}
}
}