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(memory): serialize connector stores; never overwrite an unmovable corrupt file
M3gA-Mind2aa134a56b2f
diff --git a/crates/openhuman-core/src/memory/sources/composio.rs b/crates/openhuman-core/src/memory/sources/composio.rsindex 7d4639eb4a..5a9e2d6bbe 100644--- a/crates/openhuman-core/src/memory/sources/composio.rs+++ b/crates/openhuman-core/src/memory/sources/composio.rs@@ -21,6 +21,15 @@ use crate::integrations::composio::ops::{use crate::memory::engine::BoundEngine;use crate::memory::error::{MemoryError, MemoryResult};+/// Held across one [`store_records`] call: storing, finding the previous+/// versions and forgetting them. Two passes over the same records (the+/// on-demand and the scheduled sync) would otherwise interleave, and one+/// could forget an item the other has just made current again.+// ponytail: one lock for every connection, as passes are short and rare; a+// per-connection lock if syncs of many accounts must overlap.+static STORE: std::sync::LazyLock<tokio::sync::Mutex<()>> =+ std::sync::LazyLock::new(|| tokio::sync::Mutex::new(()));+/// Most connector passes one source sync runs per connection.const MAX_PASSES_PER_CONNECTION: usize = 25;@@ -80,6 +89,7 @@ pub async fn store_records(layout: &tinymemory_tools::MemoryLayout,records: &[ConnectorRecord],) -> MemoryResult<u64> {+ let _serial = STORE.lock().await;let mut keys = Vec::with_capacity(records.len());let mut items = Vec::with_capacity(records.len());let mut emptied = Vec::new();diff --git a/crates/openhuman-core/src/memory/sources/versions.rs b/crates/openhuman-core/src/memory/sources/versions.rsindex 2a912257f6..9ecbdc26fc 100644--- a/crates/openhuman-core/src/memory/sources/versions.rs+++ b/crates/openhuman-core/src/memory/sources/versions.rs@@ -57,17 +57,26 @@ fn load(workspace_dir: &Path) -> Option<Versions> {return None;}};- Some(serde_json::from_str(&text).unwrap_or_else(|error| {- tracing::warn!(error = %error, "[memory:sources] connector item versions unparsable");- set_aside(&file)- }))+ match serde_json::from_str(&text) {+ Ok(versions) => Some(versions),+ Err(error) => {+ tracing::warn!(error = %error, "[memory:sources] connector item versions unparsable");+ set_aside(&file)+ }+ }}-fn set_aside(file: &Path) -> Versions {- if let Err(error) = std::fs::rename(file, file.with_extension("json.corrupt")) {- tracing::warn!(error = %error, "[memory:sources] could not set the versions file aside");+/// Moves an unparsable file to `.corrupt` and starts from empty, or, when+/// it cannot be moved, changes nothing (`None`), so a later save never+/// overwrites the only copy.+fn set_aside(file: &Path) -> Option<Versions> {+ match std::fs::rename(file, file.with_extension("json.corrupt")) {+ Ok(()) => Some(Versions::default()),+ Err(error) => {+ tracing::warn!(error = %error, "[memory:sources] could not set the versions file aside; skipping");+ None+ }}- Versions::default()}/// Writes through a temporary file and a rename, so a stop mid-write never