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
fix: close library route and lock retention gaps
Steven Enamakelcf15e8138ac8
diff --git a/src/embed/harness/mod.rs b/src/embed/harness/mod.rsindex a7d9b42b3f..379842f887 100644--- a/src/embed/harness/mod.rs+++ b/src/embed/harness/mod.rs@@ -125,10 +125,10 @@ pub struct Harness {/// Borrowed access to the core owned by a [`Harness`].///-/// Unlike [`Core`], this facade is deliberately not cloneable and does not-/// expose the runtime `Arc`: a retained runtime could outlive the harness's-/// process-slot and workspace ownership. Share an `Arc<Harness>` when several-/// agents need concurrent access.+/// Unlike [`Core`], this facade is deliberately not cloneable and exposes+/// neither the unconfigured agent facade nor the raw runtime: either path+/// could start a turn without the harness's caller-supplied provider route.+/// Share an `Arc<Harness>` when several agents need concurrent turn access.pub struct HarnessCore<'a> {core: &'a Core,}@@ -142,19 +142,10 @@ impl HarnessCore<'_> {self.core.auth()}- pub fn agent(&self) -> crate::embed::Agent<'_> {- self.core.agent()- }-#[cfg(feature = "medulla")]pub fn medulla(&self) -> crate::embed::Medulla<'_> {self.core.medulla()}-- /// Borrow the underlying runtime without exposing its owning `Arc`.- pub fn raw(&self) -> &crate::core::runtime::CoreRuntime {- self.core.raw().as_ref()- }}impl Harness {@@ -195,8 +186,9 @@ impl Harness {turn}- /// The typed core facade beneath this harness — config, memory, and the- /// [`raw`](Core::raw) escape hatch for anything not yet modelled.+ /// Safe typed access to non-turn core domains. Agent turns intentionally+ /// remain on [`Harness::turn`], which always applies the harness provider+ /// route and access origin.pub fn core(&self) -> HarnessCore<'_> {HarnessCore {core: selfdiff --git a/src/openhuman/memory/conversations/store/store_locks.rs b/src/openhuman/memory/conversations/store/store_locks.rsindex 78d8d79769..651d81e5fa 100644--- a/src/openhuman/memory/conversations/store/store_locks.rs+++ b/src/openhuman/memory/conversations/store/store_locks.rs@@ -21,7 +21,7 @@ pub(super) struct StoreLocks {pub(super) metadata: Mutex<()>,/// Only one cold scan may construct this root's in-memory index.pub(super) index_build: Mutex<()>,- threads: Mutex<HashMap<String, Arc<Mutex<()>>>>,+ threads: Mutex<HashMap<String, Weak<Mutex<()>>>>,/// Appends completed while a cold scan is in flight. `None` means no scan/// is active, so the warm-cache path alone owns index maintenance.pending_index_appends: Mutex<Option<Vec<(String, ConversationMessage)>>>,@@ -30,11 +30,13 @@ pub(super) struct StoreLocks {impl StoreLocks {pub(super) fn thread(&self, thread_id: &str) -> Arc<Mutex<()>> {let mut locks = self.threads.lock();- Arc::clone(- locks- .entry(thread_id.to_string())- .or_insert_with(|| Arc::new(Mutex::new(()))),- )+ locks.retain(|_, lock| lock.strong_count() > 0);+ if let Some(lock) = locks.get(thread_id).and_then(Weak::upgrade) {+ return lock;+ }+ let lock = Arc::new(Mutex::new(()));+ locks.insert(thread_id.to_string(), Arc::downgrade(&lock));+ lock}pub(super) fn begin_index_build(&self) {@@ -68,7 +70,11 @@ impl StoreLocks {#[cfg(test)]pub(super) fn thread_count(&self) -> usize {- self.threads.lock().len()+ self.threads+ .lock()+ .values()+ .filter(|lock| lock.strong_count() > 0)+ .count()}}diff --git a/src/openhuman/memory/conversations/store/store_ops.rs b/src/openhuman/memory/conversations/store/store_ops.rsindex d91acf25ab..3c65c223b4 100644--- a/src/openhuman/memory/conversations/store/store_ops.rs+++ b/src/openhuman/memory/conversations/store/store_ops.rs@@ -167,6 +167,15 @@ impl ConversationStore {// re-reading this file.{let _metadata = self.locks.metadata.lock();+ // The transcript row is already durable. Publish it to an active+ // cold-build journal and any warm cache before the derived stats+ // append, which may fail independently.+ self.locks.record_index_append(thread_id, &message);+ let mut cache = CONVERSATION_INDEX_CACHE.lock();+ if let Some(idx) = cache.get_mut(&self.root_dir()) {+ idx.insert(thread_id, message.clone());+ }+ drop(cache);let threads_path = self.root_dir().join(THREADS_FILENAME);append_jsonl(&threads_path,@@ -175,15 +184,6 @@ impl ConversationStore {last_message_at: message.created_at.clone(),},)?;- // A cold builder scans without holding metadata. Journal the- // completed append before touching the cache so publication can- // fold it in; once publication finishes, this same critical- // section observes and updates the warm cache instead.- self.locks.record_index_append(thread_id, &message);- let mut cache = CONVERSATION_INDEX_CACHE.lock();- if let Some(idx) = cache.get_mut(&self.root_dir()) {- idx.insert(thread_id, message.clone());- }}Ok(message)}diff --git a/src/openhuman/memory/conversations/store/store_tests_late.rs b/src/openhuman/memory/conversations/store/store_tests_late.rsindex 68072f12cf..41d0167b05 100644--- a/src/openhuman/memory/conversations/store/store_tests_late.rs+++ b/src/openhuman/memory/conversations/store/store_tests_late.rs@@ -1,4 +1,5 @@use super::*;+use std::sync::Arc;#[test]fn search_cross_thread_messages_finds_japanese_bigram_match() {@@ -180,13 +181,14 @@ fn one_hundred_agent_threads_use_independent_message_locks() {let store = ConversationStore::new(temp.path().to_path_buf());let root_lock = store.lock_identity_for_test();let mut message_locks = std::collections::HashSet::new();+ let mut retained_locks = Vec::new();for index in 0..100 {let clone = ConversationStore::new(temp.path().to_path_buf());assert_eq!(clone.lock_identity_for_test(), root_lock);- assert!(- message_locks.insert(clone.thread_lock_identity_for_test(&format!("agent-{index}")))- );+ let lock = clone.locks.thread(&format!("agent-{index}"));+ assert!(message_locks.insert(Arc::as_ptr(&lock) as usize));+ retained_locks.push(lock);}assert_eq!(message_locks.len(), 100);@@ -456,17 +458,19 @@ fn delete_and_purge_evict_historical_thread_locks() {personality_id: None,}).unwrap();- let _ = store.thread_lock_identity_for_test("t1");+ let t1_lock = store.locks.thread("t1");assert_eq!(store.thread_lock_count_for_test(), 1);assert!(store.delete_thread("t1", "2026-04-10T12:02:00Z").unwrap());assert_eq!(store.thread_lock_count_for_test(), 0);+ drop(t1_lock);- for index in 0..100 {- let _ = store.thread_lock_identity_for_test(&format!("historical-{index}"));- }+ let historical_locks = (0..100)+ .map(|index| store.locks.thread(&format!("historical-{index}")))+ .collect::<Vec<_>>();assert_eq!(store.thread_lock_count_for_test(), 100);store.purge_threads().unwrap();assert_eq!(store.thread_lock_count_for_test(), 0);+ drop(historical_locks);}// ── legacy workspace (pre-Stats backfill path) ───────────────────────────────