Skip to content

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

refactor(core): drop current-user cache from app_state

Steven Enamakelcea3dd041d71
diff --git a/crates/openhuman-core/src/desktop/app_state/ops.rs b/crates/openhuman-core/src/desktop/app_state/ops.rs
index fa72540fe6..02c0b4c610 100644
--- a/crates/openhuman-core/src/desktop/app_state/ops.rs
+++ b/crates/openhuman-core/src/desktop/app_state/ops.rs
@@ -1,75 +1,39 @@
-//! Core-owned `app_state` business logic: the polled snapshot RPC, local
-//! on-disk state, and the current-user cache that backs both.
+//! Core-owned `app_state` business logic: the polled snapshot RPC and local
+//! on-disk state.
//!
//! Split by responsibility:
//! - [`types`] — the serde types exchanged with the frontend.
//! - [`state_file`] — atomic on-disk persistence of `StoredAppState`.
-//! - [`auth_timeout`] — the `auth_get_me` fetch timeout and its derived backoff base.
-//! - [`current_user_fetch`] — the plain `GET /auth/me` HTTP call.
-//! - [`current_user`] — the positive/negative current-user caches and their
-//! blocking/background refresh paths.
-//! - [`current_user_generation`] — sign-out invalidation of those caches.
-//! - [`staleness`] — how old the data a snapshot is serving has become.
-//! - [`pending_session`] — activating or rejecting a not-yet-confirmed session.
//! - [`runtime_snapshot`] — the local-AI + service half of the snapshot.
//! - [`snapshot`] — the `app_state_snapshot` / `update_local_state` RPC handlers.
+//!
+//! The current user is no longer refreshed here: the host that owns the
+//! session (the desktop shell's `openhuman-session`) caches `/auth/me`, and
+//! the snapshot reports the payload the host handed the core at login.
-mod auth_timeout;
-mod current_user;
-mod current_user_fetch;
-mod current_user_generation;
-mod pending_session;
mod runtime_snapshot;
mod snapshot;
-mod staleness;
mod state_file;
mod types;
-#[cfg(test)]
-#[path = "ops_current_user_backoff_tests.rs"]
-mod current_user_backoff_tests;
-#[cfg(test)]
-#[path = "ops_snapshot_latency_tests.rs"]
-mod snapshot_latency_tests;
#[cfg(test)]
#[path = "ops_tests.rs"]
mod tests;
-// Test-only flat re-import of every submodule's internals, so the test
-// files below — written against this module's pre-split flat scope — keep
-// working unmodified via `use super::*;`. Each submodule marks the items
-// these tests reach into as `pub(super)` (visible to `ops` and, therefore,
-// to these test descendants) for exactly this purpose.
-//
-// External types the tests reach through `super::*` (rather than importing
-// themselves) also need to be back in this flat scope, since a plain `use`
-// inside a submodule is private to it and is not picked up by a glob import
-// of that submodule.
+// Test-only flat re-import of every submodule's internals, so the test file
+// above — written against this module's pre-split flat scope — keeps working
+// via `use super::*;`.
#[cfg(test)]
use crate::config::Config;
#[cfg(test)]
-use crate::security::credentials::{AuthService, APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFILE_NAME};
-#[cfg(test)]
use serde_json::Value;
#[cfg(test)]
-use std::collections::{BTreeMap, HashMap};
-#[cfg(test)]
use std::time::{Duration, Instant};
-#[cfg(test)]
-use auth_timeout::*;
-#[cfg(test)]
-use current_user::*;
-#[cfg(test)]
-use current_user_fetch::*;
-#[cfg(test)]
-use current_user_generation::*;
-#[cfg(test)]
-use pending_session::*;
#[cfg(test)]
use runtime_snapshot::*;
#[cfg(test)]
-use staleness::*;
+use snapshot::sanitize_snapshot_user;
#[cfg(test)]
use state_file::*;
@@ -77,12 +41,6 @@ use state_file::*;
/// these submodules.
pub(super) const LOG_PREFIX: &str = "[app_state]";
-pub use auth_timeout::{
- parse_auth_fetch_timeout_secs, AUTH_FETCH_TIMEOUT_ENV_VAR, DEFAULT_AUTH_FETCH_TIMEOUT_SECS,
- MAX_AUTH_FETCH_TIMEOUT_SECS, MIN_AUTH_FETCH_TIMEOUT_SECS,
-};
-pub use current_user::peek_cached_current_user_identity;
-pub use current_user_generation::{forget_current_user_caches, CURRENT_USER_SESSION_MUTATION_LOCK};
pub use snapshot::{snapshot, update_local_state};
pub(crate) use state_file::load_stored_app_state;
pub use state_file::save_app_state;
diff --git a/crates/openhuman-core/src/desktop/app_state/ops/snapshot.rs b/crates/openhuman-core/src/desktop/app_state/ops/snapshot.rs
index 12fc23d640..f55d847403 100644
--- a/crates/openhuman-core/src/desktop/app_state/ops/snapshot.rs
+++ b/crates/openhuman-core/src/desktop/app_state/ops/snapshot.rs
@@ -30,7 +30,7 @@ use std::time::Instant;
/// Correlates a snapshot call's own timing/debug log lines across the poll.
pub(super) static SNAPSHOT_REQ_COUNTER: AtomicU64 = AtomicU64::new(0);
-fn sanitize_snapshot_user(user: Option<Value>) -> Option<Value> {
+pub(super) fn sanitize_snapshot_user(user: Option<Value>) -> Option<Value> {
match user {
Some(Value::Object(map)) if map.is_empty() => None,
Some(Value::Null) => None,
diff --git a/crates/openhuman-core/src/desktop/app_state/ops_tests.rs b/crates/openhuman-core/src/desktop/app_state/ops_tests.rs
index 067533c436..8564a0e4f9 100644
--- a/crates/openhuman-core/src/desktop/app_state/ops_tests.rs
+++ b/crates/openhuman-core/src/desktop/app_state/ops_tests.rs
@@ -1,17 +1,12 @@
use super::*;
use once_cell::sync::Lazy as TestLazy;
-use parking_lot::Mutex as TestMutex;
use serde_json::json;
use tempfile::tempdir;
-/// Serialises every test that reads or writes the process-global snapshot
-/// caches. A `tokio` mutex rather than a `parking_lot` one so async tests can
-/// hold it across an `.await` — sibling `ops_current_user_backoff_tests.rs`
-/// guards its own global the same way.
-///
-/// `pub(super)` for `ops_snapshot_latency_tests.rs`, which seeds the positive
-/// cache and so has to serialise against the readers here.
-pub(super) static APP_STATE_CACHE_TEST_LOCK: TestLazy<tokio::sync::Mutex<()>> =
+/// Serialises every test that reads or writes the process-global runtime
+/// snapshot cache. A `tokio` mutex rather than a `parking_lot` one so async
+/// tests can hold it across an `.await`.
+static APP_STATE_CACHE_TEST_LOCK: TestLazy<tokio::sync::Mutex<()>> =
TestLazy::new(|| tokio::sync::Mutex::new(()));
#[test]
@@ -24,12 +19,6 @@ fn sanitize_snapshot_user_drops_empty_payloads() {
);
}
-
-// The freshness branch in `fetch_current_user_cached` is `elapsed() < TTL`.
-// Lock that contract here so a future TTL change can't silently flip the
-// cache from "hit" to "miss" without updating this test.
-
-
#[test]
fn app_state_path_creates_state_dir_and_points_at_app_state_json() {
let tmp = tempdir().unwrap();
@@ -260,53 +249,3 @@ fn degraded_runtime_snapshot_has_expected_degraded_fields() {
fn build_dummy_runtime_snapshot() -> RuntimeSnapshot {
degraded_runtime_snapshot(&Config::default())
}
-
-
-#[path = "ops_signout_cache_tests.rs"]
-mod signout_cache_tests;
-
-// Serialises the `OPENHUMAN_WORKSPACE` env mutations below so two of these tests
-// can't race each other on the process-global var.
-static WORKSPACE_ENV_TEST_LOCK: TestLazy<TestMutex<()>> = TestLazy::new(|| TestMutex::new(()));
-
-/// RAII guard for `OPENHUMAN_WORKSPACE`. Captures the prior value on
-/// construction and restores it (set or remove) on drop, so a test that panics
-/// between the mutation and the end of the test can't leak the override into a
-/// sibling test. Must be constructed while holding `WORKSPACE_ENV_TEST_LOCK`:
-/// mutating a process env var while another thread reads it is unsafe, and the
-/// lock serialises every test in this group.
-struct WorkspaceEnvGuard {
- prior: Option<std::ffi::OsString>,
-}
-
-impl WorkspaceEnvGuard {
- fn set(value: &std::path::Path) -> Self {
- let prior = std::env::var_os("OPENHUMAN_WORKSPACE");
- std::env::set_var("OPENHUMAN_WORKSPACE", value);
- Self { prior }
- }
-
- fn set_empty() -> Self {
- let prior = std::env::var_os("OPENHUMAN_WORKSPACE");
- std::env::set_var("OPENHUMAN_WORKSPACE", "");
- Self { prior }
- }
-
- fn unset() -> Self {
- let prior = std::env::var_os("OPENHUMAN_WORKSPACE");
- std::env::remove_var("OPENHUMAN_WORKSPACE");
- Self { prior }
- }
-}
-
-impl Drop for WorkspaceEnvGuard {
- fn drop(&mut self) {
- match &self.prior {
- Some(value) => std::env::set_var("OPENHUMAN_WORKSPACE", value),
- None => std::env::remove_var("OPENHUMAN_WORKSPACE"),
- }
- }
-}
-
-
-