Skip to content

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

fix(inference): stop the managed catalog swallowing real credential faults

Ghost Scripterb2f57475535a
diff --git a/src/openhuman/inference/provider/ops/models.rs b/src/openhuman/inference/provider/ops/models.rs
index ba0c0a31bd..d14297b3a6 100644
--- a/src/openhuman/inference/provider/ops/models.rs
+++ b/src/openhuman/inference/provider/ops/models.rs
@@ -150,29 +150,51 @@ pub async fn list_configured_models_from_config(
// Do NOT propagate a missing session: a self-hosted entry may carry a
// provider-scoped key instead, and the auth arm below documents that
// fallback. Only fail when neither credential exists, so the error the
- // caller sees names the real problem. `require_live_session_token` also
- // publishes `SessionExpired` for a locally-expired token, which we still
- // want on the session path.
- match crate::openhuman::security::credentials::session_support::require_live_session_token(
- config,
- ) {
- Ok(token) => managed_token = token,
- // Signed out is not a provider failure. The managed catalog simply
- // has nothing to offer until there is a session, and the picker
- // still shows managed with its automatic routing — so return an
- // empty list rather than surfacing "could not load models".
- Err(err) if api_key.is_empty() => {
+ // caller sees names the real problem.
+ //
+ // Classify the session directly rather than going through
+ // `require_live_session_token`, which flattens "signed out" and "could
+ // not read the credential store" into one opaque Err. A lock timeout or
+ // filesystem error is a recoverable fault the picker should surface —
+ // swallowing it into a successful empty catalog hides it (review, #6206).
+ // A store error still propagates; only a genuinely absent/expired
+ // session degrades to an empty list.
+ use crate::openhuman::security::credentials::session_support::{
+ classify_session_token, load_app_session_profile, publish_local_session_expiry,
+ SessionTokenCheck,
+ };
+ let profile = load_app_session_profile(config)?;
+ match classify_session_token(profile.as_ref(), chrono::Utc::now()) {
+ SessionTokenCheck::Live(token) => managed_token = token,
+ // Signed out is not a provider failure. The managed catalog has
+ // nothing to offer until there is a session, and managed stays
+ // selectable on its automatic routing — so return an empty list
+ // rather than surfacing "could not load models".
+ check if api_key.is_empty() => {
+ let reason = match check {
+ SessionTokenCheck::Expired => {
+ // Still announce the expiry: `require_live_session_token`
+ // did this for us before, and without it an expired token
+ // stays in the store with nothing prompting a re-auth.
+ publish_local_session_expiry("list_configured_models");
+ "session expired"
+ }
+ _ => "no session",
+ };
log::info!(
- "[providers][list_models] managed catalog unavailable — no live session ({err}); returning an empty list"
+ "[providers][list_models] managed catalog unavailable — {reason}; returning an empty list"
);
return Ok(crate::rpc::RpcOutcome::new(
serde_json::json!({ "models": Vec::<ModelInfo>::new() }),
- vec!["no live session; managed catalog is empty".to_string()],
+ vec![format!("{reason}; managed catalog is empty")],
));
}
- Err(err) => {
+ check => {
+ if matches!(check, SessionTokenCheck::Expired) {
+ publish_local_session_expiry("list_configured_models");
+ }
log::debug!(
- "[providers][list_models] no live session ({err}); falling back to the provider-scoped key"
+ "[providers][list_models] no live session; falling back to the provider-scoped key"
);
}
}
@@ -270,7 +292,7 @@ pub async fn list_configured_models_from_config(
// 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) {
+ if managed_401_means_signed_out(status.as_u16(), entry.auth_style, &managed_token) {
log::info!(
"[providers][list_models] managed catalog unavailable — backend rejected the session token (401); returning an empty list"
);
diff --git a/src/openhuman/inference/provider/ops/models_part_01.rs b/src/openhuman/inference/provider/ops/models_part_01.rs
index 7aaab3f65f..1331b4a8bb 100644
--- a/src/openhuman/inference/provider/ops/models_part_01.rs
+++ b/src/openhuman/inference/provider/ops/models_part_01.rs
@@ -95,7 +95,13 @@ fn url_is_credential_safe(url: &str) -> bool {
fn managed_401_means_signed_out(
status: u16,
auth_style: crate::openhuman::config::schema::cloud_providers::AuthStyle,
+ managed_token: &str,
) -> bool {
use crate::openhuman::config::schema::cloud_providers::AuthStyle;
- status == 401 && auth_style == AuthStyle::OpenhumanJwt
+ // `managed_token` non-empty means the request actually carried the app
+ // session. When it is empty the request went out with the provider-scoped
+ // fallback key instead, and a 401 then means THAT key is wrong or revoked —
+ // an actionable credential error that must not be hidden behind an empty
+ // catalog just because the entry's auth_style is OpenhumanJwt (review, #6206).
+ status == 401 && auth_style == AuthStyle::OpenhumanJwt && !managed_token.is_empty()
}
diff --git a/src/openhuman/inference/provider/ops/models_tests.rs b/src/openhuman/inference/provider/ops/models_tests.rs
index b0c8b0f241..49a0ae0145 100644
--- a/src/openhuman/inference/provider/ops/models_tests.rs
+++ b/src/openhuman/inference/provider/ops/models_tests.rs
@@ -91,7 +91,24 @@ fn other_slugs_do_not_synthesize_a_managed_entry() {
#[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));
+ assert!(managed_401_means_signed_out(
+ 401,
+ AuthStyle::OpenhumanJwt,
+ "session-jwt"
+ ));
+}
+
+/// When no session existed, the request went out with the provider-scoped
+/// fallback key — so a 401 means THAT key is wrong or revoked. Hiding it behind
+/// an empty catalog would strand a self-hosted entry with no clue why.
+#[test]
+fn a_401_against_the_fallback_key_still_surfaces() {
+ 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
@@ -101,11 +118,14 @@ fn a_managed_401_reads_as_signed_out() {
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");
+ assert!(
+ !managed_401_means_signed_out(401, style, "session-jwt"),
+ "{style:?} 401"
+ );
}
for status in [400, 403, 404, 429, 500, 503] {
assert!(
- !managed_401_means_signed_out(status, AuthStyle::OpenhumanJwt),
+ !managed_401_means_signed_out(status, AuthStyle::OpenhumanJwt, "session-jwt"),
"managed {status}"
);
}
diff --git a/src/openhuman/security/credentials/session_support.rs b/src/openhuman/security/credentials/session_support.rs
index b0521ea455..42c4c94f6f 100644
--- a/src/openhuman/security/credentials/session_support.rs
+++ b/src/openhuman/security/credentials/session_support.rs
@@ -211,20 +211,7 @@ pub fn require_live_session_token(config: &Config) -> Result<String, String> {
Err("no backend session token; run auth_store_session first".to_string())
}
SessionTokenCheck::Expired => {
- // Dedupe the publish via the scheduler gate so N parallel authed
- // callers in one tick don't emit N SessionExpired events.
- if !crate::openhuman::cron::scheduler_gate::is_signed_out() {
- tracing::info!(
- domain = "credentials",
- operation = "require_live_session_token",
- "[credentials] app-session token expired locally — publishing SessionExpired before any backend call"
- );
- crate::core::bus::BUS.publish(crate::core::events::DomainEvent::SessionExpired {
- source: "credentials.local_expiry_precheck".to_string(),
- reason: "backend session token expired locally — re-authentication required"
- .to_string(),
- });
- }
+ publish_local_session_expiry("require_live_session_token");
Err(
"SESSION_EXPIRED: backend session token expired locally — re-authentication required"
.to_string(),
@@ -233,6 +220,34 @@ pub fn require_live_session_token(config: &Config) -> Result<String, String> {
}
}
+/// Announce a locally-detected session expiry on the bus so
+/// `SessionExpiredSubscriber` clears credentials and the UI re-authenticates,
+/// exactly as it would on a real network 401.
+///
+/// Callers that classify the session themselves — rather than going through
+/// [`require_live_session_token`] — MUST call this on the
+/// [`SessionTokenCheck::Expired`] arm. Classifying without publishing leaves an
+/// expired token in the store with the scheduler gate still open, so nothing
+/// ever prompts a re-auth (that regression was caught in review on #6206).
+///
+/// `operation` names the calling site for the log line only.
+pub fn publish_local_session_expiry(operation: &'static str) {
+ // Dedupe the publish via the scheduler gate so N parallel authed
+ // callers in one tick don't emit N SessionExpired events.
+ if crate::openhuman::cron::scheduler_gate::is_signed_out() {
+ return;
+ }
+ tracing::info!(
+ domain = "credentials",
+ operation = operation,
+ "[credentials] app-session token expired locally — publishing SessionExpired before any backend call"
+ );
+ crate::core::bus::BUS.publish(crate::core::events::DomainEvent::SessionExpired {
+ source: "credentials.local_expiry_precheck".to_string(),
+ reason: "backend session token expired locally — re-authentication required".to_string(),
+ });
+}
+
/// Load the `app-session` profile once. Callers that need both the
/// session-state view (`session_state_from_profile`) AND the raw token
/// (`session_token_from_profile`) should call this once and pass the