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(credentials): clear identity and refine session error handling
Steven Enamakela4d343db4e44
diff --git a/crates/openhuman-core/src/security/credentials/ops/credential.rs b/crates/openhuman-core/src/security/credentials/ops/credential.rsindex 1234db94bc..8f77a7bf71 100644--- a/crates/openhuman-core/src/security/credentials/ops/credential.rs+++ b/crates/openhuman-core/src/security/credentials/ops/credential.rs@@ -184,6 +184,9 @@ pub async fn set_credential(if resolved.kind == CredentialKind::ApiKey {api_key::store_api_key(config, &resolved.token).map_err(|e| e.to_string())?;+ // API-key-backed runs must not retain a previous session identity in+ // prompt composition or observability scope.+ identity::clear_current_user();crate::cron::scheduler_gate::set_signed_out(false);tracing::info!(domain = "credentials",@@ -294,6 +297,7 @@ pub async fn set_credential(identity::set_current_user(resolved.user.clone().or_else(|| {existing.as_ref()+ .filter(|_| refresh).and_then(|p| p.metadata.get("user_json").cloned()).and_then(|raw| serde_json::from_str(&raw).ok())}));diff --git a/crates/openhuman-session/src/client.rs b/crates/openhuman-session/src/client.rsindex a9dae533c4..3d4623e220 100644--- a/crates/openhuman-session/src/client.rs+++ b/crates/openhuman-session/src/client.rs@@ -152,8 +152,10 @@ impl FetchMeError {fn from_sdk(error: tinyhumans_sdk::Error) -> Self {match error {tinyhumans_sdk::Error::Status { status, body } => {- let message = format!("http {status}: {body}");- if TRANSIENT_STATUSES.contains(&status) {+ // Error bodies are controlled by the backend or an intervening+ // proxy. Do not carry them into the manager's logs.+ let message = format!("http {status}: {}", error_body_shape(&body));+ if TRANSIENT_STATUSES.contains(&status) || (500..=599).contains(&status) {Self::Transient(message)} else {Self::Rejected(message)@@ -165,13 +167,19 @@ impl FetchMeError {if contains_transient_transport_phrase(&message) {Self::Transport(message)} else {- Self::Rejected(message)+ // A decoding or SDK failure provides no authoritative+ // evidence that the credential was refused.+ Self::Transport("unexpected backend client failure".to_string())}}}}}+fn error_body_shape(body: &str) -> &'static str {+ if body.trim().is_empty() { "empty response body" } else { "non-empty response body" }+}+impl std::fmt::Display for FetchMeError {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {match self {diff --git a/crates/openhuman-session/src/manager.rs b/crates/openhuman-session/src/manager.rsindex 4f1bb7ff9d..d1e17f3ef9 100644--- a/crates/openhuman-session/src/manager.rs+++ b/crates/openhuman-session/src/manager.rs@@ -207,7 +207,7 @@ impl<L: CoreLink> SessionManager<L> {token: &str,user: Option<Value>,) -> Result<SessionState, SessionError> {- let _guard = self.mutation.lock().await;+ let guard = self.mutation.lock().await;self.cancel_revalidation();let credential = Credential::classify(token);if credential.secret.is_empty() {@@ -223,6 +223,7 @@ impl<L: CoreLink> SessionManager<L> {}self.push(&credential, None, user.as_ref()).await?;self.cache.forget();+ drop(guard);return self.changed().await;}@@ -246,6 +247,7 @@ impl<L: CoreLink> SessionManager<L> {self.push(&credential, user_id.as_deref(), Some(&me)).await?;self.cache.seed(&client, &credential, me);+ drop(guard);self.changed().await}Err(FetchMeError::Rejected(reason)) => {@@ -273,6 +275,7 @@ impl<L: CoreLink> SessionManager<L> {.await?;self.cache.forget();self.spawn_revalidation(credential);+ drop(guard);self.changed().await}}@@ -280,12 +283,13 @@ impl<L: CoreLink> SessionManager<L> {/// Store a TinyHumans API key. No user identity, no backend round trip.pub async fn store_api_key(self: &Arc<Self>, key: &str) -> Result<SessionState, SessionError> {- let _guard = self.mutation.lock().await;+ let guard = self.mutation.lock().await;let credential = Credential::api_key(key);if credential.secret.is_empty() {return Err(SessionError::Invalid("api key is required".to_string()));}self.push(&credential, None, None).await?;+ drop(guard);self.changed().await}@@ -360,11 +364,12 @@ impl<L: CoreLink> SessionManager<L> {*self.revalidation.lock().unwrap_or_else(|p| p.into_inner()) = Some(handle);}- async fn clear_session_credential(&self, source: &str) {+ async fn clear_session_credential(&self, source: &str) -> bool {if let Err(e) =link::clear_credential(self.link.as_ref(), Some(CredentialKind::Session)).await{log::warn!("{LOG_PREFIX} failed to clear rejected session credential: {e}");+ return false;}self.cache.forget();identity::clear();@@ -374,6 +379,7 @@ impl<L: CoreLink> SessionManager<L> {// The credential is gone, so the signed-out state is known without// asking the core again (and `state()` would recurse into here).self.emit(SessionEvent::Changed(SessionState::default()));+ true}/// Whether the core still holds `secret` as its session token.