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(subagent_sessions): persist subagent session documents
Steven Enamakela8a10c89aa6b
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rsindex e4cb017c18..4214ba6365 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs@@ -163,7 +163,6 @@ fn legacy_session_with_toolkit_key_still_loads_and_reuses() {// longer take part in reuse matching.let dir = tempfile::tempdir().unwrap();let store = SubagentSessionStore::new(dir.path().to_path_buf());- std::fs::create_dir_all(store.path().parent().unwrap()).unwrap();let legacy = serde_json::json!([{"subagentSessionId": "subsess-legacy","parentSession": "parent-a",@@ -186,7 +185,9 @@ fn legacy_session_with_toolkit_key_still_loads_and_reuses() {"updatedAt": "2026-01-01T00:00:00Z","lastUsedAt": "2026-01-01T00:00:00Z"}]);- std::fs::write(store.path(), legacy.to_string()).unwrap();+ let parsed: Vec<DurableSubagentSession> =+ serde_json::from_value(legacy).expect("legacy toolkit key is ignored");+ store.save(&parsed).unwrap();let sessions = store.load().expect("legacy toolkit key is ignored");assert_eq!(sessions.len(), 1);diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rsindex c90fdc6bf8..5bd20311e7 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs@@ -1,5 +1,4 @@-use std::fs;-use std::path::{Path, PathBuf};+use std::path::PathBuf;use super::types::{DurableSubagentSession, SubagentSessionStore};@@ -8,48 +7,15 @@ impl SubagentSessionStore {Self { workspace_dir }}- pub fn path(&self) -> PathBuf {- self.workspace_dir- .join(".openhuman")- .join("subagent_sessions.json")- }-pub fn load(&self) -> Result<Vec<DurableSubagentSession>, String> {- if let Some(docs) = super::store_documents::current().map_err(|err| format!("{err:#}"))? {- return docs.load().map_err(|err| format!("{err:#}"));- }- load_from_path(&self.path())+ super::store_documents::current(&self.workspace_dir)+ .and_then(|docs| docs.load())+ .map_err(|err| format!("{err:#}"))}pub fn save(&self, sessions: &[DurableSubagentSession]) -> Result<(), String> {- if let Some(docs) = super::store_documents::current().map_err(|err| format!("{err:#}"))? {- return docs.save(sessions).map_err(|err| format!("{err:#}"));- }- save_to_path(&self.path(), sessions)- }-}--pub(crate) fn load_from_path(path: &Path) -> Result<Vec<DurableSubagentSession>, String> {- match fs::read_to_string(path) {- Ok(raw) => serde_json::from_str(&raw)- .map_err(|err| format!("failed to parse subagent session store: {err}")),- Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(Vec::new()),- Err(err) => Err(format!("failed to read subagent session store: {err}")),- }-}--pub(crate) fn save_to_path(path: &Path, sessions: &[DurableSubagentSession]) -> Result<(), String> {- if let Some(parent) = path.parent() {- fs::create_dir_all(parent)- .map_err(|err| format!("failed to create subagent session dir: {err}"))?;+ super::store_documents::current(&self.workspace_dir)+ .and_then(|docs| docs.save(sessions))+ .map_err(|err| format!("{err:#}"))}- let raw = serde_json::to_string_pretty(sessions)- .map_err(|err| format!("failed to encode subagent session store: {err}"))?;- let tmp_path = path.with_extension(format!("json.tmp-{}", uuid::Uuid::new_v4().simple()));- fs::write(&tmp_path, raw)- .map_err(|err| format!("failed to write temporary subagent session store: {err}"))?;- fs::rename(&tmp_path, path).map_err(|err| {- let _ = fs::remove_file(&tmp_path);- format!("failed to commit subagent session store: {err}")- })}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 098785ea25..4e6719d699 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@@ -1,9 +1,9 @@//! Durable sub-agent sessions on the `tinystoragedrivers` document port.//!-//! Used instead of `<workspace>/.openhuman/subagent_sessions.json` when the-//! host configured a storage backend ([`crate::storage`]); `store.rs` picks it-//! per call, so the sessions live under the acting agent's storage scope-//! (`local` on a single-user host).+//! The only store: sessions live under the acting agent's storage scope+//! (`local` on a single-user host) in the backend the host installed+//! ([`crate::storage`]), or the workspace default when none is installed+//! ([`crate::storage::local`]). `store.rs` opens it per call.//!//! # Layout//!@@ -11,8 +11,7 @@//! | --- | --- | --- |//! | `subagent_sessions` | the session id | one [`DurableSubagentSession`] plus `created_at` for ordering |//!-//! The file store loads and saves the whole list, last writer wins. `save`-//! keeps that contract for the callers in `ops.rs`, but writes each session as+//! 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//! limit and two processes only collide on a session they both changed. `save`//! never deletes: `ops.rs` only replaces a session (remove then re-add the same@@ -34,13 +33,14 @@ fn collections() -> Vec<CollectionSpec> {vec![CollectionSpec::new(SESSIONS)]}-/// The document store for this call, when the host configured one.-pub(super) fn current() -> Result<Option<Docs>> {+/// The document store for this call: the installed backend, else the+/// workspace default, in the acting scope.+pub(super) fn current(workspace_dir: &std::path::Path) -> Result<Docs> {#[cfg(test)]if let Some(docs) = TEST_OVERRIDE.with(|slot| slot.borrow().clone()) {- return Ok(Some(docs));+ return Ok(docs);}- Ok(Repo::current(DOMAIN, collections)?.map(Docs))+ Ok(Docs(Repo::current_for(workspace_dir, DOMAIN, collections)?))}/// Runs `f` with `docs` standing in for the installed backend, on this threaddiff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rsindex 39a67e8f00..a95e79f78c 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs@@ -69,16 +69,18 @@ fn scopes_do_not_see_each_others_sessions() {}#[test]-fn the_file_store_still_works_with_no_backend() {+fn the_store_uses_the_workspace_default_with_no_backend_installed() {let dir = tempfile::tempdir().unwrap();let store = SubagentSessionStore::new(dir.path().to_path_buf());assert!(store.load().unwrap().is_empty());store.save(&[session("a")]).unwrap();- assert!(dir+ assert_eq!(store.load().unwrap().len(), 1);+ // No JSON file store: the records are in the workspace's own database.+ assert!(!dir.path().join(".openhuman/subagent_sessions.json").exists());- assert_eq!(store.load().unwrap().len(), 1);+ assert!(dir.path().join("storage").exists());}#[test]