Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(agent): handle missing runtime channel in parallel graph workers

Steven Enamakel7208b21d6944
diff --git a/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/workers.rs b/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/workers.rs
new file mode 100644
index 0000000000..11fdf0c925
--- /dev/null
+++ b/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/workers.rs
@@ -0,0 +1,225 @@
+//! Running the staged workers: the serial shared-workspace-write fallback,
+//! the bounded `map_reduce` parallel fanout, and the single-worker execution
+//! (`run_subagent` + post-run worktree status snapshot) both paths share.
+
+use std::path::PathBuf;
+
+use tinyagents_graph::parallel::{map_reduce, FailurePolicy, ParallelOptions};
+use tinyagents_harness::{CancellationToken, TinyAgentsError};
+
+use crate::agent::harness::subagent_runner::{run_subagent, SubagentRunOptions};
+
+use super::staging::WorkerDispatchMode;
+use super::types::{ParallelAgentResult, SpawnParallelWorker};
+
+pub(crate) async fn run_spawn_parallel_workers(
+ prepared: Vec<SpawnParallelWorker>,
+ action_root: Option<PathBuf>,
+ cancel: CancellationToken,
+) -> tinyagents_harness::Result<Vec<ParallelAgentResult>> {
+ let n = prepared.len();
+ let serial_write_count = prepared
+ .iter()
+ .filter(|worker| {
+ matches!(
+ worker.dispatch_mode,
+ WorkerDispatchMode::SerialSharedWorkspaceWrite
+ )
+ })
+ .count();
+ if serial_write_count > 0 {
+ tracing::debug!(
+ target: "orchestration",
+ workers = n,
+ serial_write_count,
+ "[orchestration] running serial fallback for shared-workspace write fan-out"
+ );
+ let mut results = Vec::with_capacity(n);
+ for worker in prepared {
+ if cancel.is_cancelled() {
+ tracing::debug!(
+ target: "orchestration",
+ "[orchestration] spawn_parallel serial fan-out cancelled before next worker"
+ );
+ return Err(TinyAgentsError::Cancelled);
+ }
+ results.push(run_one_parallel_task(worker, action_root.clone()).await);
+ }
+ return Ok(results);
+ }
+
+ let max_concurrency = prepared.len().max(1);
+ let action_root_for_workers = action_root.clone();
+ tracing::debug!(
+ target: "orchestration",
+ workers = n,
+ max_concurrency,
+ "[orchestration] running parallel fan-out on tinyagents map_reduce (spawn_parallel_agents)"
+ );
+ let options = ParallelOptions::default()
+ .with_max_concurrency(max_concurrency)
+ .with_failure_policy(FailurePolicy::CollectAll)
+ .with_cancellation(cancel);
+ let outcome = map_reduce(prepared, options, move |_i, worker| {
+ let repo_root = action_root_for_workers.clone();
+ async move { Ok(run_one_parallel_task(worker, repo_root).await) }
+ })
+ .await?;
+
+ let mut results = Vec::with_capacity(n);
+ for item in outcome.outcomes {
+ match item.result {
+ Ok(value) => results.push(value),
+ Err(err) => {
+ return Err(TinyAgentsError::Graph(format!(
+ "spawn_parallel_agents fan-out: worker {} failed: {err}",
+ item.index
+ )));
+ }
+ }
+ }
+ if results.len() != n {
+ return Err(TinyAgentsError::Graph(format!(
+ "spawn_parallel_agents fan-out: expected {n} result(s), got {}",
+ results.len()
+ )));
+ }
+ Ok(results)
+}
+
+async fn run_one_parallel_task(
+ worker: SpawnParallelWorker,
+ repo_root: Option<PathBuf>,
+) -> ParallelAgentResult {
+ let SpawnParallelWorker {
+ definition,
+ prompt,
+ task,
+ task_id,
+ lineage,
+ worktree_path,
+ workspace_descriptor,
+ dispatch_mode: _,
+ } = worker;
+ let started = std::time::Instant::now();
+ tracing::debug!(
+ task_id = %task_id,
+ agent_id = %definition.id,
+ toolkit = task.toolkit.as_deref().unwrap_or(""),
+ context_chars = task.context.as_ref().map(|s| s.chars().count()).unwrap_or(0),
+ prompt_chars = prompt.chars().count(),
+ isolated = worktree_path.is_some(),
+ "[spawn_parallel_agents] task_start"
+ );
+ let worktree_action_dir = worktree_path.clone().or_else(|| {
+ workspace_descriptor
+ .as_ref()
+ .map(|descriptor| descriptor.root.clone())
+ });
+ let options = SubagentRunOptions {
+ skill_filter_override: None,
+ toolkit_override: task.toolkit.clone(),
+ context: task.context.clone(),
+ model_override: None,
+ task_id: Some(task_id.clone()),
+ worker_thread_id: None,
+ initial_history: None,
+ checkpoint_dir: None,
+ worktree_action_dir,
+ workspace_descriptor,
+ run_queue: None,
+ };
+ let run_result = run_subagent(&definition, &prompt, options).await;
+
+ // After the worker finishes, snapshot the worktree's changed files +
+ // dirty status so the parent can detect cross-worker overlaps and the UI
+ // can surface diff/cleanup actions. Best-effort: a status error degrades
+ // to "no changes recorded" rather than failing the task.
+ let worktree_str = worktree_path
+ .as_ref()
+ .map(|p| p.to_string_lossy().to_string());
+ let (changed_files, dirty_status) = match (&worktree_path, &repo_root) {
+ (Some(wt), Some(root)) => {
+ use crate::agent::orchestration::worktree;
+ match worktree::status(root, wt) {
+ Ok(st) => {
+ tracing::debug!(
+ task_id = %task_id,
+ worktree = %wt.display(),
+ is_dirty = st.is_dirty,
+ changed = st.changed_files.len(),
+ "[spawn_parallel_agents] worktree_post_run_status"
+ );
+ let files = st
+ .changed_files
+ .iter()
+ .map(|p| p.to_string_lossy().to_string())
+ .collect();
+ (files, Some(st.is_dirty))
+ }
+ Err(err) => {
+ tracing::warn!(
+ task_id = %task_id,
+ worktree = %wt.display(),
+ error = %err,
+ "[spawn_parallel_agents] worktree_status_failed"
+ );
+ (Vec::new(), None)
+ }
+ }
+ }
+ _ => (Vec::new(), None),
+ };
+
+ match run_result {
+ Ok(outcome) => {
+ tracing::debug!(
+ task_id = %outcome.task_id,
+ agent_id = %outcome.agent_id,
+ elapsed_ms = outcome.elapsed.as_millis() as u64,
+ iterations = outcome.iterations,
+ output_chars = outcome.output.chars().count(),
+ "[spawn_parallel_agents] task_success"
+ );
+ ParallelAgentResult {
+ task_id: outcome.task_id,
+ agent_id: outcome.agent_id,
+ lineage,
+ success: true,
+ output: Some(outcome.output),
+ error: None,
+ ownership: task.ownership,
+ elapsed_ms: outcome.elapsed.as_millis() as u64,
+ iterations: outcome.iterations as u32,
+ stale_parent_reads: Vec::new(),
+ worktree_path: worktree_str,
+ changed_files,
+ dirty_status,
+ }
+ }
+ Err(err) => {
+ tracing::debug!(
+ task_id = %task_id,
+ agent_id = %definition.id,
+ elapsed_ms = started.elapsed().as_millis() as u64,
+ error = %err,
+ "[spawn_parallel_agents] task_error"
+ );
+ ParallelAgentResult {
+ task_id,
+ agent_id: definition.id,
+ lineage,
+ success: false,
+ output: None,
+ error: Some(err.to_string()),
+ ownership: task.ownership,
+ elapsed_ms: started.elapsed().as_millis() as u64,
+ iterations: 0,
+ stale_parent_reads: Vec::new(),
+ worktree_path: worktree_str,
+ changed_files,
+ dirty_status,
+ }
+ }
+ }
+}
diff --git a/crates/openhuman-core/src/channels/runtime/startup.rs b/crates/openhuman-core/src/channels/runtime/startup.rs
index 2e87abcaaa..e230a6e40c 100644
--- a/crates/openhuman-core/src/channels/runtime/startup.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup.rs
@@ -12,8 +12,11 @@ pub use start_channels::start_channels;
// items reached only through their owning submodule) so the `#[path]` test
// modules below — which share this module's scope via `super::*` — can see
// them exactly as they could when this was one unsplit file.
+#[cfg(test)]
use chat_workload::{resolve_chat_workload, ChatWorkloadResolution};
+#[cfg(any(test, debug_assertions))]
use credentials::{resolve_email_password, resolve_yuanbao_app_secret};
+#[cfg(test)]
use relay::RelayInboundMessageHandler;
#[cfg(test)]
use crate::config::Config;
diff --git a/crates/openhuman-core/src/integrations/composio/client/execute.rs b/crates/openhuman-core/src/integrations/composio/client/execute.rs
index 2f9f031bc8..ad5839ce39 100644
--- a/crates/openhuman-core/src/integrations/composio/client/execute.rs
+++ b/crates/openhuman-core/src/integrations/composio/client/execute.rs
@@ -5,7 +5,7 @@
use std::time::Duration;
use anyhow::Result;
-use serde_json::Value;
+use serde_json::{json, Value};
use super::connections::ComposioClient;
use super::super::types::{ComposioExecuteResponse, ComposioToolsResponse};
diff --git a/crates/openhuman-core/src/modules/memory/documents_tree.rs b/crates/openhuman-core/src/modules/memory/documents_tree.rs
new file mode 100644
index 0000000000..b734702e45
--- /dev/null
+++ b/crates/openhuman-core/src/modules/memory/documents_tree.rs
@@ -0,0 +1,287 @@
+//! `MemoryDocuments` and `MemoryTree` forwarding for [`ModuleMemoryProvider`].
+
+use async_trait::async_trait;
+use tinymemory_api::chunks::Chunk;
+use tinymemory_api::error::MemoryError;
+use tinymemory_api::provider::types::SourceScope;
+use tinymemory_api::provider::{MemoryDocuments, MemoryTree, RootSummary, SummaryContext, SummaryInput, SummaryOutput};
+use tinymemory_api::tree::{IngestRequest, QueryResult, SummaryForest, TreeLeaf, TreeNode, TreeStatus};
+use tinymemory_api::types::{NamespaceDocumentInput, NamespaceRetrievalContext, StoredMemoryDocument};
+use tinymemory_bus::names::methods;
+
+use super::provider::{module_call, ModuleMemoryProvider};
+
+#[async_trait]
+impl MemoryDocuments for ModuleMemoryProvider {
+ async fn put_document(&self, input: NamespaceDocumentInput) -> Result<String, MemoryError> {
+ module_call!(self, "put_document", methods::PUT_DOCUMENT, (input,))
+ }
+ async fn get_document(
+ &self,
+ namespace: &str,
+ key: &str,
+ ) -> Result<Option<StoredMemoryDocument>, MemoryError> {
+ module_call!(
+ self,
+ "get_document",
+ methods::GET_DOCUMENT,
+ (namespace, key)
+ )
+ }
+ async fn list_documents(
+ &self,
+ namespace: Option<&str>,
+ ) -> Result<serde_json::Value, MemoryError> {
+ module_call!(
+ self,
+ "list_documents",
+ methods::LIST_DOCUMENTS,
+ (namespace.map(str::to_string),)
+ )
+ }
+ async fn list_namespaces(&self) -> Result<Vec<String>, MemoryError> {
+ module_call!(self, "list_namespaces", methods::LIST_NAMESPACES, ())
+ }
+ async fn delete_document(
+ &self,
+ namespace: &str,
+ document_id: &str,
+ ) -> Result<serde_json::Value, MemoryError> {
+ module_call!(
+ self,
+ "delete_document",
+ methods::DELETE_DOCUMENT,
+ (namespace, document_id)
+ )
+ }
+ async fn clear_namespace(&self, namespace: &str) -> Result<(), MemoryError> {
+ module_call!(
+ self,
+ "clear_namespace",
+ methods::CLEAR_NAMESPACE,
+ (namespace,)
+ )
+ }
+ async fn query_documents(
+ &self,
+ namespace: &str,
+ query: &str,
+ limit: usize,
+ ) -> Result<NamespaceRetrievalContext, MemoryError> {
+ module_call!(
+ self,
+ "query_documents",
+ methods::QUERY_DOCUMENTS,
+ (namespace, query, limit)
+ )
+ }
+ async fn recall_documents(
+ &self,
+ namespace: &str,
+ limit: usize,
+ ) -> Result<NamespaceRetrievalContext, MemoryError> {
+ module_call!(
+ self,
+ "recall_documents",
+ methods::RECALL_DOCUMENTS,
+ (namespace, limit)
+ )
+ }
+}
+
+#[async_trait]
+impl MemoryTree for ModuleMemoryProvider {
+ async fn append(&self, request: IngestRequest) -> Result<(), MemoryError> {
+ module_call!(self, "append", methods::APPEND, (request,))
+ }
+ async fn query_source(
+ &self,
+ namespace: &str,
+ source_id: &str,
+ limit: usize,
+ scope: Option<&SourceScope>,
+ ) -> Result<Vec<Chunk>, MemoryError> {
+ module_call!(
+ self,
+ "query_source",
+ methods::QUERY_SOURCE,
+ (namespace, source_id, limit, scope.cloned())
+ )
+ }
+ async fn drill_down(&self, namespace: &str, node_id: &str) -> Result<QueryResult, MemoryError> {
+ module_call!(
+ self,
+ "drill_down",
+ methods::DRILL_DOWN,
+ (namespace, node_id)
+ )
+ }
+ async fn seal(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ module_call!(self, "seal", methods::SEAL, (namespace,))
+ }
+ async fn cascade(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ module_call!(self, "cascade", methods::CASCADE, (namespace,))
+ }
+ async fn summary_forest(
+ &self,
+ limit: usize,
+ scope: Option<&SourceScope>,
+ ) -> Result<SummaryForest, MemoryError> {
+ module_call!(
+ self,
+ "summary_forest",
+ methods::SUMMARY_FOREST,
+ (limit, scope)
+ )
+ }
+
+ async fn flush_source_tree(&self, source_scope: &str) -> Result<u64, MemoryError> {
+ module_call!(
+ self,
+ "flush_source_tree",
+ methods::FLUSH_SOURCE_TREE,
+ (source_scope,)
+ )
+ }
+ async fn recent_leaves(
+ &self,
+ limit: usize,
+ scope: Option<&SourceScope>,
+ ) -> Result<Vec<TreeLeaf>, MemoryError> {
+ module_call!(
+ self,
+ "recent_leaves",
+ methods::RECENT_LEAVES,
+ (limit, scope)
+ )
+ }
+ /// The one member here that costs a provider call rather than a store read,
+ /// so it is also the one whose bus deadline could bind. It rides the
+ /// default: the module clamps the fold to the `token_budget` this caller
+ /// supplied, and a summariser that outruns the deadline is the same failure
+ /// a caller must already handle — the contract puts the deterministic
+ /// fallback on the *caller* and states that the driver never substitutes
+ /// one, precisely so a fallback cannot be mistaken for a model's own work
+ /// once it is in the tree. An `Ok` here is therefore always the model's
+ /// text, or empty when there was nothing to fold; a model that errors,
+ /// times out or refuses arrives as `Err`, never as a filled-in summary.
+ async fn summarise(
+ &self,
+ inputs: &[SummaryInput],
+ context: &SummaryContext,
+ ) -> Result<SummaryOutput, MemoryError> {
+ module_call!(self, "summarise", methods::SUMMARISE, (inputs, context))
+ }
+ /// The wire member is `RootSummaries`; the caps are in the signature on
+ /// both sides, so the name carries only what distinguishes the call.
+ async fn root_summaries_with_caps(
+ &self,
+ per_namespace_cap: usize,
+ total_cap: usize,
+ ) -> Result<Vec<RootSummary>, MemoryError> {
+ module_call!(
+ self,
+ "root_summaries_with_caps",
+ methods::ROOT_SUMMARIES,
+ (per_namespace_cap, total_cap)
+ )
+ }
+
+ // ── The runtime-tree and flavour doors ──────────────────────────────────
+ //
+ // The seven below are named through `tinymemory_bus::names::methods`
+ // rather than as string literals, unlike their neighbours above. The
+ // failure a literal invites is precisely the one this family is prone to:
+ // a member the pinned artifact does not serve answers `Unsupported` at run
+ // time, so a mistyped wire name is indistinguishable from a stale pin, and
+ // both look like "the module is old". The constants make the typo a
+ // compile error and leave `Unsupported` meaning only what it should.
+ //
+ // Every one of them is **defaulted** on the trait, which is what makes
+ // forwarding them mandatory rather than optional: an override that is
+ // missing here does not fail to compile, it silently inherits
+ // `Err(Unsupported)` and the driver underneath is never asked.
+
+ async fn runtime_buffer_write(
+ &self,
+ namespace: &str,
+ content: &str,
+ timestamp: chrono::DateTime<chrono::Utc>,
+ metadata: Option<serde_json::Value>,
+ ) -> Result<String, MemoryError> {
+ module_call!(
+ self,
+ "runtime_buffer_write",
+ methods::RUNTIME_BUFFER_WRITE,
+ (namespace, content, timestamp, metadata)
+ )
+ }
+
+ async fn runtime_read_node(
+ &self,
+ namespace: &str,
+ node_id: &str,
+ ) -> Result<Option<TreeNode>, MemoryError> {
+ module_call!(
+ self,
+ "runtime_read_node",
+ methods::RUNTIME_READ_NODE,
+ (namespace, node_id)
+ )
+ }
+
+ async fn runtime_read_children(
+ &self,
+ namespace: &str,
+ parent_id: &str,
+ ) -> Result<Vec<TreeNode>, MemoryError> {
+ module_call!(
+ self,
+ "runtime_read_children",
+ methods::RUNTIME_READ_CHILDREN,
+ (namespace, parent_id)
+ )
+ }
+
+ async fn runtime_tree_status(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ module_call!(
+ self,
+ "runtime_tree_status",
+ methods::RUNTIME_TREE_STATUS,
+ (namespace,)
+ )
+ }
+
+ /// Long-running on [`Self::summarise`]'s terms — the fold is one provider
+ /// call per hour group drained, plus the propagation above them — and it
+ /// rides the default deadline for the same reason: the module clamps each
+ /// fold to the level's own token budget, and a summariser that outruns the
+ /// deadline is the failure every caller of this surface already handles.
+ async fn runtime_summarize(
+ &self,
+ namespace: &str,
+ timestamp: chrono::DateTime<chrono::Utc>,
+ ) -> Result<Option<TreeNode>, MemoryError> {
+ module_call!(
+ self,
+ "runtime_summarize",
+ methods::RUNTIME_SUMMARIZE,
+ (namespace, timestamp)
+ )
+ }
+
+ /// As [`Self::runtime_summarize`], over every level of the tree at once.
+ async fn runtime_rebuild(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ module_call!(
+ self,
+ "runtime_rebuild",
+ methods::RUNTIME_REBUILD,
+ (namespace,)
+ )
+ }
+
+ async fn flavour_profile(&self, scope: &str) -> Result<Option<String>, MemoryError> {
+ module_call!(self, "flavour_profile", methods::FLAVOUR_PROFILE, (scope,))
+ }
+}
+
diff --git a/crates/openhuman-core/src/modules/memory/provider.rs b/crates/openhuman-core/src/modules/memory/provider.rs
index b590f1611a..b1e0904405 100644
--- a/crates/openhuman-core/src/modules/memory/provider.rs
+++ b/crates/openhuman-core/src/modules/memory/provider.rs
@@ -452,7 +452,7 @@ impl ModuleMemoryProvider {
///
/// Uses the shared table so the host and the module cannot disagree about what a
/// name means. An unrecognised name becomes `Other`, never `Invalid`.
-fn from_bus(error: &tinybus::Error) -> MemoryError {
+pub(super) fn from_bus(error: &tinybus::Error) -> MemoryError {
wire::from_wire(error.wire_name(), &error.to_string())
}