The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
chore: files changed crates/openhuman-core/src/memory/state_store.rs,crates/openhuman-core/src/memor
Steven Enamakel225f1571bae8
diff --git a/crates/openhuman-core/src/memory/state_store.rs b/crates/openhuman-core/src/memory/state_store.rsindex 0b2fd660dd..d27b387263 100644--- a/crates/openhuman-core/src/memory/state_store.rs+++ b/crates/openhuman-core/src/memory/state_store.rs@@ -15,6 +15,7 @@ use serde::de::DeserializeOwned;use serde::Serialize;use sha2::Digest;+use crate::storage::StorageBackend;use crate::storage::state_kv::StateKv;const OWNER: &str = "memory";@@ -103,10 +104,13 @@ fn open_strict(workspace_dir: &Path, name: &str) -> Result<StateKv> {////// A storage error or an unparsable file.pub(crate) fn import_all(- scoped: &crate::storage::ScopedStorage,+ backend: &std::sync::Arc<dyn crate::storage::StorageBackend>,workspace_dir: &Path,) -> Result<Vec<String>> {- let kv = StateKv::over(scoped, OWNER, NS);+ let local = backend.for_scope(&crate::storage::Scope::local())?;+ let local_kv = StateKv::over(&local, OWNER, NS);+ let queue_scope = workspace_scope(workspace_dir)?;+ let queue_kv = StateKv::on_backend(backend, &queue_scope, OWNER, NS)?;let mut names = Vec::new();let Ok(entries) = std::fs::read_dir(workspace_dir.join("memory")) else {return Ok(names);@@ -124,7 +128,11 @@ pub(crate) fn import_all(if !path.is_file() {continue;}- kv.import_file_strict(&name, &path)?;+ if name == "pending_deletions" {+ queue_kv.import_file_strict(&name, &path)?;+ } else {+ local_kv.import_file_strict(&name, &path)?;+ }names.push(name);}names.sort();diff --git a/crates/openhuman-core/src/memory/state_store_tests.rs b/crates/openhuman-core/src/memory/state_store_tests.rsindex 82796bfbf8..73223680a9 100644--- a/crates/openhuman-core/src/memory/state_store_tests.rs+++ b/crates/openhuman-core/src/memory/state_store_tests.rs@@ -86,6 +86,47 @@ fn workspace_scopes_keep_retry_queues_stable_and_isolated_on_shared_storage() {);}+#[test]+fn layout_import_places_legacy_retry_queue_in_its_workspace_scope() {+ let tmp = tempfile::tempdir().unwrap();+ let queue_file = super::legacy_path(tmp.path(), "pending_deletions");+ std::fs::create_dir_all(queue_file.parent().unwrap()).unwrap();+ std::fs::write(+ &queue_file,+ serde_json::to_vec(&vec![crate::memory::deletion::PendingDeletion::Thread {+ thread_id: "thread-legacy".into(),+ }])+ .unwrap(),+ )+ .unwrap();++ let backend: std::sync::Arc<dyn crate::storage::StorageBackend> =+ std::sync::Arc::new(crate::storage::MemoryStorage::new());+ super::import_all(&backend, tmp.path()).unwrap();++ let workspace_scope = super::workspace_scope(tmp.path()).unwrap();+ let workspace = backend.for_scope(&workspace_scope).unwrap();+ let queue = crate::storage::state_kv::StateKv::over(&workspace, "memory", "state");+ assert_eq!(+ queue+ .get::<Vec<crate::memory::deletion::PendingDeletion>>("pending_deletions")+ .unwrap(),+ Some(vec![crate::memory::deletion::PendingDeletion::Thread {+ thread_id: "thread-legacy".into(),+ }])+ );++ let local = backend.for_scope(&crate::storage::Scope::local()).unwrap();+ let local_queue = crate::storage::state_kv::StateKv::over(&local, "memory", "state");+ assert!(+ local_queue+ .get::<Vec<crate::memory::deletion::PendingDeletion>>("pending_deletions")+ .unwrap()+ .is_none(),+ "the migration must not strand a duplicate queue in local scope"+ );+}+#[test]fn state_values_do_not_leak_between_workspaces() {let first = tempfile::tempdir().unwrap();diff --git a/crates/openhuman-core/src/storage/layout/legacy.rs b/crates/openhuman-core/src/storage/layout/legacy.rsindex c49f0cda35..c933c1fff6 100644--- a/crates/openhuman-core/src/storage/layout/legacy.rs+++ b/crates/openhuman-core/src/storage/layout/legacy.rs@@ -11,7 +11,9 @@//! - the memory domain's `memory/*.json` state values (`tsd.kv`) and the//! legacy conversation log;//!-//! all into the `local` scope, the one the desktop operator's profile reads.+//! into the `local` scope, the one the desktop operator's profile reads. The+//! pending-deletion queue is workspace-owned and goes into its deterministic+//! workspace module scope so retries still find it after profile context ends.//! Every importer is idempotent and records its completion in//! `tsd.migrations`, so a resumed migration repeats nothing. An importer that//! fails fails the step: nothing may be archived-and-deleted that was not@@ -104,10 +106,7 @@ fn import_blocking(failures.push(format!("{}: {error:#}", report.domain));}}- let scoped = backend- .for_scope(&storage::tenant_scope(None))- .map_err(|e| LayoutError::Other(anyhow::anyhow!("open the local scope: {e}")))?;- match crate::memory::state_store::import_all(&scoped, workspace) {+ match crate::memory::state_store::import_all(backend, workspace) {Ok(names) => summary.memory_state = names,Err(error) => failures.push(format!("memory state: {error:#}")),}diff --git a/crates/openhuman-core/src/storage/state_kv.rs b/crates/openhuman-core/src/storage/state_kv.rsindex 1d04d1b61d..9450cbe0a0 100644--- a/crates/openhuman-core/src/storage/state_kv.rs+++ b/crates/openhuman-core/src/storage/state_kv.rs@@ -86,6 +86,18 @@ impl StateKv {Ok(Self { repo, owner, ns })}+ /// The state for an explicit backend and scope, for importers that must+ /// keep data on the backend they are migrating rather than reopen a URL.+ pub(crate) fn on_backend(+ backend: &Arc<dyn super::StorageBackend>,+ scope: &Scope,+ owner: &'static str,+ ns: &'static str,+ ) -> Result<Self> {+ let repo = Repo::on(backend, scope, "storage::state_kv", collections)?;+ Ok(Self { repo, owner, ns })+ }+/// The state over an already scoped handle (tests, explicit scopes).#[must_use]pub fn over(scoped: &ScopedStorage, owner: &'static str, ns: &'static str) -> Self {