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
feat(storage): drop cached session stores when a profile lease is released
Steven Enamakelfbc9e08229ed
diff --git a/crates/openhuman-core/src/profiles/lease.rs b/crates/openhuman-core/src/profiles/lease.rsindex 5e77c93c91..48b4a2ed39 100644--- a/crates/openhuman-core/src/profiles/lease.rs+++ b/crates/openhuman-core/src/profiles/lease.rs@@ -127,9 +127,19 @@ pub(crate) async fn release_all(host: &ProfileHost, grants: Vec<(ProfileId, LeasOk(()) => log::debug!("[profiles][lease] released profile={id}"),Err(error) => log::debug!("[profiles][lease] release of profile={id}: {error}"),}+ release_profile_stores(host, &id);}}+/// Discard cached stores whose storage handles captured this profile's old+/// fence. In-flight owners retain their handles and remain fenced; any later+/// open constructs stores against the profile's new lease epoch.+pub(crate) fn release_profile_stores(host: &ProfileHost, id: &ProfileId) {+ crate::storage::sessions::release_profile(id.as_str());+ let workspace = host.layout_of(id).workspace_dir;+ crate::storage::sessions::release_workspace(&workspace);+}+/// What one renewal pass did.#[derive(Debug, Default, Clone, PartialEq, Eq)]pub struct HeartbeatReport {diff --git a/crates/openhuman-core/src/storage/sessions/mod.rs b/crates/openhuman-core/src/storage/sessions/mod.rsindex 8fdef7bb4c..22f4a93d5a 100644--- a/crates/openhuman-core/src/storage/sessions/mod.rs+++ b/crates/openhuman-core/src/storage/sessions/mod.rs@@ -31,6 +31,12 @@ pub use workspace::{turn_states_for, with_ledger, with_ledger_async, WorkspaceSessionStores,};+/// Drops cached stores for a profile after its lease is released. Existing+/// handles retain their original fence; a later profile open gets fresh ones.+pub fn release_profile(profile: &str) {+ rebound::release_profile(profile);+}+static PROVIDER: LazyLock<RwLock<Option<Arc<dyn SessionStoreProvider>>>> =LazyLock::new(|| RwLock::new(None));diff --git a/crates/openhuman-core/src/storage/sessions/rebound.rs b/crates/openhuman-core/src/storage/sessions/rebound.rsindex 1b0646cfa8..532d773ad3 100644--- a/crates/openhuman-core/src/storage/sessions/rebound.rs+++ b/crates/openhuman-core/src/storage/sessions/rebound.rs@@ -59,6 +59,12 @@ impl StoreRegistry {);live.len()}++ fn release_profile(&self, profile: &str) {+ for stores in self.live() {+ stores.release_profile(profile);+ }+ }}/// The process's registry, the one [`ReboundSessionStores::new`] joins.@@ -130,6 +136,12 @@ impl ReboundSessionStores {"[session_store] rebound to a new storage backend");}++ /// Drops cached session handles for a profile whose lease was released.+ /// Handles already handed out remain tied to their original fence.+ pub fn release_profile(&self, profile: &str) {+ self.current().release_profile(profile);+ }}/// Rebinds every live [`ReboundSessionStores`] of the process to `backend`;@@ -138,6 +150,11 @@ pub fn rebind_all(backend: &Arc<dyn StorageBackend>) -> usize {PROCESS.rebind(backend)}+/// Drops the cached provider for `profile` from every live process store.+pub fn release_profile(profile: &str) {+ PROCESS.release_profile(profile);+}+impl SessionStoreProvider for ReboundSessionStores {fn for_agent(&self, agent_id: &str) -> AgentStores {self.current().for_agent(agent_id)diff --git a/crates/openhuman-core/src/storage/sessions/tenant_router.rs b/crates/openhuman-core/src/storage/sessions/tenant_router.rsindex da26d0b1ca..8699b83e73 100644--- a/crates/openhuman-core/src/storage/sessions/tenant_router.rs+++ b/crates/openhuman-core/src/storage/sessions/tenant_router.rs@@ -131,6 +131,18 @@ impl TenantSessionStores {.cloned().collect()}++ /// Drops the session provider captured for one profile's current lease.+ /// Existing handles keep their old fenced backend, so in-flight work+ /// still fails closed after a takeover; the next open builds fresh handles+ /// against the new lease epoch.+ pub fn release_profile(&self, profile: &str) {+ let tenant = crate::storage::tenant_scope(Some(profile));+ self.tenants+ .lock()+ .unwrap_or_else(PoisonError::into_inner)+ .remove(&tenant);+ }}impl SessionStoreProvider for TenantSessionStores {