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
feat(core): seed scheduler gate from api-key credential at startup
Steven Enamakel0b077cc49160
diff --git a/crates/openhuman-core/src/core/jsonrpc.rs b/crates/openhuman-core/src/core/jsonrpc.rsindex 5da59c4b95..a3bcacdf8d 100644--- a/crates/openhuman-core/src/core/jsonrpc.rs+++ b/crates/openhuman-core/src/core/jsonrpc.rs@@ -2065,30 +2065,37 @@ fn register_domain_subscribers(// battery-powered hosts).crate::cron::scheduler_gate::init_global(&config);- // Seed the scheduler-gate signed-out override from the on-disk session.- // Without this, a sidecar that boots with no stored JWT would happily- // spin up cron / channel loops and fire LLM requests that all 401.- match crate::api::jwt::get_session_token(&config) {- Ok(Some(_)) => {- crate::cron::scheduler_gate::set_signed_out(false);- }- Ok(None) => {- log::info!(- "[auth] no session token at startup — scheduler gate set to signed_out \- (config_path={}, keyring_backend={})",- config.config_path.display(),- crate::security::keyring::backend_name(),- );- crate::cron::scheduler_gate::set_signed_out(true);- }- Err(err) => {- log::warn!(- "[auth] failed to read session token at startup ({err}) — assuming signed_out \- (config_path={}, keyring_backend={})",- config.config_path.display(),- crate::security::keyring::backend_name(),- );- crate::cron::scheduler_gate::set_signed_out(true);+ // Seed the scheduler-gate signed-out override from the on-disk+ // credential — an API key (library runtime) or the app session.+ // Without this, a sidecar that boots with no stored credential would+ // happily spin up cron / channel loops and fire LLM requests that all+ // 401.+ if crate::security::credentials::api_key::has_api_key(&config) {+ log::info!("[auth] api-key credential present at startup — scheduler gate signed in");+ crate::cron::scheduler_gate::set_signed_out(false);+ } else {+ match crate::api::jwt::get_session_token(&config) {+ Ok(Some(_)) => {+ crate::cron::scheduler_gate::set_signed_out(false);+ }+ Ok(None) => {+ log::info!(+ "[auth] no session token at startup — scheduler gate set to signed_out \+ (config_path={}, keyring_backend={})",+ config.config_path.display(),+ crate::security::keyring::backend_name(),+ );+ crate::cron::scheduler_gate::set_signed_out(true);+ }+ Err(err) => {+ log::warn!(+ "[auth] failed to read session token at startup ({err}) — assuming signed_out \+ (config_path={}, keyring_backend={})",+ config.config_path.display(),+ crate::security::keyring::backend_name(),+ );+ crate::cron::scheduler_gate::set_signed_out(true);+ }}}diff --git a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs b/crates/openhuman-core/src/inference/provider/factory/access_gates.rsindex c4cc718879..bd454fc032 100644--- a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs+++ b/crates/openhuman-core/src/inference/provider/factory/access_gates.rs@@ -152,13 +152,6 @@ pub(crate) fn verify_session_active(config: &Config) -> anyhow::Result<()> {/// in a Library host. Library mode exempts caller-owned provider credentials;/// it cannot manufacture a TinyHumans account credential.pub(crate) fn verify_backend_session_active(config: &Config) -> anyhow::Result<()> {- // Fast path: the scheduler gate already knows the session is dead.- if crate::cron::scheduler_gate::is_signed_out() {- anyhow::bail!(- "SESSION_EXPIRED: backend session not active — sign in to use custom providers"- );- }- // Verify the app-session JWT actually exists in auth-profiles.let state_dir = config.config_path.parent()@@ -168,6 +161,19 @@ pub(crate) fn verify_backend_session_active(config: &Config) -> anyhow::Result<(.map(|d| d.home_dir().join(".openhuman")).unwrap_or_else(|| std::path::PathBuf::from(".openhuman"))});+ // An API key is a standing credential: no session to be active, nothing+ // for the scheduler gate to have expired.+ if crate::security::credentials::api_key::has_api_key_in(&state_dir, config.secrets.encrypt) {+ log::debug!("[providers][access-gate] api-key credential satisfies the backend session gate");+ return Ok(());+ }+ // Fast path: the scheduler gate already knows the session is dead.+ if crate::cron::scheduler_gate::is_signed_out() {+ anyhow::bail!(+ "SESSION_EXPIRED: backend session not active — sign in to use custom providers"+ );+ }+ // Verify the app-session JWT actually exists in auth-profiles.let auth = AuthService::new(&state_dir, config.secrets.encrypt);let has_session = auth.get_provider_bearer_token(crate::security::credentials::APP_SESSION_PROVIDER, None)?diff --git a/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs b/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rsindex 3596c083de..7f7f9a620a 100644--- a/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs+++ b/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs@@ -110,6 +110,17 @@ impl OpenHumanBackendModel {classify_session_token, SessionTokenCheck,};+ // 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+ // consult.+ if let Some(key) = crate::security::credentials::api_key::get_api_key_in(+ &self.state_dir(),+ self.options.secrets_encrypt,+ )? {+ log::debug!("[providers][openhuman-backend] authenticating managed inference with api-key");+ return Ok(key);+ }if crate::cron::scheduler_gate::is_signed_out() {anyhow::bail!("SESSION_EXPIRED: backend session not active — sign in to resume LLM work"diff --git a/crates/openhuman-core/src/security/credentials/bus.rs b/crates/openhuman-core/src/security/credentials/bus.rsindex 6b7c5fbad0..5a60584fab 100644--- a/crates/openhuman-core/src/security/credentials/bus.rs+++ b/crates/openhuman-core/src/security/credentials/bus.rs@@ -64,6 +64,17 @@ impl EventHandler<DomainEvent> for SessionExpiredSubscriber {match crate::config::rpc::load_config_with_timeout().await {Ok(config) => {+ // An API-key runtime has no session to clear: a backend 401 on+ // the key is a per-call error for the caller, not a sign-out.+ if crate::security::credentials::api_key::has_api_key(&config) {+ tracing::warn!(+ source = %source,+ reason = %reason,+ "[auth] SessionExpired ignored — runtime authenticates with an API key; re-enabling scheduler gate"+ );+ scheduler_gate::set_signed_out(false);+ return;+ }let is_local_session = crate::api::jwt::get_session_token(&config).ok().flatten()