Skip to content

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

chore: files changed crates/openhuman-tinyhumans/src/inference/managed_embedding.rs,crates/openhuman

Steven Enamakel9222c4e671eb
diff --git a/crates/openhuman-tinyhumans/src/inference/managed_embedding.rs b/crates/openhuman-tinyhumans/src/inference/managed_embedding.rs
index 37566b30b0..555f28a88a 100644
--- a/crates/openhuman-tinyhumans/src/inference/managed_embedding.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_embedding.rs
@@ -7,9 +7,9 @@ use std::sync::Arc;
use openhuman_embed::__host::egress::{emit_external_transfer, enforce_egress, EgressDescriptor};
use openhuman_embed::__host::inference_registry::EmbeddingRequest;
use openhuman_embed::__host::security::approval::ApprovalChatContext;
-use openhuman_embed::__host::security::credentials::{AuthService, APP_SESSION_PROVIDER};
use tinyinference_embeddings::{BearerResolver, CloudEmbeddingModel, EmbeddingModel};
+use super::managed_session::resolve_session_bearer;
use crate::backend::url::effective_api_url;
use crate::client::endpoint::is_managed_endpoint_for_api_key;
@@ -73,17 +73,13 @@ impl ManagedEmbeddingModel {
log::debug!("[tinyhumans][embeddings] authenticating with api-key");
return Ok(key);
}
- let auth = AuthService::new(&state_dir, secrets_encrypt);
- auth.get_provider_bearer_token(APP_SESSION_PROVIDER, None)
- .map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))?
- .filter(|token| !token.trim().is_empty())
- .ok_or_else(|| {
- tinyinference_embeddings::Error::Validation(
- "No backend session for cloud embeddings: log in to OpenHuman or set a \
- TinyHumans API key"
- .into(),
- )
- })
+ resolve_session_bearer(
+ &state_dir,
+ secrets_encrypt,
+ None,
+ "managed_embedding.resolve_bearer",
+ )
+ .map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))
});
let model = model.to_string();
Self {
diff --git a/crates/openhuman-tinyhumans/src/inference/managed_model.rs b/crates/openhuman-tinyhumans/src/inference/managed_model.rs
index a51443a0df..06451383fb 100644
--- a/crates/openhuman-tinyhumans/src/inference/managed_model.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_model.rs
@@ -24,9 +24,7 @@ use tinyinference_llm::providers::openai::OpenAiModel;
use tinyinference_llm::providers::ProviderRequestOptions;
use tinyinference_llm::Error as TiError;
-use openhuman_embed::__host::security::credentials::{AuthService, APP_SESSION_PROVIDER};
-
-use super::managed_session::managed_bearer;
+use super::managed_session::resolve_session_bearer;
use crate::backend::url::effective_api_url;
use crate::client::endpoint::is_managed_endpoint_for_api_key;
@@ -119,8 +117,6 @@ impl OpenHumanBackendModel {
}
pub(super) fn resolve_bearer(&self) -> anyhow::Result<String> {
- use openhuman_embed::__host::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>`,
// and there is no session — so no `exp` and no signed-out state — to
@@ -147,25 +143,12 @@ impl OpenHumanBackendModel {
);
return Ok(key);
}
- if openhuman_embed::__host::platform::llm_gate::is_signed_out() {
- anyhow::bail!(
- "SESSION_EXPIRED: backend session not active — sign in to resume LLM work"
- );
- }
- let auth = AuthService::new(&self.state_dir(), self.options.secrets_encrypt);
- let profile = auth.get_profile(
- APP_SESSION_PROVIDER,
+ resolve_session_bearer(
+ &self.state_dir(),
+ self.options.secrets_encrypt,
self.options.auth_profile_override.as_deref(),
- )?;
-
- // #5503: precheck the recorded JWT `exp` BEFORE building a request, the
- // same way `require_live_session_token` guards the backend REST callers.
- // Managed inference used to fire a doomed request on an expired-but-
- // 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.
- managed_bearer(classify_session_token(profile.as_ref(), chrono::Utc::now()))
+ "openhuman_backend_model.resolve_bearer",
+ )
}
/// The managed OpenAI-compatible endpoint, from the configured `api_url`
diff --git a/crates/openhuman-tinyhumans/src/inference/managed_session.rs b/crates/openhuman-tinyhumans/src/inference/managed_session.rs
index b563440c72..874c176ce1 100644
--- a/crates/openhuman-tinyhumans/src/inference/managed_session.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_session.rs
@@ -5,6 +5,27 @@
use tinyinference_llm::model::ProviderError;
use tinyinference_llm::Error as TiError;
+/// Resolve the persisted app-session token for a managed inference caller.
+/// Both chat and embeddings use this path so signed-out state, expiry checks,
+/// and offline-local credential refusal stay consistent.
+pub(super) fn resolve_session_bearer(
+ state_dir: &std::path::Path,
+ secrets_encrypt: bool,
+ profile_override: Option<&str>,
+ operation: &str,
+) -> anyhow::Result<String> {
+ use openhuman_embed::__host::security::credentials::session_support::classify_session_token;
+ use openhuman_embed::__host::security::credentials::{AuthService, APP_SESSION_PROVIDER};
+
+ if openhuman_embed::__host::platform::llm_gate::is_signed_out() {
+ anyhow::bail!("SESSION_EXPIRED: backend session not active — sign in to resume LLM work");
+ }
+ let auth = AuthService::new(state_dir, secrets_encrypt);
+ let profile = auth.get_profile(APP_SESSION_PROVIDER, profile_override)?;
+ let check = classify_session_token(profile.as_ref(), chrono::Utc::now());
+ managed_bearer_for(check, operation)
+}
+
/// The bearer a classified app-session token yields for managed inference.
///
/// Separate from `OpenHumanBackendModel::resolve_bearer` so the decision is
@@ -19,6 +40,13 @@ use tinyinference_llm::Error as TiError;
/// backend REST caller, and keeps the local credential intact.
pub(super) fn managed_bearer(
check: openhuman_embed::__host::security::credentials::session_support::SessionTokenCheck,
+) -> anyhow::Result<String> {
+ managed_bearer_for(check, "openhuman_backend_model.resolve_bearer")
+}
+
+fn managed_bearer_for(
+ check: openhuman_embed::__host::security::credentials::session_support::SessionTokenCheck,
+ operation: &str,
) -> anyhow::Result<String> {
use openhuman_embed::__host::security::credentials::session_support::{
is_local_session_token, SessionTokenCheck, LOCAL_SESSION_MANAGED_INFERENCE_UNAVAILABLE,
@@ -33,7 +61,7 @@ pub(super) fn managed_bearer(
}
SessionTokenCheck::Live(token) => Ok(token),
SessionTokenCheck::Expired => {
- maybe_publish_local_session_expiry();
+ maybe_publish_local_session_expiry(operation);
anyhow::bail!(
"SESSION_EXPIRED: backend session token expired locally — re-authentication required"
)
@@ -51,7 +79,7 @@ pub(super) fn managed_bearer(
/// pre-flight publish so the credentials subscriber clears state and the UI
/// re-auths exactly as it would on a real backend 401. Deduped via the
/// scheduler gate so N parallel managed turns in one tick don't emit N events.
-fn maybe_publish_local_session_expiry() {
+fn maybe_publish_local_session_expiry(operation: &str) {
if openhuman_embed::__host::platform::llm_gate::is_signed_out() {
return;
}
@@ -61,7 +89,7 @@ fn maybe_publish_local_session_expiry() {
);
openhuman_embed::__host::core::bus::BUS.publish(
openhuman_embed::__host::core::events::DomainEvent::SessionExpired {
- source: "openhuman_backend_model.resolve_bearer".to_string(),
+ source: operation.to_string(),
reason: "backend session token expired locally — re-authentication required"
.to_string(),
},