Skip to content

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

feat(memory): add memory_erase_all rpc method

Steven Enamakel84f4a07b202e
diff --git a/app/src/services/rpcMethods.ts b/app/src/services/rpcMethods.ts
index b501a40ab7..f94d769a37 100644
--- a/app/src/services/rpcMethods.ts
+++ b/app/src/services/rpcMethods.ts
@@ -42,6 +42,7 @@ export const CORE_RPC_METHODS = {
memoryFetch: 'openhuman.memory_fetch',
memoryLearn: 'openhuman.memory_learn',
memoryForget: 'openhuman.memory_forget',
+ memoryEraseAll: 'openhuman.memory_erase_all',
memoryItemsList: 'openhuman.memory_items_list',
memoryExplore: 'openhuman.memory_explore',
memoryItemsGet: 'openhuman.memory_items_get',
diff --git a/crates/openhuman-core/src/memory/ops_tests.rs b/crates/openhuman-core/src/memory/ops_tests.rs
index 201f3ae53d..b469bb18a4 100644
--- a/crates/openhuman-core/src/memory/ops_tests.rs
+++ b/crates/openhuman-core/src/memory/ops_tests.rs
@@ -351,3 +351,42 @@ async fn fetch_refuses_a_mode_the_engine_does_not_declare() {
.unwrap_err();
assert_eq!(error.code(), UNSUPPORTED);
}
+
+#[tokio::test]
+async fn erase_all_needs_its_confirmation() {
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ let engine = bind_reference(&config);
+ learn(&config, learn_params("a fact"), None).await.unwrap();
+ let error = erase_all(&config, EraseAllParams { confirm: false })
+ .await
+ .unwrap_err();
+ assert_eq!(error.code(), INVALID_REQUEST);
+ assert_eq!(stored(&engine, MetaFilter::default()).await.len(), 1);
+}
+
+#[tokio::test]
+async fn erase_all_erases_everything_the_engine_holds() {
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ let engine = bind_reference(&config);
+ learn(&config, learn_params("a fact"), None).await.unwrap();
+ learn(&config, learn_params("another fact"), None)
+ .await
+ .unwrap();
+ let view = erase_all(&config, EraseAllParams { confirm: true })
+ .await
+ .unwrap();
+ assert!(view.erased_scopes >= 1, "{view:?}");
+ assert!(stored(&engine, MetaFilter::default()).await.is_empty());
+}
+
+#[tokio::test]
+async fn erase_all_reports_memory_off_without_an_engine() {
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ let error = erase_all(&config, EraseAllParams { confirm: true })
+ .await
+ .unwrap_err();
+ assert_eq!(error.code(), MEMORY_OFF);
+}
diff --git a/crates/openhuman-core/src/memory/schemas_tests.rs b/crates/openhuman-core/src/memory/schemas_tests.rs
index fd87e8fa57..da3a3bd4cf 100644
--- a/crates/openhuman-core/src/memory/schemas_tests.rs
+++ b/crates/openhuman-core/src/memory/schemas_tests.rs
@@ -6,7 +6,7 @@ use crate::memory::test_fixtures::{bind_reference, config_in};
use serde_json::{json, Map, Value};
/// Every method of the spec's RPC table (`docs/specs/memory-v2.md`), exactly.
-const SPEC_METHODS: [&str; 34] = [
+const SPEC_METHODS: [&str; 35] = [
"openhuman.memory_engines_list",
"openhuman.memory_engine_get",
"openhuman.memory_engine_set",
@@ -17,6 +17,7 @@ const SPEC_METHODS: [&str; 34] = [
"openhuman.memory_fetch",
"openhuman.memory_learn",
"openhuman.memory_forget",
+ "openhuman.memory_erase_all",
"openhuman.memory_items_list",
"openhuman.memory_explore",
"openhuman.memory_items_get",
@@ -144,6 +145,8 @@ async fn invalid_params_are_rejected_as_invalid_request() {
("fetch", json!({"mode": "keyword"})),
("learn", json!({"confidence": 0.5})),
("forget", json!({"ids": "not-a-list"})),
+ ("erase_all", json!({"confirm": "yes"})),
+ ("erase_all", json!({"confirm": false})),
("sources_add", json!({"kind": "folder"})),
("sources_remove", json!({})),
("policy_set", json!({"budget_tokens": "many"})),
@@ -168,6 +171,7 @@ async fn memory_off_surfaces_the_memory_off_code() {
("fetch", json!({"query": "q"})),
("learn", json!({"text": "t"})),
("forget", json!({"ids": ["a"]})),
+ ("erase_all", json!({"confirm": true})),
("items_list", json!({})),
("explore", json!({"facet": "kind"})),
("items_get", json!({"ids": ["a"]})),
@@ -233,6 +237,20 @@ async fn read_handlers_answer_over_a_bound_engine() {
let forgotten = call(&config, "forget", json!({"ids": [id]})).await.unwrap();
let forgotten = forgotten.get("result").unwrap_or(&forgotten);
assert_eq!(forgotten["forgotten"], 1);
+
+ call(&config, "learn", json!({"text": "Drinks tea"}))
+ .await
+ .unwrap();
+ let erased = call(&config, "erase_all", json!({"confirm": true}))
+ .await
+ .unwrap();
+ let erased = erased.get("result").unwrap_or(&erased);
+ assert_eq!(erased["erased_scopes"], 1);
+ let listed = call(&config, "items_list", json!({"limit": 5}))
+ .await
+ .unwrap();
+ let listed = listed.get("result").unwrap_or(&listed);
+ assert!(listed["items"].as_array().unwrap().is_empty());
}
#[tokio::test]
diff --git a/docs/specs/memory-v2.md b/docs/specs/memory-v2.md
index 0ebc9bd5a3..b47f48e389 100644
--- a/docs/specs/memory-v2.md
+++ b/docs/specs/memory-v2.md
@@ -230,6 +230,7 @@ memory.
| `memory_fetch` | `{query, mode?, filter?, limit?, cursor?}` | `{hits: Hit[], next_cursor?}` |
| `memory_learn` | `{text, kind?, confidence?, meta?}` | `{id}` |
| `memory_forget` | `{ids, reach?}` | `{forgotten}` |
+| `memory_erase_all` | `{confirm: true}` | `{erased_scopes}`; erases everything the bound engine holds, for good. Hosted: one `DELETE /memory`, the account's entire hosted memory. Direct: every kind scope of the bound layout; a shared legacy tree is left alone |
| `memory_items_list` | `{filter?, limit?, cursor?, path?}` | `{items: Hit[], next_cursor?}` |
| `memory_explore` | `{facet, path?, filter?, limit?, scan_limit?}` | `{facet, buckets: {value, count}[], total, missing, more_buckets, truncated}` |
| `memory_items_get` | `{ids, reach?}` | `{items: Hit[]}` |