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(storage): mark legacy imports with documents instead of renaming files
Steven Enamakelcc8c5784fd32
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rsindex ee5039f8bc..d83e4ec835 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs@@ -15,10 +15,14 @@ impl SubagentSessionStore {}/// Imports the pre-documents session file once: its sessions are written- /// (an already stored newer copy wins) and the file is renamed to- /// `subagent_sessions.json.migrated`, so it is never imported again and- /// stays recoverable. A missing file is the common case and a no-op.+ /// (an already stored newer copy wins) and a marker document records that+ /// the import finished. The file is only read, never renamed or rewritten,+ /// so it stays byte-identical. A missing file is the common case and a+ /// no-op.fn import_legacy(&self, docs: &super::store_documents::Docs) -> Result<(), String> {+ if docs.legacy_imported().map_err(|err| format!("{err:#}"))? {+ return Ok(());+ }let path = self.legacy_path();let raw = match std::fs::read_to_string(&path) {Ok(raw) => raw,@@ -27,14 +31,12 @@ impl SubagentSessionStore {};let sessions: Vec<DurableSubagentSession> = serde_json::from_str(&raw).map_err(|err| format!("failed to parse legacy subagent sessions: {err}"))?;- docs.save(&sessions).map_err(|err| format!("{err:#}"))?;+ docs.import_legacy(&sessions)+ .map_err(|err| format!("{err:#}"))?;log::debug!("[subagent_sessions] imported legacy sessions count={}",sessions.len());- if let Err(err) = std::fs::rename(&path, path.with_extension("json.migrated")) {- log::warn!("[subagent_sessions] could not retire legacy file: {err}");- }Ok(())}diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rsindex 4e6719d699..5a0058a295 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs@@ -10,6 +10,7 @@//! | Collection | Document id | Holds |//! | --- | --- | --- |//! | `subagent_sessions` | the session id | one [`DurableSubagentSession`] plus `created_at` for ordering |+//! | `subagent_sessions_import` | `subagent_sessions.json` | marker: the legacy file was imported (it is left byte-identical) |//!//! The callers in `ops.rs` load and save the whole list. `save` writes each session as//! its own document, so a session's history stays well under any document-size@@ -27,10 +28,14 @@ use crate::storage::documents::Repo;use crate::storage::DocumentStoreExt;const SESSIONS: &str = "subagent_sessions";+/// Holds the marker document that records the one-time legacy file import, in+/// a collection of its own so `load` never sees it as a session.+const IMPORTED: &str = "subagent_sessions_import";+const LEGACY_MARKER: &str = "subagent_sessions.json";const DOMAIN: &str = "subagent_sessions::store";fn collections() -> Vec<CollectionSpec> {- vec![CollectionSpec::new(SESSIONS)]+ vec![CollectionSpec::new(SESSIONS), CollectionSpec::new(IMPORTED)]}/// The document store for this call: the installed backend, else the@@ -84,6 +89,35 @@ impl Docs {.collect()}+ /// Whether the one-time legacy file import finished in this scope.+ pub(super) fn legacy_imported(&self) -> Result<bool> {+ let found = self+ .0+ .run(|docs| async move { docs.get(IMPORTED, LEGACY_MARKER).await })?;+ Ok(found.is_some())+ }++ /// Imports `sessions` read from the legacy file (a stored newer copy+ /// wins), then records the import in a marker document.+ pub(super) fn import_legacy(&self, sessions: &[DurableSubagentSession]) -> Result<()> {+ self.save(sessions)?;+ self.0.run(|docs| async move {+ match docs+ .put(+ IMPORTED,+ LEGACY_MARKER,+ serde_json::json!({ "imported": true }),+ Precondition::Absent,+ )+ .await+ {+ Ok(_) => Ok(()),+ Err(error) if error.kind() == tinystoragedrivers::ErrorKind::Conflict => Ok(()),+ Err(error) => Err(error),+ }+ })+ }+pub(super) fn save(&self, sessions: &[DurableSubagentSession]) -> Result<()> {let mut writes = Vec::with_capacity(sessions.len());for session in sessions {diff --git a/crates/openhuman-core/src/integrations/composio/file_store.rs b/crates/openhuman-core/src/integrations/composio/file_store.rsindex f3ce082391..31b1f47675 100644--- a/crates/openhuman-core/src/integrations/composio/file_store.rs+++ b/crates/openhuman-core/src/integrations/composio/file_store.rs@@ -20,14 +20,23 @@ pub(crate) const IDENTITIES_FILE: &str = "composio_identities.json";pub(crate) const USER_SCOPES_FILE: &str = "composio_user_scopes.json";/// Moves a pre-documents `<workspace>/integrations/<name>` file into the-/// document store, once: the value is stored only if none exists yet, then the-/// file is renamed to `<name>.migrated` so it is never imported again and the-/// old data stays recoverable. A missing file is the common case and a no-op.+/// document store, once: the value is stored only if none exists yet, then a+/// marker document records that the import finished. The legacy file is only+/// ever read, never renamed or rewritten, so the old data stays byte-identical.+/// A missing file is the common case and a no-op.async fn import_legacy(config: &Config,docs: &super::file_store_documents::Docs,name: &'static str,) -> Result<(), String> {+ let marker_docs = docs.clone();+ let done = crate::core::runtime::spawn_blocking_scoped(move || marker_docs.legacy_imported(name))+ .await+ .map_err(|error| format!("[composio:store] checking legacy {name} failed: {error}"))?+ .map_err(|error| format!("[composio:store] checking legacy {name} failed: {error:#}"))?;+ if done {+ return Ok(());+ }let path = config.workspace_dir.join("integrations").join(name);let bytes = match tokio::fs::read(&path).await {Ok(bytes) => bytes,@@ -49,10 +58,6 @@ async fn import_legacy(format!("[composio:store] importing legacy {name} failed: {error:#}")})?;log::debug!("[composio:store] legacy import name={name} wrote={wrote}");- let migrated = path.with_file_name(format!("{name}.migrated"));- if let Err(error) = tokio::fs::rename(&path, &migrated).await {- log::warn!("[composio:store] could not retire legacy {name}: {error}");- }Ok(())}diff --git a/crates/openhuman-core/src/integrations/composio/file_store_documents.rs b/crates/openhuman-core/src/integrations/composio/file_store_documents.rsindex 4c89aa3aaf..7ac262a847 100644--- a/crates/openhuman-core/src/integrations/composio/file_store_documents.rs+++ b/crates/openhuman-core/src/integrations/composio/file_store_documents.rs@@ -11,6 +11,7 @@//! | Collection | Document id | Holds |//! | --- | --- | --- |//! | `composio_state` | the value name (`composio_identities.json`, ...) | `value`: the serde value |+//! | `composio_state_import` | the value name | marker: the legacy `integrations/<name>` file was imported (the file is left byte-identical) |use std::path::Path;@@ -23,10 +24,13 @@ use tinystoragedrivers::{CollectionSpec, ErrorKind, Precondition, StorageError};use crate::storage::documents::Repo;const STATE: &str = "composio_state";+/// One marker document per legacy file whose one-time import finished, so the+/// file itself is never touched.+const IMPORTED: &str = "composio_state_import";const DOMAIN: &str = "composio::file_store";fn collections() -> Vec<CollectionSpec> {- vec![CollectionSpec::new(STATE)]+ vec![CollectionSpec::new(STATE), CollectionSpec::new(IMPORTED)]}/// The document store for this call: the installed backend, else the@@ -119,19 +123,40 @@ impl Docs {})}+ /// Whether the one-time import of the legacy `integrations/<name>` file+ /// finished in this scope.+ pub(super) fn legacy_imported(&self, name: &str) -> Result<bool> {+ let id = name.to_string();+ let found = self+ .0+ .run(|docs| async move { docs.get(IMPORTED, &id).await })?;+ Ok(found.is_some())+ }+/// Stores `value` under `name` only when no value is stored there yet- /// (the one-time import of a pre-documents state file). Returns whether it- /// wrote.+ /// (the one-time import of a pre-documents state file), then records the+ /// import in a marker document so it never runs again. The legacy file is+ /// not modified. Returns whether the value was written.pub(super) fn import_if_absent(&self, name: &str, value: serde_json::Value) -> Result<bool> {let id = name.to_string();let doc = json!({ "value": value });log::debug!("[composio:store] document import id={id}");self.0.run(|docs| async move {- match docs.put(STATE, &id, doc, Precondition::Absent).await {- Ok(_) => Ok(true),- Err(error) if error.kind() == ErrorKind::Conflict => Ok(false),- Err(error) => Err(error),+ let wrote = match docs.put(STATE, &id, doc, Precondition::Absent).await {+ Ok(_) => true,+ Err(error) if error.kind() == ErrorKind::Conflict => false,+ Err(error) => return Err(error),+ };+ match docs+ .put(IMPORTED, &id, json!({ "imported": true }), Precondition::Absent)+ .await+ {+ Ok(_) => {}+ // Another core finished first.+ Err(error) if error.kind() == ErrorKind::Conflict => {}+ Err(error) => return Err(error),}+ Ok(wrote)})}