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): refuse managed inference for the offline local session
obchain195f3c0cc96d
diff --git a/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs b/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rsindex 1de0f259af..d7b2caeefa 100644--- a/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs+++ b/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs@@ -170,9 +170,7 @@ impl OpenHumanBackendModel {}fn resolve_bearer(&self) -> anyhow::Result<String> {- use crate::security::credentials::session_support::{- classify_session_token, SessionTokenCheck,- };+ use crate::security::credentials::session_support::classify_session_token;// A stored API key (library runtime) is the bearer outright: the// OpenAI-compatible managed endpoint accepts it as `Bearer <key>`,@@ -217,23 +215,8 @@ impl OpenHumanBackendModel {// stored token and let the 401 come back — but an expired session can// also surface upstream as a misleading "model unavailable", which is a// core symptom of #5503 (all tiers "die" over a long session). Failing- // fast as `session_expired` routes the user to re-auth instead. Offline- // / local sessions (`is_local_session_token`) and `exp`-less tokens- // carry no recorded expiry, so `classify_session_token` returns `Live`- // for them — their behaviour is unchanged and the post-call 401 net- // still covers a server-side revocation.- match classify_session_token(profile.as_ref(), chrono::Utc::now()) {- SessionTokenCheck::Live(token) => Ok(token),- SessionTokenCheck::Expired => {- maybe_publish_local_session_expiry();- anyhow::bail!(- "SESSION_EXPIRED: backend session token expired locally — re-authentication required"- )- }- SessionTokenCheck::Absent => {- anyhow::bail!("No backend session: store a JWT via auth (app-session)")- }- }+ // fast as `session_expired` routes the user to re-auth instead.+ managed_bearer(classify_session_token(profile.as_ref(), chrono::Utc::now()))}/// The managed OpenAI-compatible endpoint, from the installed backend@@ -511,6 +494,45 @@ fn with_thread_id(request: ModelRequest, thread_id: Option<&str>) -> ModelRequesrequest.with_provider_options(options)}+/// The bearer a classified app-session token yields for managed inference.+///+/// Separate from [`OpenHumanBackendModel::resolve_bearer`] so the decision is+/// testable without an on-disk auth profile.+///+/// `exp`-less tokens carry no recorded expiry, so `classify_session_token`+/// reports them `Live`; the offline local session is one of those, and it+/// authenticates no TinyHumans account. Sending it anyway earned a backend+/// `401 "Invalid token"`, which published `SessionExpired` and told a user who+/// was signed in locally that their session had expired (#6932). Refusing here+/// mirrors the arm `resolve_backend_credential` already applies to every+/// backend REST caller, and keeps the local credential intact.+fn managed_bearer(+ check: crate::security::credentials::session_support::SessionTokenCheck,+) -> anyhow::Result<String> {+ use crate::security::credentials::session_support::{+ is_local_session_token, SessionTokenCheck, LOCAL_SESSION_MANAGED_INFERENCE_UNAVAILABLE,+ };++ match check {+ SessionTokenCheck::Live(token) if is_local_session_token(&token) => {+ log::debug!(+ "[providers][openhuman-backend] refusing managed inference for the offline local session"+ );+ anyhow::bail!(LOCAL_SESSION_MANAGED_INFERENCE_UNAVAILABLE)+ }+ SessionTokenCheck::Live(token) => Ok(token),+ SessionTokenCheck::Expired => {+ maybe_publish_local_session_expiry();+ anyhow::bail!(+ "SESSION_EXPIRED: backend session token expired locally — re-authentication required"+ )+ }+ SessionTokenCheck::Absent => {+ anyhow::bail!("No backend session: store a JWT via auth (app-session)")+ }+ }+}+/// Publish a `SessionExpired` event when the local `exp` precheck in/// [`resolve_bearer`](OpenHumanBackendModel::resolve_bearer) rejects an expired/// managed session token before a request is ever sent — mirroringdiff --git a/crates/openhuman-core/src/inference/provider/openhuman_backend_model_tests.rs b/crates/openhuman-core/src/inference/provider/openhuman_backend_model_tests.rsindex f80160e373..7b6a30fdba 100644--- a/crates/openhuman-core/src/inference/provider/openhuman_backend_model_tests.rs+++ b/crates/openhuman-core/src/inference/provider/openhuman_backend_model_tests.rs@@ -713,3 +713,48 @@ fn resolve_bearer_returns_token_for_exp_less_offline_session() {}#[path = "openhuman_backend_model_endpoint_tests.rs"]mod endpoint_tests;++// #6932: the offline local profile is a valid sign-in with no TinyHumans+// account behind it. `classify_session_token` reports its `exp`-less token+// `Live`, so managed inference used to send it, collect a backend+// `401 "Invalid token"` and surface that as an expired session.+#[test]+fn the_offline_local_session_cannot_authenticate_managed_inference() {+ use crate::security::credentials::session_support::{+ SessionTokenCheck, LOCAL_SESSION_MANAGED_INFERENCE_UNAVAILABLE,+ };++ let error = managed_bearer(SessionTokenCheck::Live("header.payload.local".to_string()))+ .expect_err("a local session has no managed bearer");++ assert_eq!(+ error.to_string(),+ LOCAL_SESSION_MANAGED_INFERENCE_UNAVAILABLE+ );+}++#[test]+fn the_refusal_does_not_read_as_an_expired_session() {+ use crate::security::credentials::session_support::SessionTokenCheck;++ let error = managed_bearer(SessionTokenCheck::Live("header.payload.local".to_string()))+ .expect_err("a local session has no managed bearer");++ // The whole point of the fix: this must not reach the sign-out path that+ // the backend's 401 envelope used to trigger.+ assert!(!crate::core::observability::is_session_expired_message(+ &error.to_string()+ ));+}++#[test]+fn a_signed_in_session_still_authenticates_managed_inference() {+ use crate::security::credentials::session_support::SessionTokenCheck;++ let bearer = managed_bearer(SessionTokenCheck::Live(+ "header.payload.signature".to_string(),+ ))+ .expect("a hosted session is the bearer");++ assert_eq!(bearer, "header.payload.signature");+}diff --git a/crates/openhuman-core/src/security/credentials/README.md b/crates/openhuman-core/src/security/credentials/README.mdindex 4a54ae0272..423d0aac3f 100644--- a/crates/openhuman-core/src/security/credentials/README.md+++ b/crates/openhuman-core/src/security/credentials/README.md@@ -37,7 +37,7 @@ Credential management for the backend credential the core authenticates with and- **`AuthService`** (`core.rs`) — `from_config`, `new`, `load_profiles`, `store_provider_token`, `set_active_profile`, `remove_profile`, `get_profile`, `get_provider_bearer_token`.- **Constants** — `APP_SESSION_PROVIDER` (`"app-session"`), `DEFAULT_AUTH_PROFILE_NAME` (`"default"`), `COMPOSIO_DIRECT_PROVIDER` (`"composio-direct"`), `api_key::API_KEY_PROVIDER` (`"api-key"`).-- **Credential kinds** — `session_support::CredentialKind {Session, ApiKey, Local}` (wire values `"session"`, `"api-key"`, `"local"`). `session_support::resolve_backend_credential` returns `BackendCredential::ApiKey` when a key is stored (before any session classification) and `BackendCredential::Session` otherwise; `BackendOAuthClient::authed_json` sends an API key as `x-api-key` and a session as `Authorization: Bearer`, while `OpenHumanBackendModel::resolve_bearer` sends the key as the bearer for managed inference. Every backend caller goes through it (integrations, voice, channels, webhooks, hosted proxies); bearer-only seams (connector proxy route, memory-host `SessionBearer`, the Socket.IO handshake) use `backend_bearer_secret`, which returns the key first and the stored session otherwise — the backend accepts a key as `Authorization: Bearer` by its `tiny_` prefix. Cloud embeddings mirror `resolve_bearer`. `has_backend_credential` is the boot-time "signed in?" question the scheduler gate asks; `SessionExpired` is ignored for an API-key runtime and for a local session.+- **Credential kinds** — `session_support::CredentialKind {Session, ApiKey, Local}` (wire values `"session"`, `"api-key"`, `"local"`). `session_support::resolve_backend_credential` returns `BackendCredential::ApiKey` when a key is stored (before any session classification) and `BackendCredential::Session` otherwise; `BackendOAuthClient::authed_json` sends an API key as `x-api-key` and a session as `Authorization: Bearer`, while `OpenHumanBackendModel::resolve_bearer` sends the key as the bearer for managed inference. Every backend caller goes through it (integrations, voice, channels, webhooks, hosted proxies); bearer-only seams (connector proxy route, memory-host `SessionBearer`, the Socket.IO handshake) use `backend_bearer_secret`, which returns the key first and the stored session otherwise — the backend accepts a key as `Authorization: Bearer` by its `tiny_` prefix. Cloud embeddings mirror `resolve_bearer`. `has_backend_credential` is the boot-time "signed in?" question the scheduler gate asks; `SessionExpired` is ignored for an API-key runtime and for a local session. A local session also has no managed bearer: `resolve_backend_credential` answers `LOCAL_SESSION_BACKEND_UNAVAILABLE` and `resolve_bearer` answers `LOCAL_SESSION_MANAGED_INFERENCE_UNAVAILABLE`, so neither hosted REST nor managed inference sends a token the backend will only 401 (#6932).- **Helpers** — `normalize_provider`, `default_profile_id`, `select_profile_id`, `state_dir_from_config`, `profile_id`.- **Types** (`profiles.rs`) — `AuthProfile`, `AuthProfileKind` (`OAuth`/`Token`), `TokenSet`, `AuthProfilesData`, `AuthProfilesStore`.- **Ops/RPC** (`ops`, re-exported as `rpc`) — `set_credential`, `clear_credential`, `store_session`, `clear_session`, `SetCredentialRequest`, `seed_api_key_from_env`, `seed_session_from_env`, `auth_get_state`, `auth_get_session_token_json`, `store_provider_credentials`, `remove_provider_credentials`, `list_provider_credentials`, `list_provider_credentials_by_prefix`, `encrypt_secret`, `decrypt_secret`, `start_credential_gated_services`, `stop_credential_gated_services`.diff --git a/crates/openhuman-core/src/security/credentials/session_support.rs b/crates/openhuman-core/src/security/credentials/session_support.rsindex 744495dd5f..9f91c456ad 100644--- a/crates/openhuman-core/src/security/credentials/session_support.rs+++ b/crates/openhuman-core/src/security/credentials/session_support.rs@@ -359,6 +359,16 @@ impl BackendCredential {pub const LOCAL_SESSION_BACKEND_UNAVAILABLE: &str ="BACKEND_UNAVAILABLE: hosted account data is unavailable for the offline local session";+/// Error [`OpenHumanBackendModel::resolve_bearer`](crate::inference::provider::OpenHumanBackendModel)+/// returns for the offline local session. The local credential authenticates+/// no TinyHumans account, so managed inference has nothing to bill or route;+/// sending the token anyway earned a backend `401` that read to the user as an+/// expired session (#6932). Distinct from+/// [`LOCAL_SESSION_BACKEND_UNAVAILABLE`] because the chat surface renders this+/// one as its own failure class.+pub const LOCAL_SESSION_MANAGED_INFERENCE_UNAVAILABLE: &str =+ "BACKEND_UNAVAILABLE: managed inference is unavailable for the offline local session";+/// Resolve the backend credential for `config`: the API key when one is/// stored, else the live app-session token with exactly the classification/// [`require_live_session_token`] has always applied.