Skip to content

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

feat(memory): add channel-based memory source support

Steven Enamakeld5af6e7aff33
diff --git a/crates/openhuman-core/src/memory/channels.rs b/crates/openhuman-core/src/memory/channels.rs
index a31dad6231..9ec34fdabb 100644
--- a/crates/openhuman-core/src/memory/channels.rs
+++ b/crates/openhuman-core/src/memory/channels.rs
@@ -77,14 +77,42 @@ pub fn threads_of(workspace_dir: &Path, channel: &str) -> Vec<String> {
.unwrap_or_default()
}
-/// Forgets every conversation logged from `channel` and drops its record.
-/// Memory off forgets nothing and reports zero.
+/// Forgets, for good, every conversation logged from `channel` and drops
+/// its record. Conversations share their chat node with other channels, so
+/// there is no channel scope to erase: each thread's items are removed by
+/// `memory_ids` (with an explicit `redact_events` cascade).
+///
+/// Memory off forgets nothing now and reports zero; the deletion is queued
+/// ([`super::deletion`]) and runs on the next sign-in, with the channel's
+/// thread record kept until then. A failure is queued the same way.
pub async fn forget_channel(config: &Config, channel: &str) -> MemoryResult<usize> {
+ let pending = || super::deletion::PendingDeletion::Channel {
+ channel: key(channel),
+ };
let bound = match engine::resolve(config).engine() {
Ok(bound) => bound,
- Err(MemoryError::Off(_)) => return Ok(0),
+ Err(MemoryError::Off(_)) => {
+ if !threads_of(&config.workspace_dir, channel).is_empty() {
+ super::deletion::enqueue(&config.workspace_dir, pending());
+ }
+ return Ok(0);
+ }
Err(error) => return Err(error),
};
+ match forget_channel_with(config, &bound, channel).await {
+ Ok(forgotten) => Ok(forgotten),
+ Err(error) => {
+ super::deletion::enqueue(&config.workspace_dir, pending());
+ Err(error)
+ }
+ }
+}
+
+async fn forget_channel_with(
+ config: &Config,
+ bound: &engine::BoundEngine,
+ channel: &str,
+) -> MemoryResult<usize> {
let mut forgotten = 0;
for thread_id in threads_of(&config.workspace_dir, channel) {
let filter = MetaFilter {
diff --git a/crates/openhuman-core/src/memory/mod.rs b/crates/openhuman-core/src/memory/mod.rs
index 4136945175..fe83517d5c 100644
--- a/crates/openhuman-core/src/memory/mod.rs
+++ b/crates/openhuman-core/src/memory/mod.rs
@@ -25,6 +25,7 @@ pub mod brain;
pub mod bus;
pub mod channels;
pub(crate) mod convert;
+pub mod deletion;
pub mod engine;
pub mod error;
pub mod explore;
diff --git a/crates/openhuman-core/src/memory/sources/mod.rs b/crates/openhuman-core/src/memory/sources/mod.rs
index 8168e1d6fb..ee8bc01d46 100644
--- a/crates/openhuman-core/src/memory/sources/mod.rs
+++ b/crates/openhuman-core/src/memory/sources/mod.rs
@@ -177,19 +177,33 @@ pub fn apply_remove(config: &mut Config, id: &str) -> Option<MemorySourceConfig>
Some(removed)
}
-/// Forgets every item source `id` stored. Memory off is not an error here:
-/// there is nothing reachable to forget.
+/// Forgets, for good, every item source `id` stored (by `memory_ids`, with
+/// an explicit `redact_events` cascade). Memory off is not an error here:
+/// the deletion is queued ([`crate::memory::deletion`]) and runs on the next
+/// sign-in. A failure is queued the same way, and returned.
pub async fn forget_items(config: &Config, id: &str) -> MemoryResult<usize> {
+ let pending = || crate::memory::deletion::PendingDeletion::Source {
+ source_id: id.to_string(),
+ };
let bound = match engine::resolve(config).engine() {
Ok(bound) => bound,
- Err(MemoryError::Off(_)) => return Ok(0),
+ Err(MemoryError::Off(_)) => {
+ crate::memory::deletion::enqueue(&config.workspace_dir, pending());
+ return Ok(0);
+ }
Err(error) => return Err(error),
};
let filter = MetaFilter {
source_id: Some(id.to_string()),
..MetaFilter::default()
};
- let report = bound.engine.forget(ForgetTarget::Filter(filter)).await?;
+ let report = match bound.engine.forget(ForgetTarget::Filter(filter)).await {
+ Ok(report) => report,
+ Err(error) => {
+ crate::memory::deletion::enqueue(&config.workspace_dir, pending());
+ return Err(error.into());
+ }
+ };
tracing::debug!(id = %id, forgotten = report.forgotten, "[memory:sources] items forgotten");
Ok(report.forgotten)
}