Skip to content

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

fix(subagent_host): make staging policy thread-safe and adapt to async API

Steven Enamakel994ed00901b3
diff --git a/crates/openhuman-core/src/agent/orchestration/spawn_parallel/staging.rs b/crates/openhuman-core/src/agent/orchestration/spawn_parallel/staging.rs
index 235628e19a..3e9fae9dae 100644
--- a/crates/openhuman-core/src/agent/orchestration/spawn_parallel/staging.rs
+++ b/crates/openhuman-core/src/agent/orchestration/spawn_parallel/staging.rs
@@ -13,7 +13,7 @@
use std::collections::HashMap;
use std::path::PathBuf;
-use std::cell::RefCell;
+use std::sync::Mutex;
use tinyagents_graph::parallel::{parse_relative_claim_paths, ClaimConflict, ClaimPathError};
use tinyagents_orchestration::parallel::WorkerDispatchMode;
@@ -234,7 +234,7 @@ struct AdmitPayload {
struct SpawnParallelPolicy<'a> {
parent: &'a ParentExecutionContext,
/// Rejection kind per input index (the module carries only the sentence).
- kinds: RefCell<HashMap<usize, ParallelTaskRejectionKind>>,
+ kinds: Mutex<HashMap<usize, ParallelTaskRejectionKind>>,
}
impl SpawnParallelPolicy<'_> {
@@ -244,7 +244,10 @@ impl SpawnParallelPolicy<'_> {
kind: ParallelTaskRejectionKind,
message: String,
) -> AdmissionVerdict {
- self.kinds.borrow_mut().insert(index, kind);
+ self.kinds
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .insert(index, kind);
AdmissionVerdict::Reject(message)
}
}
@@ -319,10 +322,13 @@ pub(crate) fn prepare_spawn_parallel_tasks_from_defs(
);
let policy = SpawnParallelPolicy {
parent,
- kinds: RefCell::new(HashMap::new()),
+ kinds: Mutex::new(HashMap::new()),
};
let staged = plan.stage(&policy);
- let kinds = policy.kinds.into_inner();
+ let kinds = policy
+ .kinds
+ .into_inner()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
staged
.into_iter()
.enumerate()
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index 679a91cb88..6f23202986 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -369,7 +369,8 @@ impl OpenHumanSubagentHost {
})
.map_err(map_lifecycle_error)?;
let request = if continuation {
- SubagentRequest::continue_with_key(task_key.clone(), child, request, input, None)
+ SubagentRequest::continue_with_key(task_key.clone(), child, request, input, None, None)
+ .await
} else {
// `direct_subagent_child` derives the same key for the host's
// durable lookup; this constructor independently proves that the
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
index e4f900d978..5e7303e3e9 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
@@ -21,6 +21,12 @@ fn key() -> SubagentTaskKey {
fn paused_outcome(question: &str, resume: SubagentResume) -> SubagentOutcome {
SubagentOutcome {
task_id: "task".into(),
+ worker_thread_id: None,
+ tier: None,
+ model_override: None,
+ cost_usd: None,
+ cost_source: None,
+ extensions: Default::default(),
output: "partial result".into(),
history: resume.history.clone(),
status: SubagentOutcomeKind::AwaitingInput(SubagentPause {
diff --git a/crates/openhuman-core/src/memory/import.rs b/crates/openhuman-core/src/memory/import.rs
index f6e4ea7f45..83d92477af 100644
--- a/crates/openhuman-core/src/memory/import.rs
+++ b/crates/openhuman-core/src/memory/import.rs
@@ -79,7 +79,7 @@ impl CheckpointStore for FileCheckpointStore {
.unwrap_or_default()
}
- fn save(&self, file: &ImportFile) -> Result<(), String> {
+ fn save(&self, file: &ImportFile) -> std::result::Result<(), String> {
super::state_store::save(&self.workspace_dir, STATE, file)
.map_err(|error| error.to_string())
}
diff --git a/crates/openhuman-core/src/storage/import/sessions.rs b/crates/openhuman-core/src/storage/import/sessions.rs
index f36af3d31f..df363e67b0 100644
--- a/crates/openhuman-core/src/storage/import/sessions.rs
+++ b/crates/openhuman-core/src/storage/import/sessions.rs
@@ -100,7 +100,6 @@ fn import(backend: &Arc<dyn StorageBackend>, config: &Config) -> Result<Outcome>
report.members,
report.tasks,
report.tool_effects,
- report.entries,
] {
found += counts.read;
written += counts.imported;