Skip to content

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

fix(core, desktop): replace event-bus check and guard user-record races

Steven Enamakel29c91b3eac4a
diff --git a/src/core/jsonrpc.rs b/src/core/jsonrpc.rs
index 2df27b67bb..32b55c68b3 100644
--- a/src/core/jsonrpc.rs
+++ b/src/core/jsonrpc.rs
@@ -1965,7 +1965,7 @@ fn group_first_time(group: crate::core::all::DomainGroup) -> bool {
group_first_time_when_bus_ready(
DONE.get_or_init(|| Mutex::new(HashSet::new())),
group,
- crate::core::event_bus::global().is_some(),
+ crate::core::bus::BUS.get().is_some(),
)
}
@@ -1995,7 +1995,7 @@ fn learning_first_time() -> bool {
static DONE: std::sync::OnceLock<std::sync::Mutex<bool>> = std::sync::OnceLock::new();
learning_first_time_when_bus_ready(
DONE.get_or_init(|| std::sync::Mutex::new(false)),
- crate::core::event_bus::global().is_some(),
+ crate::core::bus::BUS.get().is_some(),
)
}
diff --git a/src/openhuman/agent/tinyagents/middleware_part_02.rs b/src/openhuman/agent/tinyagents/middleware_part_02.rs
index f507e275dc..b02eab8048 100644
--- a/src/openhuman/agent/tinyagents/middleware_part_02.rs
+++ b/src/openhuman/agent/tinyagents/middleware_part_02.rs
@@ -760,17 +760,4 @@ impl ToolPolicyMiddleware {
None
}
- fn generated_context(
- &self,
- name: &str,
- args: &serde_json::Value,
- ) -> Option<crate::openhuman::agent::tool_policy::GeneratedToolRuntimeContext> {
- self.tool_sets
- .iter()
- .flat_map(|set| set.iter())
- .find(|t| t.name() == name)
- .and_then(|t| {
- crate::openhuman::tools::traits::generated_runtime_context(t.as_ref(), args)
- })
- }
}
diff --git a/src/openhuman/desktop/app_state/ops_part_02.rs b/src/openhuman/desktop/app_state/ops_part_02.rs
index 784d28a4a7..0b1ef951f9 100644
--- a/src/openhuman/desktop/app_state/ops_part_02.rs
+++ b/src/openhuman/desktop/app_state/ops_part_02.rs
@@ -472,15 +472,11 @@ async fn refresh_current_user_now(
return Ok(fetched);
}
- clear_current_user_failure();
- // Only a *refreshed user* makes the displayed data fresh. The backend can
- // answer 200 with no user at all, and the snapshot caller then falls back
- // to `stored_user` — so stamping success here would report an age of ~0s
- // for data that was never replaced. `clear_current_user_failure` still runs
- // either way: an empty answer is the backend being healthy, just not
- // useful, and it should not keep the backoff window open.
- if fetched.is_some() {
- note_current_user_success(&api_base, token);
+ // Keep all post-fetch records behind the same generation checks as the
+ // positive cache. A logout (or a subsequent login) can land after the
+ // cache commit and must not have its failure/success records overwritten.
+ if !publish_current_user_unless_stale(generation, &api_base, token, fetched.clone()) {
+ return Ok(fetched);
}
Ok(fetched)
diff --git a/src/openhuman/desktop/app_state/ops_part_03.rs b/src/openhuman/desktop/app_state/ops_part_03.rs
index 2488e37597..303cd52281 100644
--- a/src/openhuman/desktop/app_state/ops_part_03.rs
+++ b/src/openhuman/desktop/app_state/ops_part_03.rs
@@ -36,12 +36,14 @@ pub async fn snapshot() -> Result<RpcOutcome<AppStateSnapshot>, String> {
// fetched with the *old* token, passing its own staleness check.
// `load_app_session_profile` busy-waits up to ~35s on a contended lock, so that
// window is not a narrow one.
+ let session_mutation_lock = super::CURRENT_USER_SESSION_MUTATION_LOCK.lock().await;
let generation = current_user_generation();
let config_for_profile = config.clone();
let session_profile =
tokio::task::spawn_blocking(move || load_app_session_profile(&config_for_profile))
.await
.unwrap_or_else(|e| Err(format!("[app_state] auth profile load task panicked: {e}")))?;
+ drop(session_mutation_lock);
let mut auth = session_state_from_profile(session_profile.as_ref());
let mut session_token = session_token_from_profile(session_profile.as_ref());
let stored_user = sanitize_snapshot_user(auth.user.clone());