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(session): guard credential clear against token race
Steven Enamakel2544b03c4b2b
diff --git a/app/src/services/session/sessionOwner.ts b/app/src/services/session/sessionOwner.tsindex be80eacf53..3e8094d7b5 100644--- a/app/src/services/session/sessionOwner.ts+++ b/app/src/services/session/sessionOwner.ts@@ -216,10 +216,20 @@ const browserCurrentUser = async (force: boolean): Promise<SessionCurrentUser> =const message = error instanceof Error ? error.message : String(error);if (message.startsWith('REJECTED:')) {browserCurrentUserCache = null;- await callCoreRpc({- method: 'openhuman.auth_clear_credential',- params: { kind: 'session' },- }).catch(() => undefined);+ // A login may have published a newer token while this request was in+ // flight. Never clear that newer browser-owned session on an old+ // request's rejection.+ const latest = await callCoreRpc<{ result: { token: string | null } }>({+ method: 'openhuman.auth_get_session_token',+ }).catch(() => null);+ if (latest?.result.token === token) {+ await callCoreRpc({+ method: 'openhuman.auth_clear_credential',+ params: { kind: 'session' },+ }).catch(() => undefined);+ } else {+ return { user: core.user, stale: true, staleSeconds: null };+ }// Same confirmed-expiry signal the shell owner raises through// `auth://expired`: the credential is gone, so the core-state layer// must sign out now rather than keep a stale signed-in snapshot untildiff --git a/crates/openhuman-session/src/cache.rs b/crates/openhuman-session/src/cache.rsindex 9f68236e1e..570c1bf065 100644--- a/crates/openhuman-session/src/cache.rs+++ b/crates/openhuman-session/src/cache.rs@@ -205,9 +205,6 @@ impl CurrentUserCache {}fn record_failure(&self, generation: u64, key: &Key, error: FetchMeError) {- if !error.is_availability_failure() {- return;- }let mut state = self.lock();if state.generation != generation {log::debug!("{LOG_PREFIX} discarding failure that raced sign-out");@@ -252,6 +249,18 @@ impl CurrentUserCache {let generation = self.lock().generation;if !force {+ // A background rejection is authoritative. Surface it before a+ // stale positive entry so the owning manager can clear the token.+ if let Some((error, consecutive, retry_in)) = self.suppressed(&key) {+ if matches!(error, FetchMeError::Rejected(_)) {+ return Err(error);+ }+ return Err(FetchMeError::Suppressed {+ message: error.message().to_string(),+ consecutive,+ retry_in,+ });+ }if let Some((user, age)) = self.cached(&key) {if age < REFRESH_TTL {return Ok(self.with_result(&key, Some(user)));@@ -263,13 +272,6 @@ impl CurrentUserCache {);return Ok(self.with_result(&key, Some(user)));}- if let Some((error, consecutive, retry_in)) = self.suppressed(&key) {- return Err(FetchMeError::Suppressed {- message: error.message().to_string(),- consecutive,- retry_in,- });- }}let timeout = fetch_timeout();