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
feat(storage): import legacy state files into the document store
Steven Enamakel32ac50a06794
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rsindex 5bd20311e7..ee5039f8bc 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs@@ -7,15 +7,48 @@ impl SubagentSessionStore {Self { workspace_dir }}+ /// The pre-documents `<workspace>/.openhuman/subagent_sessions.json`.+ fn legacy_path(&self) -> PathBuf {+ self.workspace_dir+ .join(".openhuman")+ .join("subagent_sessions.json")+ }++ /// 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.+ fn import_legacy(&self, docs: &super::store_documents::Docs) -> Result<(), String> {+ let path = self.legacy_path();+ let raw = match std::fs::read_to_string(&path) {+ Ok(raw) => raw,+ Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(()),+ Err(err) => return Err(format!("failed to read legacy subagent sessions: {err}")),+ };+ 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:#}"))?;+ 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(())+ }+pub fn load(&self) -> Result<Vec<DurableSubagentSession>, String> {- super::store_documents::current(&self.workspace_dir)- .and_then(|docs| docs.load())- .map_err(|err| format!("{err:#}"))+ let docs = super::store_documents::current(&self.workspace_dir)+ .map_err(|err| format!("{err:#}"))?;+ self.import_legacy(&docs)?;+ docs.load().map_err(|err| format!("{err:#}"))}pub fn save(&self, sessions: &[DurableSubagentSession]) -> Result<(), String> {- super::store_documents::current(&self.workspace_dir)- .and_then(|docs| docs.save(sessions))- .map_err(|err| format!("{err:#}"))+ let docs = super::store_documents::current(&self.workspace_dir)+ .map_err(|err| format!("{err:#}"))?;+ self.import_legacy(&docs)?;+ docs.save(sessions).map_err(|err| format!("{err:#}"))}}diff --git a/crates/openhuman-core/src/integrations/composio/file_store.rs b/crates/openhuman-core/src/integrations/composio/file_store.rsindex 23c48277f4..55731058f6 100644--- a/crates/openhuman-core/src/integrations/composio/file_store.rs+++ b/crates/openhuman-core/src/integrations/composio/file_store.rs@@ -19,6 +19,42 @@ pub(crate) const IDENTITIES_FILE: &str = "composio_identities.json";/// Per-toolkit agent scope prefs value name.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.+async fn import_legacy(+ config: &Config,+ docs: &super::file_store_documents::Docs,+ name: &'static str,+) -> Result<(), String> {+ let path = config.workspace_dir.join("integrations").join(name);+ let bytes = match tokio::fs::read(&path).await {+ Ok(bytes) => bytes,+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(()),+ Err(error) => {+ return Err(format!(+ "[composio:store] reading legacy {name} failed: {error}"+ ))+ }+ };+ let value: serde_json::Value = serde_json::from_slice(&bytes)+ .map_err(|error| format!("[composio:store] parsing legacy {name} failed: {error}"))?;+ let docs = docs.clone();+ let wrote = crate::core::runtime::spawn_blocking_scoped(move || {+ docs.import_if_absent(name, value)+ })+ .await+ .map_err(|error| format!("[composio:store] importing legacy {name} failed: {error}"))?+ .map_err(|error| 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(())+}+/// The value stored under `name`, or `T::default()` when there is none.////// # Errors@@ -30,6 +66,7 @@ where{let docs = super::file_store_documents::current(&config.workspace_dir).map_err(|e| format!("[composio:store] {e:#}"))?;+ import_legacy(config, &docs, name).await?;// The document port is reached through a blocking bridge; keep it off the// async worker, under the caller's context.crate::core::runtime::spawn_blocking_scoped(move || docs.load(name))@@ -56,6 +93,7 @@ where{let docs = super::file_store_documents::current(&config.workspace_dir).map_err(|e| format!("[composio:store] {e:#}"))?;+ import_legacy(config, &docs, name).await?;crate::core::runtime::spawn_blocking_scoped(move || docs.update(name, change)).await.map_err(|error| format!("[composio:store] updating {name} failed: {error}"))?diff --git a/crates/openhuman-core/src/integrations/composio/file_store_documents.rs b/crates/openhuman-core/src/integrations/composio/file_store_documents.rsindex 8928d8d446..f5538f9dff 100644--- a/crates/openhuman-core/src/integrations/composio/file_store_documents.rs+++ b/crates/openhuman-core/src/integrations/composio/file_store_documents.rs@@ -119,6 +119,22 @@ impl Docs {})}+ /// 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.+ 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() == tinystoragedrivers::ErrorKind::Conflict => Ok(false),+ Err(error) => Err(error),+ }+ })+ }+#[cfg(test)]pub(super) fn save<T: Serialize>(&self, name: &str, value: &T) -> Result<()> {let id = name.to_string();diff --git a/docs/gitbooks/en/developing/architecture.md b/docs/gitbooks/en/developing/architecture.mdindex 2e6fa2bf26..e40812c31a 100644--- a/docs/gitbooks/en/developing/architecture.md+++ b/docs/gitbooks/en/developing/architecture.md@@ -230,7 +230,7 @@ Conversation state is separate from memory: each thread's transcript is a JSONL## Storage-Durable state sits on the ports of `tinystoragedrivers` (documents, streams, blobs, search, secrets), vendored through `vendor/tinyagents/vendor/tinystoragedrivers`. One URL picks the backend for the process: `OPENHUMAN_STORAGE_URL`, else `[storage] url`, else nothing, which keeps the classic per-domain files on desktop. The drivers are Cargo features (`storage-sqlite`, `storage-file`, `storage-mongodb`; `memory` is always there), and a URL for a driver the build lacks fails at boot. Records live in a scope: the tenant's profile when work runs for one, else the acting agent's id, else `local` for the operator in single-user mode. In SaaS mode a call with no profile is refused. The host side is `crates/openhuman-core/src/storage/`. See [Storage](architecture/storage.md).+Durable state sits on the ports of `tinystoragedrivers` (documents, streams, blobs, search, secrets), vendored through `vendor/tinyagents/vendor/tinystoragedrivers`. One URL picks the backend for the process: `OPENHUMAN_STORAGE_URL`, else `[storage] url`, else the workspace default, `sqlite:<workspace>/storage`, so a build needs the `storage-sqlite` driver (or a URL for another one). The drivers are Cargo features (`storage-sqlite`, `storage-file`, `storage-mongodb`; `memory` is always there), and a URL for a driver the build lacks fails at boot. Records live in a scope: the tenant's profile when work runs for one, else the acting agent's id, else `local` for the operator in single-user mode. In SaaS mode a call with no profile is refused. The host side is `crates/openhuman-core/src/storage/`. See [Storage](architecture/storage.md).## Security architecture