Skip to content

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

chore: files changed src/openhuman/desktop/app_state/ops_current_user_generation.rs,src/openhuman/de

Steven Enamakela1cd63d8dc15
diff --git a/src/openhuman/desktop/app_state/ops_current_user_generation.rs b/src/openhuman/desktop/app_state/ops_current_user_generation.rs
index 831e4f1478..f497d36688 100644
--- a/src/openhuman/desktop/app_state/ops_current_user_generation.rs
+++ b/src/openhuman/desktop/app_state/ops_current_user_generation.rs
@@ -17,6 +17,13 @@
/// cancelling each other out.
static CURRENT_USER_GENERATION: AtomicU64 = AtomicU64::new(0);
+/// Serializes session-profile mutation with pending-session persistence. The
+/// generation check must cover the profile write itself, not only the work
+/// that prepares its input, or logout can bump the generation between the
+/// check and `store_provider_token`.
+pub static CURRENT_USER_SESSION_MUTATION_LOCK: Lazy<tokio::sync::Mutex<()>> =
+ Lazy::new(|| tokio::sync::Mutex::new(()));
+
/// The failure write itself, taking the guard rather than the lock, so a caller
/// that must decide *under* the lock can do so without re-entering it.
fn record_current_user_failure_locked(
diff --git a/src/openhuman/desktop/app_state/ops_part_03.rs b/src/openhuman/desktop/app_state/ops_part_03.rs
index a9fd6d121e..2488e37597 100644
--- a/src/openhuman/desktop/app_state/ops_part_03.rs
+++ b/src/openhuman/desktop/app_state/ops_part_03.rs
@@ -92,6 +92,7 @@ pub async fn snapshot() -> Result<RpcOutcome<AppStateSnapshot>, String> {
&token,
session_metadata.clone(),
fresh_user.clone(),
+ generation,
)
.await
{
diff --git a/src/openhuman/security/credentials/ops_part_02.rs b/src/openhuman/security/credentials/ops_part_02.rs
index 7e4cb01f2a..d42f265743 100644
--- a/src/openhuman/security/credentials/ops_part_02.rs
+++ b/src/openhuman/security/credentials/ops_part_02.rs
@@ -82,6 +82,10 @@ fn normalize_local_session_user(user: serde_json::Value, local_user_id: &str) ->
}
pub async fn clear_session(config: &Config) -> Result<RpcOutcome<serde_json::Value>, String> {
+ let _session_mutation_lock = crate::openhuman::desktop::app_state::
+ CURRENT_USER_SESSION_MUTATION_LOCK
+ .lock()
+ .await;
let mut logs = Vec::new();
// Flip the scheduler-gate override first so any background worker that
// is mid-iteration (or wakes up while we tear down) stalls at its next
@@ -89,6 +93,10 @@ pub async fn clear_session(config: &Config) -> Result<RpcOutcome<serde_json::Val
// we're about to invalidate. Idempotent.
crate::openhuman::cron::scheduler_gate::set_signed_out(true);
+ // Invalidate before removing the profile so a pending revalidation cannot
+ // recreate it after logout has finished the removal.
+ crate::openhuman::desktop::app_state::forget_current_user_caches();
+
let auth = AuthService::from_config(config);
let removed = auth
.remove_profile(APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFILE_NAME)
@@ -104,11 +112,6 @@ pub async fn clear_session(config: &Config) -> Result<RpcOutcome<serde_json::Val
}
crate::openhuman::platform::socket::medulla::workflows::clear_workflow_bridge();
- // Forget the cached `/auth/me` snapshot and the cached availability failure.
- // Both are keyed on `(api_base, token)`, so signing back in with the same JWT
- // inside their windows would replay pre-logout state (#5758).
- crate::openhuman::desktop::app_state::forget_current_user_caches();
-
// Clear the active user marker so subsequent config loads fall back to the
// default (unauthenticated) openhuman directory.
if let Ok(root_dir) = default_root_openhuman_dir() {