Skip to content

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

fix(memory): forward export and erase through the scrubbing wrapper

M3gA-Minde409c957571f
diff --git a/crates/openhuman-core/src/memory/guard.rs b/crates/openhuman-core/src/memory/guard.rs
index d6ab7f9d1b..dd4a4c88f9 100644
--- a/crates/openhuman-core/src/memory/guard.rs
+++ b/crates/openhuman-core/src/memory/guard.rs
@@ -19,9 +19,9 @@ use std::time::Instant;
use async_trait::async_trait;
use tinymemory_api::{
BeliefsRequest, ConsolidateReceipt, ConsolidateRequest, EngineDescriptor, EngineHealth,
- ExplorePage, ExploreRequest, FetchPage, FetchRequest, ForgetReport, ForgetTarget, GetRequest,
- Hit, ListPage, ListRequest, MemoryEngine, RecallAnswer, RecallRequest, Result, StoreItem,
- StoreReceipt, WaitFor, WriteOptions,
+ EraseReport, EraseRequest, ExplorePage, ExploreRequest, ExportPage, FetchPage, FetchRequest,
+ ForgetReport, ForgetTarget, GetRequest, Hit, ListPage, ListRequest, MemoryEngine, RecallAnswer,
+ RecallRequest, Result, StoreItem, StoreReceipt, WaitFor, WriteOptions,
};
use super::error::MemoryError;
@@ -157,6 +157,18 @@ impl MemoryEngine for ScrubbingEngine {
.await
}
+ async fn export(&self, req: ListRequest) -> Result<ExportPage> {
+ self.timed("export", self.inner.export(req), |page| page.items.len())
+ .await
+ }
+
+ async fn erase(&self, req: EraseRequest) -> Result<EraseReport> {
+ self.timed("erase", self.inner.erase(req), |report| {
+ report.erased_scopes
+ })
+ .await
+ }
+
async fn explore(&self, req: ExploreRequest) -> Result<ExplorePage> {
self.timed("explore", self.inner.explore(req), |page| {
page.buckets.len()
diff --git a/crates/openhuman-core/src/memory/guard_tests.rs b/crates/openhuman-core/src/memory/guard_tests.rs
index c7c2fb861b..f32943cfa1 100644
--- a/crates/openhuman-core/src/memory/guard_tests.rs
+++ b/crates/openhuman-core/src/memory/guard_tests.rs
@@ -132,3 +132,31 @@ fn scrubbing_keeps_the_page_breaks_a_document_is_chunked_by() {
assert_eq!(text.matches('\u{c}').count(), 2, "{text:?}");
assert!(text.ends_with("\u{c}Page two.\u{c}Page three."), "{text:?}");
}
+
+#[tokio::test]
+async fn export_and_erase_reach_the_wrapped_engine() {
+ let reference = Arc::new(ReferenceEngine::new());
+ let guarded = ScrubbingEngine::wrap(reference.clone());
+ let namespace: tinymemory_api::Namespace = "agent:a".parse().unwrap();
+ guarded
+ .store(StoreItem::document(
+ "kept whole",
+ MemoryMeta {
+ namespace: namespace.clone(),
+ ..MemoryMeta::default()
+ },
+ ))
+ .await
+ .unwrap();
+ let page = guarded
+ .export(ListRequest::new(MetaFilter::default(), 10))
+ .await
+ .expect("export is forwarded, not refused by the wrapper");
+ assert_eq!(page.items.len(), 1);
+ let report = guarded
+ .erase(EraseRequest::new(tinymemory_api::Reach::exact(namespace)))
+ .await
+ .expect("erase is forwarded, not refused by the wrapper");
+ assert_eq!(report.erased_scopes, 1);
+ assert!(texts(&reference).await.is_empty());
+}
diff --git a/crates/openhuman-core/src/memory/test_fixtures.rs b/crates/openhuman-core/src/memory/test_fixtures.rs
index 8d11cde461..56edf9fd04 100644
--- a/crates/openhuman-core/src/memory/test_fixtures.rs
+++ b/crates/openhuman-core/src/memory/test_fixtures.rs
@@ -119,6 +119,13 @@ impl MemoryEngine for RefusingEngine {
Err(self.error.clone())
}
+ async fn export(
+ &self,
+ _req: ListRequest,
+ ) -> tinymemory_api::Result<tinymemory_api::ExportPage> {
+ Err(self.error.clone())
+ }
+
async fn consolidate(
&self,
_req: tinymemory_api::ConsolidateRequest,