Skip to content

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

refactor(spawn_parallel): delegate worker fan-out to tinyagents orchestration

Steven Enamakelf397c742d255
diff --git a/crates/openhuman-core/src/agent/orchestration/spawn_parallel/dispatch.rs b/crates/openhuman-core/src/agent/orchestration/spawn_parallel/dispatch.rs
index 3099912dc4..e4f2f4e927 100644
--- a/crates/openhuman-core/src/agent/orchestration/spawn_parallel/dispatch.rs
+++ b/crates/openhuman-core/src/agent/orchestration/spawn_parallel/dispatch.rs
@@ -6,6 +6,7 @@ use std::collections::HashMap;
use std::path::Path;
use tinyagents_harness::workspace::WorkspaceIsolation;
+use tinyagents_orchestration::parallel::Worker;
use tinytools::WorkspaceDescriptor;
use tokio::sync::mpsc::Sender;
@@ -145,7 +146,7 @@ pub(crate) async fn stage_spawn_parallel_workers_from_defs(
action_root: Option<&Path>,
parent_workspace_descriptor: Option<&WorkspaceDescriptor>,
parent_call_id: Option<&str>,
-) -> (Vec<SpawnParallelWorker>, Vec<ParallelAgentResult>) {
+) -> (Vec<Worker<SpawnParallelWorker>>, Vec<ParallelAgentResult>) {
let mut immediate_results = Vec::new();
let mut prepared = Vec::new();
@@ -264,14 +265,17 @@ pub(crate) async fn stage_spawn_parallel_workers_from_defs(
parent.session_parent_prefix.as_deref(),
&task_id,
);
- prepared.push(SpawnParallelWorker {
- definition,
+ prepared.push(Worker {
+ id: task_id,
prompt,
- task,
- task_id,
- lineage,
- worktree_path,
- workspace_descriptor: worker_workspace_descriptor,
+ ownership: task.ownership.clone(),
+ payload: SpawnParallelWorker {
+ definition,
+ task,
+ lineage,
+ worktree_path,
+ workspace_descriptor: worker_workspace_descriptor,
+ },
dispatch_mode,
});
}
diff --git a/crates/openhuman-core/src/agent/orchestration/spawn_parallel/types.rs b/crates/openhuman-core/src/agent/orchestration/spawn_parallel/types.rs
index a7a7960714..0bff351a0c 100644
--- a/crates/openhuman-core/src/agent/orchestration/spawn_parallel/types.rs
+++ b/crates/openhuman-core/src/agent/orchestration/spawn_parallel/types.rs
@@ -8,8 +8,6 @@ use tinytools::WorkspaceDescriptor;
use crate::agent::harness::host_definition::AgentDefinition;
-use super::staging::WorkerDispatchMode;
-
/// One worker admitted by the `spawn_parallel_agents` tool.
///
/// This is intentionally a host request contract: its ownership syntax and
@@ -31,18 +29,16 @@ pub(crate) struct ParallelAgentTask {
pub(crate) base_ref: Option<String>,
}
-/// A staged worker with everything the fanout needs: resolved definition,
-/// prompt (with any ownership boundary applied), and worktree placement.
+/// Host payload of a module `Worker`: resolved definition, lineage and worktree
+/// placement. Id, prompt (ownership boundary applied) and dispatch mode live on
+/// the module's `Worker`.
#[derive(Clone)]
pub(crate) struct SpawnParallelWorker {
pub(crate) definition: AgentDefinition,
- pub(crate) prompt: String,
pub(crate) task: ParallelAgentTask,
- pub(crate) task_id: String,
pub(crate) lineage: ParallelAgentLineage,
pub(crate) worktree_path: Option<PathBuf>,
pub(crate) workspace_descriptor: Option<WorkspaceDescriptor>,
- pub(crate) dispatch_mode: WorkerDispatchMode,
}
/// Terminal or suspended lifecycle state projected by one parallel worker.
diff --git a/crates/openhuman-core/src/agent/orchestration/spawn_parallel/workers.rs b/crates/openhuman-core/src/agent/orchestration/spawn_parallel/workers.rs
index 28656d1381..527d42a7f8 100644
--- a/crates/openhuman-core/src/agent/orchestration/spawn_parallel/workers.rs
+++ b/crates/openhuman-core/src/agent/orchestration/spawn_parallel/workers.rs
@@ -1,21 +1,21 @@
-//! 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.
+//! Running the staged workers on the module's [`run`]: the serial
+//! shared-workspace-write fallback and bounded fan-out are tinyagents-owned.
+//! This file keeps only the single-worker execution (`run_subagent` + post-run
+//! worktree status snapshot) and the result projection.
use std::path::PathBuf;
-use tinyagents_graph::parallel::{map_reduce, FailurePolicy, ParallelOptions};
-use tinyagents_harness::{CancellationToken, TinyAgentsError};
+use tinyagents_harness::CancellationToken;
+use tinyagents_orchestration::parallel::{resolve_concurrency, run, Worker};
use crate::agent::subagent_host::{
run_subagent_with_parent, SubagentRunOptions, SubagentRunStatus,
};
-use super::staging::WorkerDispatchMode;
use super::types::{ParallelAgentResult, ParallelAgentStatus, SpawnParallelWorker};
pub(crate) async fn run_spawn_parallel_workers(
- prepared: Vec<SpawnParallelWorker>,
+ prepared: Vec<Worker<SpawnParallelWorker>>,
action_root: Option<PathBuf>,
cancel: CancellationToken,
run_context: crate::agent::tinyagents::host::OpenHumanRunContext,
@@ -23,103 +23,45 @@ pub(crate) async fn run_spawn_parallel_workers(
crate::agent::tinyagents::host::OpenHumanRunContext,
>,
) -> 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(),
- run_context.child(),
- live_parent,
- )
- .await,
- );
- }
- return Ok(results);
- }
-
- let max_concurrency = prepared.len().max(1);
- let action_root_for_workers = action_root.clone();
- let run_context_for_workers = run_context.clone();
+ let concurrency = resolve_concurrency(0, prepared.len());
tracing::debug!(
target: "orchestration",
- workers = n,
- max_concurrency,
- "[orchestration] running parallel fan-out on tinyagents map_reduce (spawn_parallel_agents)"
+ workers = prepared.len(),
+ concurrency,
+ "[orchestration] running spawn_parallel_agents on tinyagents-orchestration parallel::run"
);
- 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();
- let run_context = run_context_for_workers.child();
- async move { Ok(run_one_parallel_task(worker, repo_root, run_context, live_parent).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)
+ run(
+ prepared,
+ concurrency,
+ cancel,
+ |_| run_context.child(),
+ |worker, child_context| {
+ run_one_parallel_task(worker, action_root.clone(), child_context, live_parent)
+ },
+ )
+ .await
}
async fn run_one_parallel_task(
- worker: SpawnParallelWorker,
+ worker: Worker<SpawnParallelWorker>,
repo_root: Option<PathBuf>,
run_context: crate::agent::tinyagents::host::OpenHumanRunContext,
live_parent: &tinyagents_harness::context::RunContext<
crate::agent::tinyagents::host::OpenHumanRunContext,
>,
) -> ParallelAgentResult {
- let SpawnParallelWorker {
- definition,
+ let Worker {
+ id: task_id,
prompt,
- task,
- task_id,
- lineage,
- worktree_path,
- workspace_descriptor,
- dispatch_mode: _,
+ payload:
+ SpawnParallelWorker {
+ definition,
+ task,
+ lineage,
+ worktree_path,
+ workspace_descriptor,
+ },
+ ..
} = worker;
let started = std::time::Instant::now();
tracing::debug!(