Skip to content

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

fix(inference): flatten host demotion handling and parse inline retry hints

Steven Enamakel729ee9ecc2c0
diff --git a/crates/openhuman-core/src/inference/provider/http_error.rs b/crates/openhuman-core/src/inference/provider/http_error.rs
index 3600d7b825..b45f83b65f 100644
--- a/crates/openhuman-core/src/inference/provider/http_error.rs
+++ b/crates/openhuman-core/src/inference/provider/http_error.rs
@@ -184,92 +184,76 @@ impl ErrorReporter for HostErrorReporter<'_> {
if matches!(status, 401 | 403) && is_backend {
publish_backend_session_expired(operation, provider, status_code, self.message);
- } else if matches!(
- decision,
- HostDemotion::Provider(
- DemotionKind::BudgetExhausted
- | DemotionKind::NoModelLoaded
- | DemotionKind::CustomUpstreamBadRequest
- | DemotionKind::AccessPolicyDenied
- | DemotionKind::ConfigurationRejected
- | DemotionKind::ContextWindowExceeded
- | DemotionKind::QuotaExhausted
- )
- ) {
+ } else {
match decision {
- HostDemotion::Provider(kind) => match kind {
- DemotionKind::BudgetExhausted => {
- demote("budget", "budget-exhausted 400", false)
- }
- DemotionKind::NoModelLoaded => demote(
- "provider_user_state",
- "local_provider_no_model_loaded",
- false,
- ),
- DemotionKind::CustomUpstreamBadRequest => demote(
- "provider_user_state",
- "custom_openai_upstream_bad_request",
- false,
- ),
- DemotionKind::AccessPolicyDenied => demote(
- "provider_access_policy",
- "provider access-policy 403",
- false,
- ),
- DemotionKind::ConfigurationRejected => demote(
- "provider_config_rejection",
- "provider config-rejection",
- false,
- ),
- DemotionKind::ContextWindowExceeded => {
- demote("context_window_exceeded", "context-window exceeded", true)
- }
- DemotionKind::QuotaExhausted => {
- demote("quota_exhausted", "provider monthly-quota exhausted", false)
- }
- _ => unreachable!("only precedence-preserving decisions enter this arm"),
- },
- _ => unreachable!("precedence arm only selects provider demotions"),
- }
- } else if decision == HostDemotion::BackendOwned {
- demote("backend_error_code", "backend errorCode owned", false);
- } else if let HostDemotion::Provider(decision) = decision {
- match decision {
- DemotionKind::ApiKeyRejected => {
+ HostDemotion::Provider(DemotionKind::BudgetExhausted) => {
+ demote("budget", "budget-exhausted 400", false)
+ }
+ HostDemotion::Provider(DemotionKind::NoModelLoaded) => demote(
+ "provider_user_state",
+ "local_provider_no_model_loaded",
+ false,
+ ),
+ HostDemotion::Provider(DemotionKind::CustomUpstreamBadRequest) => demote(
+ "provider_user_state",
+ "custom_openai_upstream_bad_request",
+ false,
+ ),
+ HostDemotion::Provider(DemotionKind::AccessPolicyDenied) => demote(
+ "provider_access_policy",
+ "provider access-policy 403",
+ false,
+ ),
+ HostDemotion::Provider(DemotionKind::ConfigurationRejected) => demote(
+ "provider_config_rejection",
+ "provider config-rejection",
+ false,
+ ),
+ HostDemotion::Provider(DemotionKind::ContextWindowExceeded) => {
+ demote("context_window_exceeded", "context-window exceeded", true)
+ }
+ HostDemotion::Provider(DemotionKind::QuotaExhausted) => {
+ demote("quota_exhausted", "provider monthly-quota exhausted", false)
+ }
+ HostDemotion::BackendOwned => {
+ demote("backend_error_code", "backend errorCode owned", false)
+ }
+ HostDemotion::Provider(DemotionKind::ApiKeyRejected) => {
log_byo_provider_auth_failure(operation, provider, model, status_code)
}
- DemotionKind::OAuthSessionExpired => {
+ HostDemotion::Provider(DemotionKind::OAuthSessionExpired) => {
demote("provider_user_state", "openai_oauth_session_expired", false)
}
- DemotionKind::InsufficientCredits => demote(
+ HostDemotion::Provider(DemotionKind::InsufficientCredits) => demote(
"insufficient_credits",
"provider insufficient-credits 402",
false,
),
- DemotionKind::OllamaCloudInternalError => demote(
+ HostDemotion::Provider(DemotionKind::OllamaCloudInternalError) => demote(
"ollama_cloud_internal_500",
"Ollama Cloud hosted-inference 500",
false,
),
- DemotionKind::ModerationRejected => demote(
+ HostDemotion::Provider(DemotionKind::ModerationRejected) => demote(
"external_moderation_rejection",
"external content-moderation rejection",
false,
),
- _ => unreachable!("earlier decisions were handled above"),
+ HostDemotion::Report if should_report_provider_http_status(status) => {
+ let status_str = status.to_string();
+ crate::core::observability::report_error(
+ self.message,
+ "llm_provider",
+ "api_error",
+ &[
+ ("provider", provider),
+ ("status", status_str.as_str()),
+ ("failure", "non_2xx"),
+ ],
+ );
+ }
+ HostDemotion::Report => {}
}
- } else if should_report_provider_http_status(status) {
- let status_str = status.to_string();
- crate::core::observability::report_error(
- self.message,
- "llm_provider",
- "api_error",
- &[
- ("provider", provider),
- ("status", status_str.as_str()),
- ("failure", "non_2xx"),
- ],
- );
}
}
}
diff --git a/crates/openhuman-core/src/triage/evaluator/arm.rs b/crates/openhuman-core/src/triage/evaluator/arm.rs
index c12fa4f482..767d10cfcc 100644
--- a/crates/openhuman-core/src/triage/evaluator/arm.rs
+++ b/crates/openhuman-core/src/triage/evaluator/arm.rs
@@ -266,14 +266,19 @@ pub(crate) fn classify_error(message: String) -> ArmError {
FailoverDecision::RetrySame => ArmError::Retryable {
retry_after_ms: (reason == FailoverReason::RateLimit)
.then(|| {
- message.lines().find_map(|line| {
- line.trim()
- .strip_prefix("Retry-After:")
- .or_else(|| line.trim().strip_prefix("retry-after:"))
- .and_then(|value| {
- tinyinference_core::retry_after::parse_retry_after_ms(Some(value))
- })
- })
+ message
+ .lines()
+ .find_map(|line| {
+ line.trim()
+ .strip_prefix("Retry-After:")
+ .or_else(|| line.trim().strip_prefix("retry-after:"))
+ .and_then(|value| {
+ tinyinference_core::retry_after::parse_retry_after_ms(Some(
+ value,
+ ))
+ })
+ })
+ .or_else(|| tinyinference_llm::failure::parse_retry_after_ms(&message))
})
.flatten(),
source: err,
diff --git a/crates/openhuman-core/src/triage/evaluator_fallback_chain_tests.rs b/crates/openhuman-core/src/triage/evaluator_fallback_chain_tests.rs
index 61e3310330..3e7fb059a1 100644
--- a/crates/openhuman-core/src/triage/evaluator_fallback_chain_tests.rs
+++ b/crates/openhuman-core/src/triage/evaluator_fallback_chain_tests.rs
@@ -68,6 +68,26 @@ fn classify_string_recognises_429_with_retry_after() {
}
}
+#[test]
+fn classify_string_preserves_long_fractional_and_inline_retry_hints() {
+ for (message, expected) in [
+ ("HTTP 429 Too Many Requests; Retry-After: 60", 60_000),
+ (
+ "HTTP 429 Too Many Requests; Retry-After: 2.5 seconds",
+ 2_500,
+ ),
+ ("HTTP 429 Too Many Requests; retry_after 1.5", 1_500),
+ ] {
+ match classify_error(message.to_string()) {
+ ArmError::Retryable {
+ retry_after_ms: Some(actual),
+ ..
+ } => assert_eq!(actual, expected, "Retry-After in {message:?}"),
+ _ => panic!("expected retry hint {expected}ms from {message:?}"),
+ }
+ }
+}
+
#[test]
fn classify_string_recognises_5xx_as_transient() {
let err = classify_error("upstream returned 503 Service Unavailable".to_string());