Skip to content

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

fix(memory): forget a disconnected app's items within its own source

M3gA-Mind943e91c224e6
diff --git a/crates/openhuman-core/src/integrations/composio/README.md b/crates/openhuman-core/src/integrations/composio/README.md
index f0f2db41bd..3f34667186 100644
--- a/crates/openhuman-core/src/integrations/composio/README.md
+++ b/crates/openhuman-core/src/integrations/composio/README.md
@@ -154,7 +154,7 @@ Published from `ops/` via `crate::core::bus::BUS.publish` (`crate::core::events:
- **Trigger history** (`trigger_history.rs`): JSONL records under `<workspace>/state/triggers/YYYY-MM-DD.jsonl`, partitioned by UTC day, written by `tinyconnectors::triggers::TriggerArchive` (exclusive file lock on append) behind a process-global `OnceLock` handle. Exposed via `composio.list_trigger_history`.
- **Direct-mode API key**: stored in the encrypted keychain (via `credentials`); never logged/returned. `direct_auth/mod.rs` additionally tracks a process-local (non-persisted) consecutive-401 counter for the same key.
- **Connected identities**: `<workspace>/integrations/composio_identities.json` (`identity_store.rs`). **User scope prefs**: `<workspace>/integrations/composio_user_scopes.json` (`ops::user_scopes`). Both written atomically (temp file + rename) under one process-wide lock (`file_store.rs`).
-- **Synced memory**: stored by `memory::sources::composio` with a `connection:<id>` tag; `delete_connection` with `clear_memory` forgets by that tag (`forget_connection`). Memory off forgets nothing.
+- **Synced memory**: stored by `memory::sources::composio` with a `connection:<id>` tag; `delete_connection` with `clear_memory` forgets by that tag (`forget_connection`), reading only the toolkit's brain source (`source:<toolkit>`), or every scope when the toolkit cannot be resolved. Memory off forgets nothing.
- **Integrations cache**: warmed in the background after app startup/sign-in, then kept for the process lifetime. Connection create/delete, config changes, and a divergent `list_connections` response invalidate it; the change paths eagerly re-warm it. Idle time does not trigger a backend fetch on a chat turn (`connected_integrations.rs`).
## Dependencies
diff --git a/crates/openhuman-core/src/integrations/composio/ops/connections.rs b/crates/openhuman-core/src/integrations/composio/ops/connections.rs
index a0f9e415d9..57767148f4 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/connections.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/connections.rs
@@ -178,7 +178,13 @@ pub async fn composio_delete_connection(
})?;
let mut memory_clear_error = None;
if clear_memory {
- match crate::memory::sources::composio::forget_connection(config, connection_id).await {
+ match crate::memory::sources::composio::forget_connection(
+ config,
+ connection_id,
+ toolkit.as_deref(),
+ )
+ .await
+ {
Ok(forgotten) => {
tracing::debug!(
connection_id = %connection_id,
diff --git a/crates/openhuman-core/src/memory/sources/composio.rs b/crates/openhuman-core/src/memory/sources/composio.rs
index 133f653647..1c468b1545 100644
--- a/crates/openhuman-core/src/memory/sources/composio.rs
+++ b/crates/openhuman-core/src/memory/sources/composio.rs
@@ -157,13 +157,46 @@ pub fn source_id_for_toolkit(config: &Config, toolkit: &str) -> String {
/// Forgets every item synced through `connection_id`. Memory off forgets
/// nothing and is not an error.
-pub async fn forget_connection(config: &Config, connection_id: &str) -> MemoryResult<usize> {
+///
+/// With the connection's `toolkit` known, only that toolkit's brain source
+/// is read (`source:<toolkit>`, where its items are filed): one source,
+/// not every scope memory holds. Without it the whole tree is searched, so
+/// a connection whose toolkit cannot be resolved still has its items
+/// forgotten.
+pub async fn forget_connection(
+ config: &Config,
+ connection_id: &str,
+ toolkit: Option<&str>,
+) -> MemoryResult<usize> {
let bound = match crate::memory::engine::resolve(config).engine() {
Ok(bound) => bound,
Err(MemoryError::Off(_)) => return Ok(0),
Err(error) => return Err(error),
};
+ let reach = match toolkit {
+ Some(toolkit) => {
+ let layout = super::layout_of(config, &source_id_for_toolkit(config, toolkit));
+ let source = crate::memory::brain::brain_source(
+ crate::config::schema::MemorySourceKind::Composio,
+ toolkit,
+ );
+ Some(tinymemory_api::Reach::subtree(layout.brain(&source)?))
+ }
+ None => {
+ tracing::warn!(
+ connection_id = %connection_id,
+ "[memory:sources] toolkit unknown; forgetting the connection across all memory"
+ );
+ None
+ }
+ };
+ tracing::debug!(
+ connection_id = %connection_id,
+ scoped = reach.is_some(),
+ "[memory:sources] forgetting a connection's items"
+ );
let filter = tinymemory_api::MetaFilter {
+ reach,
sources: vec![SourceKind::Composio],
tags_any: vec![connection_tag(connection_id)],
..tinymemory_api::MetaFilter::default()
diff --git a/crates/openhuman-core/src/memory/sources/composio_tests.rs b/crates/openhuman-core/src/memory/sources/composio_tests.rs
index 37f0af3139..f077bed6d0 100644
--- a/crates/openhuman-core/src/memory/sources/composio_tests.rs
+++ b/crates/openhuman-core/src/memory/sources/composio_tests.rs
@@ -214,7 +214,12 @@ async fn forget_connection_removes_only_that_connections_items() {
)
.await
.unwrap();
- assert_eq!(forget_connection(&config, "conn-a").await.unwrap(), 1);
+ assert_eq!(
+ forget_connection(&config, "conn-a", Some("gmail"))
+ .await
+ .unwrap(),
+ 1
+ );
let left = stored(&engine, MetaFilter::default()).await;
assert_eq!(left.len(), 1);
assert!(left[0].meta.tags.contains(&"connection:conn-b".to_string()));
@@ -224,7 +229,48 @@ async fn forget_connection_removes_only_that_connections_items() {
async fn forget_connection_with_memory_off_forgets_nothing() {
let tmp = tempfile::tempdir().unwrap();
let config = config_in(&tmp);
- assert_eq!(forget_connection(&config, "conn-a").await.unwrap(), 0);
+ assert_eq!(
+ forget_connection(&config, "conn-a", Some("gmail"))
+ .await
+ .unwrap(),
+ 0
+ );
+}
+
+#[tokio::test]
+async fn forget_connection_reads_only_its_toolkits_source() {
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ let engine = bind_reference(&config);
+ let bound = crate::memory::engine::resolve(&config).engine().unwrap();
+ // The same connection tag in another toolkit's source: an item the
+ // scoped forget must not reach.
+ for toolkit in ["gmail", "notion"] {
+ store_records(
+ &config,
+ &bound,
+ toolkit,
+ "conn-a",
+ "src",
+ &MemoryLayout::default(),
+ &[record(toolkit, toolkit, &format!("from {toolkit}"))],
+ )
+ .await
+ .unwrap();
+ }
+ assert_eq!(
+ forget_connection(&config, "conn-a", Some("gmail"))
+ .await
+ .unwrap(),
+ 1
+ );
+ let left = stored(&engine, MetaFilter::default()).await;
+ assert_eq!(left.len(), 1);
+ assert_eq!(left[0].meta.namespace.to_string(), "source:notion");
+
+ // An unknown toolkit falls back to the whole tree.
+ assert_eq!(forget_connection(&config, "conn-a", None).await.unwrap(), 1);
+ assert!(stored(&engine, MetaFilter::default()).await.is_empty());
}
#[tokio::test]