The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(inference): key the managed 401 on whether the session was actually sent\n\nReview follow-up on #6206. The previous commit used `!managed_token.is_empty()`\nas a stand-in for "the request carried the app session token". That proxy is\nwrong in one case, and it reintroduced the very bug this PR exists to fix.\n\n`url_is_credential_safe` refuses to put a bearer token on a non-https,\nnon-loopback URL. With a live session and a misconfigured backend URL the\nrequest therefore goes out unauthenticated, and the 401 that comes back\ndescribes the URL, not the session — but `managed_token` is still non-empty, so\nthe catalog degraded to an empty list and hid the misconfiguration.\n\nTrack the fact instead of inferring it. `managed_session_attaches` is the single\nplace that decides, and its result is threaded into the 401 predicate:\n\n fn managed_session_attaches(managed_token: &str, url: &str) -> bool {\n !managed_token.is_empty() && url_is_credential_safe(url)\n }\n\nThe reduction is exact: whenever `managed_token` is non-empty it is the token\nbeing sent, so the caller's separate emptiness check is subsumed.\n\nExtracting it rather than passing a bare bool is what makes the case testable —\na bool argument cannot express "a live session that was withheld", so a test\ntaking one could only restate the fallback-key case. The new test drives the\nhelper over a matrix of safe and unsafe URLs, and a second test composes the two\nhalves to pin the end-to-end contract.\n\nClaude-Session: https://claude.ai/code/session_01TE9ECLDivW9LsMZmEkbK9F\n
Ghost Scripterbbf557966c88
diff --git a/src/openhuman/inference/provider/ops/models.rs b/src/openhuman/inference/provider/ops/models.rsindex d14297b3a6..87698a2485 100644--- a/src/openhuman/inference/provider/ops/models.rs+++ b/src/openhuman/inference/provider/ops/models.rs@@ -214,6 +214,11 @@ pub async fn list_configured_models_from_config(validate_openrouter_api_key(&client, &routing.endpoint, &api_key).await?;}+ // Whether the app session token actually made it onto the wire. It is not+ // the same question as "is `managed_token` non-empty": the credential-safety+ // guard below can decline to attach it, and a 401 on an unauthenticated+ // request must not be read as a stale session (review, #6206).+ let mut managed_session_attached = false;let mut request = client.get(&models_url);if routing.using_oauth {request = request@@ -249,6 +254,7 @@ pub async fn list_configured_models_from_config(} else {api_key.as_str()};+ managed_session_attached = managed_session_attaches(&managed_token, &models_url);// Never put a bearer credential on the wire in clear text. `https`// or a loopback host only — loopback stays allowed so a local// backend (BACKEND_URL=http://127.0.0.1:...) still works in dev.@@ -292,7 +298,8 @@ 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, &managed_token) {+ if managed_401_means_signed_out(status.as_u16(), entry.auth_style, managed_session_attached)+ {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.rsindex 1331b4a8bb..7e6a816b56 100644--- a/src/openhuman/inference/provider/ops/models_part_01.rs+++ b/src/openhuman/inference/provider/ops/models_part_01.rs@@ -92,16 +92,36 @@ fn url_is_credential_safe(url: &str) -> bool {/// 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.+/// Whether the app session token will actually be attached to the managed+/// request — the input to [`managed_401_means_signed_out`].+///+/// This is deliberately not "is there a session": `url_is_credential_safe`+/// refuses to put a bearer token on a non-https, non-loopback URL, and in that+/// case the request goes out unauthenticated even though a live session exists.+/// A 401 on that request describes the misconfigured URL, not the session.+///+/// Note the token-emptiness check in the caller is subsumed here: whenever+/// `managed_token` is non-empty it *is* the token being sent, so a non-empty+/// managed token plus a safe URL is exactly the attach condition.+fn managed_session_attaches(managed_token: &str, url: &str) -> bool {+ !managed_token.is_empty() && url_is_credential_safe(url)+}+fn managed_401_means_signed_out(status: u16,auth_style: crate::openhuman::config::schema::cloud_providers::AuthStyle,- managed_token: &str,+ managed_session_attached: bool,) -> bool {use crate::openhuman::config::schema::cloud_providers::AuthStyle;- // `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()+ // Only a 401 on a request that actually carried the app session token says+ // anything about the session. The two other ways to reach a 401 here are+ // real, actionable faults that must not be hidden behind an empty catalog+ // just because the entry's auth_style is OpenhumanJwt (review, #6206):+ //+ // * no session, so the request went out on the provider-scoped fallback+ // key — a 401 means THAT key is wrong or revoked.+ // * a live session that the credential-safety guard refused to attach+ // (non-https, non-loopback backend URL) — the request was+ // unauthenticated, and the misconfigured URL is the thing to report.+ status == 401 && auth_style == AuthStyle::OpenhumanJwt && managed_session_attached}diff --git a/src/openhuman/inference/provider/ops/models_tests.rs b/src/openhuman/inference/provider/ops/models_tests.rsindex 49a0ae0145..695a78ea25 100644--- a/src/openhuman/inference/provider/ops/models_tests.rs+++ b/src/openhuman/inference/provider/ops/models_tests.rs@@ -1,6 +1,6 @@use super::{- managed_401_means_signed_out, resolve_local_runtime_key, synthesize_managed_entry,- url_is_credential_safe,+ managed_401_means_signed_out, managed_session_attaches, resolve_local_runtime_key,+ synthesize_managed_entry, url_is_credential_safe,};use crate::openhuman::config::Config;@@ -94,7 +94,7 @@ fn a_managed_401_reads_as_signed_out() {assert!(managed_401_means_signed_out(401,AuthStyle::OpenhumanJwt,- "session-jwt"+ true));}@@ -107,7 +107,52 @@ fn a_401_against_the_fallback_key_still_surfaces() {assert!(!managed_401_means_signed_out(401,AuthStyle::OpenhumanJwt,- ""+ false+ ));+}++/// A live session is not enough on its own: the credential-safety guard refuses+/// to attach a bearer token to a non-https, non-loopback URL, so the request+/// goes out unauthenticated. Reporting that 401 as signed-out would hide the+/// misconfigured backend URL behind an empty catalog — the same failure this+/// whole change exists to stop.+#[test]+fn a_session_is_not_attached_to_an_unsafe_url() {+ for url in [+ "http://api.example.com/openai/v1/models",+ "http://192.168.1.10:8080/openai/v1/models",+ ] {+ assert!(+ !managed_session_attaches("session-jwt", url),+ "a live session must not be attached to {url}"+ );+ }+ for url in [+ "https://api.tinyhumans.ai/openai/v1/models",+ "http://127.0.0.1:8787/openai/v1/models",+ ] {+ assert!(+ managed_session_attaches("session-jwt", url),+ "a live session must be attached to {url}"+ );+ }+ // No session: nothing to attach, whatever the URL.+ assert!(!managed_session_attaches(+ "",+ "https://api.tinyhumans.ai/openai/v1/models"+ ));+}++/// The two halves composed: a live session withheld by the safety guard reaches+/// the 401 classifier as "not attached", so the error still surfaces.+#[test]+fn a_401_on_a_token_the_safety_guard_withheld_still_surfaces() {+ use crate::openhuman::config::schema::cloud_providers::AuthStyle;+ let attached = managed_session_attaches("session-jwt", "http://api.example.com/v1/models");+ assert!(!managed_401_means_signed_out(+ 401,+ AuthStyle::OpenhumanJwt,+ attached));}@@ -119,13 +164,13 @@ 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, "session-jwt"),+ !managed_401_means_signed_out(401, style, true),"{style:?} 401");}for status in [400, 403, 404, 429, 500, 503] {assert!(- !managed_401_means_signed_out(status, AuthStyle::OpenhumanJwt, "session-jwt"),+ !managed_401_means_signed_out(status, AuthStyle::OpenhumanJwt, true),"managed {status}");}