Skip to content

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

fix(inference): read a managed 401 as signed out, not a provider failure

Ghost Scripter628aceb63253
diff --git a/src/openhuman/inference/provider/ops/models.rs b/src/openhuman/inference/provider/ops/models.rs
index 034f3f4ff1..93f519fc12 100644
--- a/src/openhuman/inference/provider/ops/models.rs
+++ b/src/openhuman/inference/provider/ops/models.rs
@@ -255,6 +255,28 @@ pub async fn list_configured_models_from_config(
let status = response.status();
if !status.is_success() {
+ // A 401 from the MANAGED catalog means the caller is not signed in —
+ // the stored session was rejected server-side even though its local
+ // `exp` was still valid, so `require_live_session_token` handed us a
+ // token the backend no longer honours. That is a signed-out state, not
+ // a provider failure, and rendering it as "could not load models" put a
+ // red error under managed for a user whose only problem is a stale
+ // session. Managed stays selectable on its automatic routing, so return
+ // an empty catalog and let the app's normal auth surfaces prompt for
+ // re-authentication.
+ //
+ // Scoped to the managed provider on purpose: for a BYOK provider a 401
+ // IS the actionable error (a wrong or revoked API key), and hiding it
+ // would strand the user with a silently empty dropdown.
+ if managed_401_means_signed_out(status.as_u16(), entry.auth_style) {
+ log::info!(
+ "[providers][list_models] managed catalog unavailable — backend rejected the session token (401); returning an empty list"
+ );
+ return Ok(crate::rpc::RpcOutcome::new(
+ serde_json::json!({ "models": Vec::<ModelInfo>::new() }),
+ vec!["session not accepted; managed catalog is empty".to_string()],
+ ));
+ }
let body = response.text().await.unwrap_or_default();
let sanitized = sanitize_api_error(&body);
let truncated = crate::openhuman::util::truncate_with_ellipsis(&sanitized, 300);
@@ -593,6 +615,23 @@ pub fn model_items_from_body(body: &serde_json::Value) -> Option<Vec<serde_json:
.cloned()
}
+/// Whether a non-2xx from a `/models` probe should be read as "signed out"
+/// rather than a provider failure.
+///
+/// Only for the MANAGED provider, and only on 401. A managed 401 means the
+/// stored session was rejected server-side — often while its local `exp` is
+/// still valid, so nothing upstream flagged it — which is a signed-out state,
+/// not a broken provider. For a BYOK provider a 401 IS the actionable error (a
+/// wrong or revoked API key); swallowing it there would strand the user with a
+/// silently empty dropdown and no clue why.
+fn managed_401_means_signed_out(
+ status: u16,
+ auth_style: crate::openhuman::config::schema::cloud_providers::AuthStyle,
+) -> bool {
+ use crate::openhuman::config::schema::cloud_providers::AuthStyle;
+ status == 401 && auth_style == AuthStyle::OpenhumanJwt
+}
+
/// Whether a bearer credential may be attached to this URL.
///
/// `https` always, plus loopback over plain `http` so a locally-hosted backend
diff --git a/src/openhuman/inference/provider/ops/models_tests.rs b/src/openhuman/inference/provider/ops/models_tests.rs
index 13295f3100..b0c8b0f241 100644
--- a/src/openhuman/inference/provider/ops/models_tests.rs
+++ b/src/openhuman/inference/provider/ops/models_tests.rs
@@ -1,4 +1,7 @@
-use super::{resolve_local_runtime_key, synthesize_managed_entry, url_is_credential_safe};
+use super::{
+ managed_401_means_signed_out, resolve_local_runtime_key, synthesize_managed_entry,
+ url_is_credential_safe,
+};
use crate::openhuman::config::Config;
#[test]
@@ -80,3 +83,30 @@ fn other_slugs_do_not_synthesize_a_managed_entry() {
assert!(synthesize_managed_entry(slug).is_none(), "{slug}");
}
}
+
+/// A managed 401 is a signed-out state, not a provider failure: the stored
+/// session was rejected server-side while its local `exp` was still valid, so
+/// the picker rendered "could not load models" for a user whose only problem
+/// was a stale session.
+#[test]
+fn a_managed_401_reads_as_signed_out() {
+ use crate::openhuman::config::schema::cloud_providers::AuthStyle;
+ assert!(managed_401_means_signed_out(401, AuthStyle::OpenhumanJwt));
+}
+
+/// Everything else must keep surfacing the error. A BYOK 401 is the actionable
+/// case (wrong or revoked key) and must not be swallowed into an empty list,
+/// and a managed non-401 is a genuine provider failure.
+#[test]
+fn other_statuses_and_providers_still_surface_the_error() {
+ use crate::openhuman::config::schema::cloud_providers::AuthStyle;
+ for style in [AuthStyle::Bearer, AuthStyle::Anthropic, AuthStyle::None] {
+ assert!(!managed_401_means_signed_out(401, style), "{style:?} 401");
+ }
+ for status in [400, 403, 404, 429, 500, 503] {
+ assert!(
+ !managed_401_means_signed_out(status, AuthStyle::OpenhumanJwt),
+ "managed {status}"
+ );
+ }
+}