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/agent/experience/ops.rs,src/openhuman/memory/binding.rs

Steven Enamakel8ecb27f4bc0e
diff --git a/src/openhuman/agent/experience/ops.rs b/src/openhuman/agent/experience/ops.rs
index 98f00e494e..5b6349dabb 100644
--- a/src/openhuman/agent/experience/ops.rs
+++ b/src/openhuman/agent/experience/ops.rs
@@ -82,8 +82,7 @@ impl DriverMemory {
"[agent-experience] bound shared memory subtree driver='{}'",
binding.driver_id()
);
- let memory: Arc<dyn Memory> = Arc::new(Self::new(binding.provider().clone()));
- Ok(memory)
+ Ok(binding.shared_memory_view(|provider| Arc::new(Self::new(Arc::clone(provider)))))
}
/// The driver bound for one memory subtree of `config`'s workspace.
@@ -105,8 +104,7 @@ impl DriverMemory {
"[agent-experience] bound memory subtree '{memory_subdir}' driver='{}'",
binding.driver_id()
);
- let memory: Arc<dyn Memory> = Arc::new(Self::new(binding.provider().clone()));
- Ok(memory)
+ Ok(binding.shared_memory_view(|provider| Arc::new(Self::new(Arc::clone(provider)))))
}
}
diff --git a/src/openhuman/memory/binding.rs b/src/openhuman/memory/binding.rs
index 49c329ec30..ebf1ab1cbb 100644
--- a/src/openhuman/memory/binding.rs
+++ b/src/openhuman/memory/binding.rs
@@ -85,6 +85,18 @@ pub struct MemoryBinding {
/// surface drift underneath an already-filtered RPC/tool registration.
capabilities: Capabilities,
fallback: Option<FallbackReason>,
+ /// The `Arc<dyn Memory>` view over [`Self::provider`], built at most once
+ /// per binding.
+ ///
+ /// Every session built against this subtree wants the same trait-object
+ /// view of the same driver, and the view is stateless — it forwards each
+ /// call to `provider`. Building one per session made each live agent hold
+ /// its own allocation for a value indistinguishable from its neighbours'.
+ /// Memoising it *here* rather than in a second cache is what keeps the
+ /// lifetime right: the view dies with the binding, so the exit path's
+ /// rebind (`forget_shut_down`) cannot leave a session holding a view over
+ /// a driver that has already been torn down.
+ memory_view: std::sync::OnceLock<Arc<dyn crate::openhuman::memory::Memory>>,
}
impl MemoryBinding {
@@ -97,6 +109,17 @@ impl MemoryBinding {
&self.provider
}
+ /// The shared `Arc<dyn Memory>` view over this binding's driver.
+ ///
+ /// `make` runs at most once per binding; every later caller gets the same
+ /// handle. See [`Self::memory_view`] for why the memo lives on the binding.
+ pub fn shared_memory_view(
+ &self,
+ make: impl FnOnce(&Arc<dyn MemoryProvider>) -> Arc<dyn crate::openhuman::memory::Memory>,
+ ) -> Arc<dyn crate::openhuman::memory::Memory> {
+ Arc::clone(self.memory_view.get_or_init(|| make(&self.provider)))
+ }
+
pub fn guard(&self) -> Arc<MemoryGuard> {
Arc::clone(&self.guard)
}
@@ -455,6 +478,7 @@ fn bind_provider(
class,
capabilities,
fallback,
+ memory_view: std::sync::OnceLock::new(),
}
}