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
perf(memory): store past chats with accepted writes
sanil-23050aedb5248d
diff --git a/crates/openhuman-core/src/memory/backfill.rs b/crates/openhuman-core/src/memory/backfill.rsindex 8605898230..c76098eb6f 100644--- a/crates/openhuman-core/src/memory/backfill.rs+++ b/crates/openhuman-core/src/memory/backfill.rs@@ -20,6 +20,10 @@//! in `<workspace>/memory/conversations_backfill.json`, so an interrupted run//! resumes and a later run sends only what is new. A re-sent item is a//! replay (its id is a content digest), never a duplicate.+//! - **Accepted, not indexed.** Batches go in with accepted writes: the+//! engine returns once it holds them durably, and indexes them after. A+//! run is `done` when every turn is stored; search catches up within+//! minutes. An engine without accepted writes stores them as before.//! - **Consent.** It uploads chat history to the selected engine, so//! [`start`] refuses without `consent`.@@ -34,7 +38,7 @@ use serde::{Deserialize, Serialize};use crate::config::Config;use crate::memory::engine::{self, BoundEngine};use crate::memory::error::{MemoryError, MemoryResult};-use crate::memory::ops::store_many_on;+use crate::memory::ops::store_many_on_with;use crate::memory::scope::{MemoryIdentity, ResolvedIdentity};use crate::memory::types::ImportPhase;use crate::threads::store::blocking as threads;@@ -284,7 +288,14 @@ async fn run();let count = items.len() as u64;if count > 0 {- if let Err(error) = store_many_on(bound, items).await {+ // Accepted, not indexed: the run reads nothing back, and+ // waiting on the engine to index every batch made a few+ // thousand messages take hours on CortexDB. They are durably+ // stored on return and searchable shortly after.+ let stored =+ store_many_on_with(bound, items, tinymemory_api::WriteOptions::accepted())+ .await;+ if let Err(error) = stored {tracing::warn!(code = error.code(),"[memory:backfill] storing a batch failed; stopping"diff --git a/crates/openhuman-core/src/memory/backfill_tests.rs b/crates/openhuman-core/src/memory/backfill_tests.rsindex fac061d695..483134733e 100644--- a/crates/openhuman-core/src/memory/backfill_tests.rs+++ b/crates/openhuman-core/src/memory/backfill_tests.rs@@ -175,3 +175,109 @@ async fn stores_past_chats_once_and_skips_what_live_logging_took() {assert_eq!(again.state.items_stored, 0);assert_eq!(stored(&engine, filter).await.len(), 6);}++/// The reference engine, recording how long each bulk store asked to wait.+struct WaitRecorder {+ inner: tinymemory_api::conformance::ReferenceEngine,+ waits: std::sync::Mutex<Vec<tinymemory_api::WaitFor>>,+}++#[async_trait::async_trait]+impl tinymemory_api::MemoryEngine for WaitRecorder {+ fn descriptor(&self) -> &tinymemory_api::EngineDescriptor {+ self.inner.descriptor()+ }+ async fn health(&self) -> tinymemory_api::EngineHealth {+ self.inner.health().await+ }+ async fn recall(+ &self,+ req: tinymemory_api::RecallRequest,+ ) -> tinymemory_api::Result<tinymemory_api::RecallAnswer> {+ self.inner.recall(req).await+ }+ async fn fetch(+ &self,+ req: tinymemory_api::FetchRequest,+ ) -> tinymemory_api::Result<tinymemory_api::FetchPage> {+ self.inner.fetch(req).await+ }+ async fn store(+ &self,+ item: tinymemory_api::StoreItem,+ ) -> tinymemory_api::Result<tinymemory_api::StoreReceipt> {+ self.inner.store(item).await+ }+ async fn store_many_with(+ &self,+ items: Vec<tinymemory_api::StoreItem>,+ options: tinymemory_api::WriteOptions,+ ) -> tinymemory_api::Result<Vec<tinymemory_api::StoreReceipt>> {+ self.waits.lock().unwrap().push(options.wait);+ self.inner.store_many_with(items, options).await+ }+ async fn forget(+ &self,+ target: tinymemory_api::ForgetTarget,+ ) -> tinymemory_api::Result<tinymemory_api::ForgetReport> {+ self.inner.forget(target).await+ }+ async fn list(+ &self,+ req: tinymemory_api::ListRequest,+ ) -> tinymemory_api::Result<tinymemory_api::ListPage> {+ self.inner.list(req).await+ }+}++#[tokio::test]+async fn batches_are_stored_accepted_without_waiting_on_indexing() {+ let tmp = tempfile::tempdir().unwrap();+ let config = config_in(&tmp);+ let engine = std::sync::Arc::new(WaitRecorder {+ inner: tinymemory_api::conformance::ReferenceEngine::new(),+ waits: std::sync::Mutex::new(Vec::new()),+ });+ crate::memory::engine::install_test_engine(&config.workspace_dir, engine.clone());+ seed_thread(+ &config.workspace_dir,+ "old-thread",+ &[+ ("user", "What is ownership?"),+ ("agent", "Values have one owner."),+ ("user", "And borrowing?"),+ ("agent", "References without ownership."),+ ],+ )+ .await;++ start(+ &DispatchCtx::ambient(),+ &config,+ BackfillStartParams { consent: true },+ )+ .await+ .unwrap();+ let done = wait_done(&config).await;+ assert_eq!(done.state.phase, ImportPhase::Done, "{:?}", done.state);+ assert_eq!(done.state.items_stored, 4);++ let waits = engine.waits.lock().unwrap().clone();+ assert!(!waits.is_empty(), "the backfill stores in bulk");+ assert!(+ waits+ .iter()+ .all(|wait| *wait == tinymemory_api::WaitFor::Accepted),+ "every batch is stored accepted, not visible: {waits:?}"+ );+ let filter = MetaFilter {+ kinds: vec![ItemKind::Conversation],+ tags_any: vec![BACKFILL_TAG.to_string()],+ ..MetaFilter::default()+ };+ assert_eq!(+ stored(&engine.inner, filter).await.len(),+ 4,+ "an engine without accepted writes still stores everything"+ );+}diff --git a/crates/openhuman-core/src/memory/ops.rs b/crates/openhuman-core/src/memory/ops.rsindex 467741974c..84e0128093 100644--- a/crates/openhuman-core/src/memory/ops.rs+++ b/crates/openhuman-core/src/memory/ops.rs@@ -363,16 +363,30 @@ pub async fn store_on_with(/// Stores `items` on `bound` in one bulk call (`MemoryEngine::store_many`):/// each is listed on return, ranked recall may lag behind for all but the-/// last. For imports and backfills.+/// last.pub async fn store_many_on(bound: &BoundEngine,items: Vec<StoreItem>,+) -> MemoryResult<Vec<StoreReceipt>> {+ store_many_on_with(bound, items, WriteOptions::visible()).await+}++/// [`store_many_on`], returning as soon as `options` allows. A backfill or an+/// import that reads nothing back until it ends passes+/// [`WriteOptions::accepted`]: an engine that supports it (CortexDB) returns+/// once the items are durably accepted, before they are indexed, and any+/// other stores them as [`store_many_on`] does.+pub async fn store_many_on_with(+ bound: &BoundEngine,+ items: Vec<StoreItem>,+ options: WriteOptions,) -> MemoryResult<Vec<StoreReceipt>> {let count = items.len();- let receipts = bound.engine.store_many(items).await?;+ let receipts = bound.engine.store_many_with(items, options).await?;tracing::debug!(engine = %bound.id,count,+ wait = ?options.wait,replayed = receipts.iter().filter(|r| r.replayed).count(),"[memory:ops] batch stored");diff --git a/docs/TEST-COVERAGE-MATRIX.md b/docs/TEST-COVERAGE-MATRIX.mdindex 1b3bc7ee12..ec15b1ce37 100644--- a/docs/TEST-COVERAGE-MATRIX.md+++ b/docs/TEST-COVERAGE-MATRIX.md@@ -369,7 +369,7 @@ Spec: `docs/specs/memory-v2.md` (host) and `vendor/tinymemory/docs/specs/memory-| ----- | ---------------------------------------- | ----- | ------------ | ------ | ----- || 8.2.1 | Engine list, select, status; memory off | RU+RI+WD | `crates/openhuman-core/src/memory/engine_tests.rs`, `crates/openhuman-core/src/memory/status_tests.rs`, `crates/openhuman-core/src/memory/error_tests.rs`, `tests/memory_v2_e2e.rs` (`memory_is_off_when_signed_out`, `signing_in_turns_memory_on`, `engines_list_get_and_set`, `engine_failures_surface_as_structured_errors`), `app/test/playwright/specs/memory-v2.spec.ts` | ✅ | TinyHumans and CortexDB || 8.2.2 | Per-account isolation | RU+RI | `crates/openhuman-core/src/memory/tool_writes_tests.rs`, `crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs`, `tests/memory_v2_e2e.rs` (`memory_is_isolated_per_account`) | ✅ | Shared-workspace outboxes and mutation barriers isolate owners; cached packs isolate identity, config, thread, workspace and core context. Credential changes reject late in-flight results |-| 8.2.3 | Turn logging and per-turn memory pack | RU+RI | `crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs`, `crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs`, `crates/openhuman-core/src/agent/tinyagents/memory_summarizer_tests.rs`, `crates/openhuman-core/src/memory/lifecycle/mod_tests.rs`, `crates/openhuman-core/src/memory/bus_tests.rs`, `tests/memory_v2_e2e.rs` (`a_chat_turn_carries_its_pack_and_is_logged`) | ✅ | Chat and transcript compaction consume only completed, scoped packs; refresh, turn logging, date extraction and compaction recall run in background. Held-engine and slow-refresh regressions prove these hooks do not delay inference or compaction. Packs expire after 60 seconds, are bounded, and stay ephemeral (`<memory-context>`); tool results are one line, no arguments |+| 8.2.3 | Turn logging and per-turn memory pack | RU+RI | `crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs`, `crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs`, `crates/openhuman-core/src/agent/tinyagents/memory_summarizer_tests.rs`, `crates/openhuman-core/src/memory/lifecycle/mod_tests.rs`, `crates/openhuman-core/src/memory/bus_tests.rs`, `crates/openhuman-core/src/memory/backfill_tests.rs`, `tests/memory_v2_e2e.rs` (`a_chat_turn_carries_its_pack_and_is_logged`) | ✅ | Past chats from before logging are stored by the consented backfill, in bulk with accepted writes (search catches up after the run). Chat and transcript compaction consume only completed, scoped packs; refresh, turn logging, date extraction and compaction recall run in background. Held-engine and slow-refresh regressions prove these hooks do not delay inference or compaction. Packs expire after 60 seconds, are bounded, and stay ephemeral (`<memory-context>`); tool results are one line, no arguments || 8.2.4 | Background jobs (belief builds) | RU+RI | `crates/openhuman-core/src/memory/lifecycle/jobs_tests.rs`, `crates/openhuman-core/src/memory/tool_writes_tests.rs`, `tests/memory_v2_e2e.rs` (`brain_pack_preview_and_jobs_round_trip`) | ✅ | `memory_background` cron, every 5 minutes; tool-write outboxes drain immediately and retry on credential/cron events after restart. Failures retain the FIFO head; background mutation deadlines allow up to 120 seconds without holding a chat turn || 8.2.5 | Document sources: add, sync, list, remove | RU+RI+WD | `crates/openhuman-core/src/memory/sources/sync_tests.rs`, `crates/openhuman-core/src/memory/sources/mod_tests.rs`, `tests/memory_v2_e2e.rs` (`sources_add_sync_list_and_remove`), `app/test/playwright/specs/memory-v2.spec.ts` | ✅ | folder, file, link, github, rss || 8.2.6 | Folder-source path picker | RU+VU | `crates/openhuman-app/src/directory_picker.rs`, `app/src/utils/tauriCommands/directoryPicker.test.ts` | ✅ | |