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(orchestration): add task ledger for running subagents
Steven Enamakelfe4933dfa169
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents.rsindex 5bcaabdd32..e9e9fadc58 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents.rs@@ -55,6 +55,7 @@ mod resolve;mod roster;mod steering;mod task_ledger;+mod task_ledger_documents;mod wait;#[cfg(test)]diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rsindex 2b502a9318..f861adf9bc 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs@@ -39,18 +39,49 @@ fn default_task_store_workspace() -> PathBuf {.unwrap_or_else(|_| PathBuf::from(".openhuman").join("workspace"))}+/// One cached ledger: a workspace, and under a storage backend the storage+/// scope it was opened for (`None` for the workspace's JSONL file).+type LedgerKey = (PathBuf, Option<String>);+/// Process-wide typed lifecycle ledger for detached sub-agents (issue #4249),-/// one durable store per workspace.-static TASK_STORES: OnceLock<TaskStoreRegistry<PathBuf>> = OnceLock::new();+/// one durable store per workspace (and per storage scope when the host+/// configured a storage backend, where it is a document collection instead of+/// the JSONL file).+static TASK_STORES: OnceLock<TaskStoreRegistry<LedgerKey>> = OnceLock::new();-fn task_stores() -> &'static TaskStoreRegistry<PathBuf> {+fn task_stores() -> &'static TaskStoreRegistry<LedgerKey> {TASK_STORES.get_or_init(|| {- TaskStoreRegistry::new(|workspace_dir: &PathBuf| {+ TaskStoreRegistry::new(|(workspace_dir, scope): &LedgerKey| {+ if scope.is_some() {+ match super::task_ledger_documents::current() {+ Ok(Some(repo)) => return super::task_ledger_documents::open_or_memory(repo),+ Ok(None) => {}+ Err(error) => {+ log::warn!("[running_subagents] task ledger scope unavailable; using memory: {error:#}");+ return Arc::new(InMemoryTaskStore::new());+ }+ }+ }open_jsonl_task_store_or_memory(&task_store_path(workspace_dir))})})}+/// The cache key for this call: the storage scope joins it when a backend is+/// installed, so two agents on one workspace never share a ledger.+fn ledger_key(workspace_dir: &Path) -> Option<LedgerKey> {+ if crate::storage::installed().is_none() {+ return Some((workspace_dir.to_path_buf(), None));+ }+ match crate::storage::current_scope() {+ Ok(scope) => Some((workspace_dir.to_path_buf(), Some(scope.to_string()))),+ Err(error) => {+ log::warn!("[running_subagents] task ledger has no storage scope: {error}");+ None+ }+ }+}+/// The ledger for `workspace_dir`, opening it on first use.////// A poisoned registry lock is degraded to a throwaway in-memory store rather@@ -58,7 +89,9 @@ fn task_stores() -> &'static TaskStoreRegistry<PathBuf> {/// panic in an unrelated task must not turn sub-agent spawning into a second/// panic.pub(crate) fn task_store_for_workspace(workspace_dir: &Path) -> Arc<dyn TaskStore> {- let key = workspace_dir.to_path_buf();+ let Some(key) = ledger_key(workspace_dir) else {+ return Arc::new(InMemoryTaskStore::new());+ };match task_stores().get_or_open(&key) {Ok(store) => store,Err(err) => {diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger_documents.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger_documents.rsindex 12f6dbd3c7..7c74df51ca 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger_documents.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger_documents.rs@@ -29,7 +29,7 @@ use tinyagents_tasks::{InMemoryTaskStore, OrchestrationControlOutcome, OrchestrationTaskFilter,OrchestrationTaskRecord, OrchestrationTaskResult, OrchestrationTaskSpec, TaskStore,};-use tinystoragedrivers::{CollectionSpec, IndexSpec, Precondition, Query};+use tinystoragedrivers::{CollectionSpec, Precondition, Query};use crate::storage::documents::Repo;use crate::storage::DocumentStoreExt;@@ -38,7 +38,7 @@ const TASKS: &str = "orchestration_tasks";const DOMAIN: &str = "running_subagents::task_ledger";fn collections() -> Vec<CollectionSpec> {- vec![CollectionSpec::new(TASKS).index(IndexSpec::new("by_kind", ["kind"]))]+ vec![CollectionSpec::new(TASKS)]}/// The repo for this call, when the host configured a backend.@@ -105,7 +105,6 @@ impl DocumentTaskStore {timeline.clone()};let doc: Value = json!({- "kind": record.spec.kind,"record": record,"history": timeline,});