Skip to content

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

chore: files changed crates/openhuman-core/src/channels/controllers/ops/connect/memory.rs,crates/ope

Steven Enamakel78f9c9e70149
diff --git a/crates/openhuman-core/src/channels/controllers/ops/connect/memory.rs b/crates/openhuman-core/src/channels/controllers/ops/connect/memory.rs
index f16a9eb6c2..535bf50e87 100644
--- a/crates/openhuman-core/src/channels/controllers/ops/connect/memory.rs
+++ b/crates/openhuman-core/src/channels/controllers/ops/connect/memory.rs
@@ -2,8 +2,8 @@
use crate::config::Config;
-/// Forgets every conversation memory logged from this channel (the threads
-/// `memory::channels` recorded for it), and reports how many items went.
+/// Forgets every conversation memory logged from this channel, and reports
+/// how many items went.
///
/// The count is reported to the caller as `memory_chunks_deleted` (the
/// disconnect reply's field name predates memory v2 and is kept as a wire
diff --git a/crates/openhuman-core/src/memory/README.md b/crates/openhuman-core/src/memory/README.md
index 94c98d5481..36c9fc40e8 100644
--- a/crates/openhuman-core/src/memory/README.md
+++ b/crates/openhuman-core/src/memory/README.md
@@ -355,8 +355,9 @@ trusted call facts; queued writes retain that call's narrower reach.
deletion workflows retain their own behavior.
- `deletion::forget_thread` (`deletion.rs`): called by `threads` when a
- thread is deleted. `channels::forget_channel` is called by `channels` on
- disconnect.
+ thread is deleted. `ops::forget_channel` is called on channel disconnect; it
+ forgets channel-stamped turns and falls back to the previous release's
+ thread ownership data for older unstamped conversations.
- Upstream `tinymemory_api::Error` values map at the RPC boundary ([`error.rs`](./error.rs)):
every RPC failure carries one of `MEMORY_OFF`,
`UNSUPPORTED`, `INVALID_REQUEST`, `UNAUTHORIZED`, `INSUFFICIENT_CREDITS`,
@@ -389,7 +390,6 @@ files under `<workspace>/memory/`, written owner-only through [`files.rs`](./fil
| File | Owner |
| --- | --- |
| `jobs.json` | `lifecycle/jobs.rs` |
-| `channel_threads.json` | `channels.rs` |
| `pending_deletions.json` | `deletion.rs` |
| `sources_state.json` | [`sources/state.rs`](./sources/state.rs) |
| `conversations_backfill.json` | `backfill.rs` |
@@ -397,6 +397,11 @@ files under `<workspace>/memory/`, written owner-only through [`files.rs`](./fil
| `layout_migration.json` | [`layout_migration/state.rs`](./layout_migration/state.rs) |
| `local_root.json` | `local_root.rs` |
+For one release, disconnect reads a valid `channel_threads.json` written by
+older versions as a read-only fallback for legacy conversations. Current code
+does not write this file. Malformed JSON keeps the existing quarantine behavior;
+remove the compatibility reader in the next release.
+
The sources registry is `[[memory.sources]]` in `config.toml`. The CortexDB
key is in the OS keyring. The layout migration's shared-tree claim marker
sits in the app directory shared by all accounts
diff --git a/crates/openhuman-core/src/memory/channels.rs b/crates/openhuman-core/src/memory/channels.rs
deleted file mode 100644
index ad3a94324c..0000000000
--- a/crates/openhuman-core/src/memory/channels.rs
+++ /dev/null
@@ -1,158 +0,0 @@
-//! Which channel each logged thread arrived on, so a channel's memory can be
-//! forgotten when it is disconnected.
-//!
-//! TinyMemory's turn items carry the thread, not the channel. The session
-//! host records the pairing when it logs a turn ([`record`]), in
-//! `<workspace>/memory/channel_threads.json`; [`forget_channel`] forgets the
-//! conversations of every thread a channel owns.
-
-use std::collections::{BTreeMap, BTreeSet};
-use std::path::{Path, PathBuf};
-use std::sync::{LazyLock, Mutex};
-
-use tinymemory_api::{ForgetTarget, ItemKind, MetaFilter};
-
-use crate::config::Config;
-
-use super::engine;
-use tinymemory_api::{Error, Result};
-
-/// Serialises read-modify-writes of the file in this process.
-static LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
-
-fn path(workspace_dir: &Path) -> PathBuf {
- workspace_dir.join("memory").join("channel_threads.json")
-}
-
-fn read(workspace_dir: &Path) -> BTreeMap<String, BTreeSet<String>> {
- let file = path(workspace_dir);
- let Ok(text) = std::fs::read_to_string(&file) else {
- return BTreeMap::new();
- };
- serde_json::from_str(&text).unwrap_or_else(|error| {
- tracing::warn!(%error, "[memory:channels] channel threads unparsable; set aside");
- if let Err(error) = std::fs::rename(&file, file.with_extension("json.corrupt")) {
- tracing::warn!(%error, "[memory:channels] could not set channel threads file aside");
- }
- BTreeMap::new()
- })
-}
-
-fn write(workspace_dir: &Path, all: &BTreeMap<String, BTreeSet<String>>) {
- let file = path(workspace_dir);
- let result = serde_json::to_vec_pretty(all)
- .map_err(std::io::Error::other)
- .and_then(|json| {
- crate::security::secret_storage::file_store::write_atomic(&file, &json)
- .map_err(std::io::Error::other)
- });
- if let Err(error) = result {
- tracing::warn!(%error, "[memory:channels] writing channel threads failed");
- }
-}
-
-fn key(channel: &str) -> String {
- channel.trim().to_ascii_lowercase()
-}
-
-/// Records that `thread_id` arrived on `channel`.
-pub fn record(workspace_dir: &Path, channel: &str, thread_id: &str) {
- let channel = key(channel);
- if channel.is_empty() || thread_id.trim().is_empty() {
- return;
- }
- let _guard = LOCK
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner);
- let mut all = read(workspace_dir);
- if all
- .entry(channel)
- .or_default()
- .insert(thread_id.to_string())
- {
- write(workspace_dir, &all);
- }
-}
-
-/// The threads `channel` owns.
-#[must_use]
-pub fn threads_of(workspace_dir: &Path, channel: &str) -> Vec<String> {
- read(workspace_dir)
- .get(&key(channel))
- .map(|threads| threads.iter().cloned().collect())
- .unwrap_or_default()
-}
-
-/// 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. A thread that cannot be
-/// forgotten now (memory off, or a failed forget) is queued as a thread
-/// deletion ([`super::deletion`]) and runs on the next sign-in; the queue
-/// names the threads the channel owned at disconnect, so a thread the
-/// channel brings later is never caught by it. A failure is returned after
-/// the rest are tried.
-pub async fn forget_channel(config: &Config, channel: &str) -> Result<usize> {
- let threads = threads_of(&config.workspace_dir, channel);
- let bound = match engine::resolve(config).engine() {
- Ok(bound) => Some(bound),
- Err(Error::Off(_)) => None,
- Err(error) => return Err(error),
- };
- let mut forgotten = 0;
- let mut failure = None;
- for thread_id in threads {
- let result = match &bound {
- Some(bound) => forget_thread_with(bound, &thread_id).await,
- None => Err(Error::Off("memory is off".to_string())),
- };
- match result {
- Ok(count) => forgotten += count,
- Err(error) => {
- super::deletion::enqueue(
- &config.workspace_dir,
- super::deletion::PendingDeletion::Thread { thread_id },
- );
- if !matches!(error, Error::Off(_)) && failure.is_none() {
- failure = Some(error);
- }
- }
- }
- }
- {
- let _guard = LOCK
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner);
- let mut all = read(&config.workspace_dir);
- if all.remove(&key(channel)).is_some() {
- write(&config.workspace_dir, &all);
- }
- }
- tracing::debug!(
- forgotten,
- queued = bound.is_none(),
- "[memory:channels] channel forgotten"
- );
- match failure {
- Some(error) => Err(error),
- None => Ok(forgotten),
- }
-}
-
-async fn forget_thread_with(bound: &engine::BoundEngine, thread_id: &str) -> Result<usize> {
- let filter = MetaFilter {
- thread_id: Some(thread_id.to_string()),
- ..MetaFilter::kinds([ItemKind::Conversation])
- };
- Ok(bound
- .engine
- .forget(ForgetTarget::Filter(filter))
- .await?
- .forgotten)
-}
-
-#[cfg(test)]
-#[path = "channels_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/memory/channels_tests.rs b/crates/openhuman-core/src/memory/channels_tests.rs
deleted file mode 100644
index fb4401609c..0000000000
--- a/crates/openhuman-core/src/memory/channels_tests.rs
+++ /dev/null
@@ -1,87 +0,0 @@
-use super::*;
-
-#[test]
-fn records_threads_per_channel_case_insensitively() {
- let tmp = tempfile::tempdir().unwrap();
- record(tmp.path(), "Telegram", "t-1");
- record(tmp.path(), "telegram", "t-1");
- record(tmp.path(), "telegram", "t-2");
- record(tmp.path(), "", "t-3");
- record(tmp.path(), "web", " ");
- assert_eq!(threads_of(tmp.path(), "TELEGRAM"), ["t-1", "t-2"]);
- assert!(threads_of(tmp.path(), "web").is_empty());
-}
-
-#[test]
-fn corrupt_channel_thread_file_is_set_aside() {
- let tmp = tempfile::tempdir().unwrap();
- let file = path(tmp.path());
- std::fs::create_dir_all(file.parent().unwrap()).unwrap();
- std::fs::write(&file, b"{\"telegram\":[").unwrap();
-
- assert!(threads_of(tmp.path(), "telegram").is_empty());
- assert!(
- !file.exists(),
- "corrupt state must not be silently replaced"
- );
- assert_eq!(
- std::fs::read(file.with_extension("json.corrupt")).unwrap(),
- b"{\"telegram\":["
- );
-}
-
-#[tokio::test]
-async fn a_channel_forgotten_while_signed_out_queues_each_thread_it_owned() {
- use crate::memory::deletion::{pending, PendingDeletion};
- use crate::memory::test_fixtures::config_in;
-
- let tmp = tempfile::tempdir().unwrap();
- let config = config_in(&tmp);
- record(&config.workspace_dir, "telegram", "t-1");
- record(&config.workspace_dir, "telegram", "t-2");
-
- assert_eq!(forget_channel(&config, "telegram").await.unwrap(), 0);
- assert_eq!(
- pending(&config.workspace_dir),
- vec![
- PendingDeletion::Thread {
- thread_id: "t-1".into()
- },
- PendingDeletion::Thread {
- thread_id: "t-2".into()
- },
- ]
- );
- // The channel's record goes now, so a thread it brings after a
- // reconnect is never caught by the queued deletion.
- assert!(threads_of(&config.workspace_dir, "telegram").is_empty());
-}
-
-#[tokio::test]
-async fn a_channels_conversations_are_forgotten_and_others_kept() {
- use crate::memory::test_fixtures::{bind_reference, config_in, stored};
- use tinymemory_api::{MemoryEngine, MemoryMeta, Role, StoreItem, Turn};
-
- let tmp = tempfile::tempdir().unwrap();
- let config = config_in(&tmp);
- let engine = bind_reference(&config);
- for thread in ["t-chan", "t-web"] {
- engine
- .store(StoreItem::Conversation {
- turns: vec![Turn::new(Role::User, thread.to_string())],
- meta: MemoryMeta {
- thread_id: Some(thread.to_string()),
- ..MemoryMeta::default()
- },
- })
- .await
- .unwrap();
- }
- record(&config.workspace_dir, "telegram", "t-chan");
-
- assert_eq!(forget_channel(&config, "telegram").await.unwrap(), 1);
- let left = stored(&engine, MetaFilter::default()).await;
- assert_eq!(left.len(), 1);
- assert_eq!(left[0].meta.thread_id.as_deref(), Some("t-web"));
- assert!(crate::memory::deletion::pending(&config.workspace_dir).is_empty());
-}
diff --git a/crates/openhuman-core/src/memory/mod.rs b/crates/openhuman-core/src/memory/mod.rs
index be194ee2f9..f274192d4c 100644
--- a/crates/openhuman-core/src/memory/mod.rs
+++ b/crates/openhuman-core/src/memory/mod.rs
@@ -10,7 +10,6 @@
//! | [`ops`] | Engine selection, recall, fetch, learn, forget, list, the pack preview |
//! | [`brain`] | The shared brain: documents by source type |
//! | [`sources`] | The `[[memory.sources]]` registry and sync into the brain (folder, file, link, github, rss, composio) |
-//! | [`channels`] | Which channel each logged thread arrived on, for forgetting a channel |
//! | [`backfill`] | Consent-gated storing of chats from before turns were logged |
//! | [`import`] | Consent-gated, resumable import of a v1 store |
//! | [`tools`] | The single `memory` agent tool |
@@ -23,7 +22,6 @@ pub mod backfill;
pub mod billing;
pub mod brain;
pub mod bus;
-pub mod channels;
pub mod deletion;
pub mod engine;
pub mod error;