Skip to content

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

Pass a bulk store's wait through the memory guard

M3gA-Mind3a380eba8106
diff --git a/crates/openhuman-core/src/memory/guard.rs b/crates/openhuman-core/src/memory/guard.rs
index dd4a4c88f9..881084bf41 100644
--- a/crates/openhuman-core/src/memory/guard.rs
+++ b/crates/openhuman-core/src/memory/guard.rs
@@ -145,6 +145,20 @@ impl MemoryEngine for ScrubbingEngine {
.await
}
+ async fn store_many_with(
+ &self,
+ items: Vec<StoreItem>,
+ options: WriteOptions,
+ ) -> Result<Vec<StoreReceipt>> {
+ let op = match options.wait {
+ WaitFor::Accepted => "store_many_accepted",
+ WaitFor::Visible => "store_many",
+ };
+ let items = items.into_iter().map(scrub).collect();
+ self.timed(op, self.inner.store_many_with(items, options), Vec::len)
+ .await
+ }
+
async fn forget(&self, target: ForgetTarget) -> Result<ForgetReport> {
self.timed("forget", self.inner.forget(target), |report| {
report.forgotten
diff --git a/crates/openhuman-core/src/memory/guard_tests.rs b/crates/openhuman-core/src/memory/guard_tests.rs
index f32943cfa1..aac35a3ac2 100644
--- a/crates/openhuman-core/src/memory/guard_tests.rs
+++ b/crates/openhuman-core/src/memory/guard_tests.rs
@@ -36,9 +36,13 @@ async fn every_write_path_is_scrubbed() {
.store_many(vec![item("three"), item("four")])
.await
.unwrap();
+ guarded
+ .store_many_with(vec![item("five"), item("six")], WriteOptions::accepted())
+ .await
+ .unwrap();
let stored = texts(&reference).await;
- assert_eq!(stored.len(), 4);
+ assert_eq!(stored.len(), 6);
assert!(
stored.iter().all(|text| !text.contains(SECRET)),
"a secret reached the engine: {stored:?}"
@@ -160,3 +164,67 @@ async fn export_and_erase_reach_the_wrapped_engine() {
assert_eq!(report.erased_scopes, 1);
assert!(texts(&reference).await.is_empty());
}
+
+/// Records the wait each bulk store asks for, storing through a reference
+/// engine.
+#[derive(Default)]
+struct Recording {
+ inner: ReferenceEngine,
+ waits: std::sync::Mutex<Vec<WaitFor>>,
+}
+
+#[async_trait::async_trait]
+impl MemoryEngine for Recording {
+ fn descriptor(&self) -> &tinymemory_api::EngineDescriptor {
+ self.inner.descriptor()
+ }
+ async fn health(&self) -> tinymemory_api::EngineHealth {
+ self.inner.health().await
+ }
+ async fn recall(&self, req: RecallRequest) -> Result<tinymemory_api::RecallAnswer> {
+ self.inner.recall(req).await
+ }
+ async fn fetch(&self, req: FetchRequest) -> Result<tinymemory_api::FetchPage> {
+ self.inner.fetch(req).await
+ }
+ async fn store(&self, item: StoreItem) -> Result<StoreReceipt> {
+ self.inner.store(item).await
+ }
+ async fn store_many_with(
+ &self,
+ items: Vec<StoreItem>,
+ options: WriteOptions,
+ ) -> Result<Vec<StoreReceipt>> {
+ self.waits.lock().unwrap().push(options.wait);
+ self.inner.store_many(items).await
+ }
+ async fn forget(
+ &self,
+ target: tinymemory_api::ForgetTarget,
+ ) -> Result<tinymemory_api::ForgetReport> {
+ self.inner.forget(target).await
+ }
+ async fn list(&self, req: ListRequest) -> Result<tinymemory_api::ListPage> {
+ self.inner.list(req).await
+ }
+}
+
+#[tokio::test]
+async fn a_bulk_store_keeps_its_wait_through_the_guard() {
+ let recording = Arc::new(Recording::default());
+ let guarded = ScrubbingEngine::wrap(recording.clone());
+ let items = || vec![StoreItem::document("tea", MemoryMeta::default())];
+ guarded
+ .store_many_with(items(), WriteOptions::accepted())
+ .await
+ .unwrap();
+ guarded
+ .store_many_with(items(), WriteOptions::visible())
+ .await
+ .unwrap();
+ assert_eq!(
+ *recording.waits.lock().unwrap(),
+ vec![WaitFor::Accepted, WaitFor::Visible],
+ "the guard passes the wait on instead of serving it as store_many"
+ );
+}