Skip to content

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

fix(memory): preserve existing memory content when updating entries

Steven Enamakel72d6a6a80ee5
diff --git a/crates/openhuman-core/src/memory/engine.rs b/crates/openhuman-core/src/memory/engine.rs
index 7e9ab71b7d..2ce4c8c7d6 100644
--- a/crates/openhuman-core/src/memory/engine.rs
+++ b/crates/openhuman-core/src/memory/engine.rs
@@ -223,7 +223,7 @@ pub fn resolve(config: &Config) -> Binding {
if let Some(bound) = host_engine() {
// A host engine is one store for the whole process: in SaaS it would
// put every user in one engine, so it is ignored there.
- if admits_host_engine_with::<BoundEngine>(crate::core::runtime::is_saas()) {
+ if admits_host_engine_with(crate::core::runtime::is_saas()) {
return Binding::On(bound);
}
tracing::warn!("[memory:engine] ignoring the host engine in SaaS mode");
@@ -288,7 +288,7 @@ pub fn bind_with_root(config: &Config, root: Option<&str>) -> MemoryResult<Bound
/// Whether the process-wide host engine may be used: never in SaaS, where one
/// engine would put every user in the same store.
-pub(crate) fn admits_host_engine_with<T>(saas: bool) -> bool {
+pub(crate) fn admits_host_engine_with(saas: bool) -> bool {
!saas
}
@@ -300,7 +300,7 @@ pub(crate) fn host_binding_with<T>(
host: Option<T>,
root: Option<&str>,
) -> MemoryResult<Option<T>> {
- let host = if admits_host_engine_with::<T>(saas) {
+ let host = if admits_host_engine_with(saas) {
host
} else {
None
diff --git a/crates/openhuman-core/src/memory/engine_tests.rs b/crates/openhuman-core/src/memory/engine_tests.rs
index 0298fd0db8..14ca151f0a 100644
--- a/crates/openhuman-core/src/memory/engine_tests.rs
+++ b/crates/openhuman-core/src/memory/engine_tests.rs
@@ -380,3 +380,29 @@ async fn switching_to_v3_persists_and_rebinds_the_persons_own_config() {
"the caller's copy is not the source of truth"
);
}
+
+#[test]
+fn saas_never_admits_the_host_engine() {
+ assert!(!admits_host_engine_with(true));
+ assert!(admits_host_engine_with(false));
+}
+
+#[test]
+fn host_binding_is_ignored_in_saas() {
+ assert_eq!(host_binding_with(true, Some(1), None).unwrap(), None);
+ // The scope-root refusal never fires in SaaS: the host engine is not
+ // in play at all.
+ assert_eq!(host_binding_with(true, Some(1), Some("user:a")).unwrap(), None);
+}
+
+#[test]
+fn host_binding_is_used_without_a_scope_root_outside_saas() {
+ assert_eq!(host_binding_with(false, Some(1), None).unwrap(), Some(1));
+ assert_eq!(host_binding_with::<u8>(false, None, None).unwrap(), None);
+}
+
+#[test]
+fn host_binding_refuses_a_scope_root_outside_saas() {
+ assert!(host_binding_with(false, Some(1), Some("user:a")).is_err());
+ assert_eq!(host_binding_with::<u8>(false, None, Some("user:a")).unwrap(), None);
+}