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(user_agents): drop the other credential kind when storing one
Steven Enamakel3e9de35e927e
diff --git a/crates/openhuman-core/src/user_agents/credentials.rs b/crates/openhuman-core/src/user_agents/credentials.rsindex f91060b467..d15f1b3167 100644--- a/crates/openhuman-core/src/user_agents/credentials.rs+++ b/crates/openhuman-core/src/user_agents/credentials.rs@@ -34,7 +34,8 @@ pub enum UserCredentialKind {ApiKey,}-/// Store `token` as agent `config`'s credential of `kind`.+/// Store `token` as agent `config`'s credential of `kind`, replacing any+/// credential of the other kind.////// `expires_at` (RFC 3339) lets the core reject an expired session locally/// instead of sending a doomed request.@@ -70,6 +71,22 @@ pub fn store(.map_err(|e| e.to_string())?;}}+ // Then drop the other kind, which would otherwise keep winning (an API+ // key is resolved before a session). The new credential is written first,+ // so a failure here never leaves the agent with none; it is reported so+ // the gateway can retry.+ let replaced = match kind {+ UserCredentialKind::Session => api_key::clear_api_key(config).map_err(|e| e.to_string()),+ UserCredentialKind::ApiKey => AuthService::from_config(config)+ .remove_profile(APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFILE_NAME)+ .map_err(|e| e.to_string()),+ };+ if let Err(error) = replaced {+ log::warn!("[user_agents][credentials] stored {kind:?} but could not remove the other kind: {error}");+ return Err(format!(+ "stored the new credential but could not remove the previous one: {error}"+ ));+ }log::debug!("[user_agents][credentials] stored {kind:?} credential in {}",configdiff --git a/crates/openhuman-rpc/src/server/saas_gateway.rs b/crates/openhuman-rpc/src/server/saas_gateway.rsindex a2002a69be..eea050e85f 100644--- a/crates/openhuman-rpc/src/server/saas_gateway.rs+++ b/crates/openhuman-rpc/src/server/saas_gateway.rs@@ -67,9 +67,21 @@ pub(crate) async fn saas_gateway(operator: Arc<CoreContext>, req: Request, next:return refuse(404, "not found");}- let Some(user) = header_str(&req, USER_HEADER).map(str::to_owned) else {+ // Absent means the operator plane. Present but unreadable, or present+ // twice, is refused: falling back to the operator would skip the user+ // signature check.+ let mut user_headers = req.headers().get_all(USER_HEADER).iter();+ let Some(first) = user_headers.next() else {return CoreContext::scope(operator, next.run(req)).await;};+ if user_headers.next().is_some() {+ log::debug!("[rpc:saas] refusing a request with more than one {USER_HEADER}");+ return refuse(400, "more than one user header");+ }+ let Ok(user) = first.to_str().map(str::to_owned) else {+ log::debug!("[rpc:saas] refusing an unreadable {USER_HEADER}");+ return refuse(400, "unreadable user header");+ };let Some(secret) = openhuman_core::core::auth::get_rpc_token() else {return refuse(503, "the core is not ready");