Skip to content

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

refactor(subagent-host): split lifecycle outcome handling into its own module

Steven Enamakel84f71256c461
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index 12a8b612cb..41f3a1e4e6 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -206,9 +206,7 @@ fn host_observer_outcome(mut outcome: SubagentRunOutcome) -> SubagentRunOutcome
outcome
}
-pub(super) fn host_in_flight(
- ctx: &crate::core::runtime::DispatchCtx,
-) -> Arc<AsyncMutex<HashMap<HostLifecycleKey, Arc<HostInFlight>>>> {
+pub(super) fn host_in_flight(ctx: &crate::core::runtime::DispatchCtx) -> Arc<HostInFlightMap> {
crate::core::runtime::slot_for(ctx)
}
@@ -292,13 +290,12 @@ impl OpenHumanSubagentHost {
})
.unwrap_or_else(|| std::path::PathBuf::from(".openhuman/subagent_checkpoints"))
}));
- let dispatch = parent.data.dispatch_ctx();
let lifecycle_key = HostLifecycleKey {
checkpoint_dir: checkpoint_dir.clone(),
task_key: task_key.clone(),
};
let (entry, is_leader) = {
- let mut entries = host_in_flight(&dispatch).lock_owned().await;
+ let mut entries = host_in_flight(&parent.data.dispatch_ctx()).lock_owned().await;
match entries.get(&lifecycle_key) {
Some(entry) => (entry.clone(), false),
None => {
@@ -336,7 +333,7 @@ impl OpenHumanSubagentHost {
))
.await;
entry.complete(result.as_ref().ok().cloned()).await;
- let mut entries = host_in_flight(&dispatch).lock_owned().await;
+ let mut entries = host_in_flight(&parent.data.dispatch_ctx()).lock_owned().await;
if entries
.get(&lifecycle_key)
.is_some_and(|current| Arc::ptr_eq(current, &entry))
@@ -1138,7 +1135,7 @@ impl tinyagents_orchestration::subagent::SubagentPersistence for OpenHumanPersis
#[path = "lifecycle_outcome.rs"]
mod outcome;
-use outcome::host_outcome_to_neutral;
+use outcome::{host_outcome_to_neutral, HostInFlightMap};
fn outcome_to_host(
result: SubagentRunResult,
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs
index e0f802e150..472d5b99f9 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs
@@ -2,6 +2,9 @@
use super::*;
+/// The host's in-flight subagent runs of one agent context.
+pub(super) type HostInFlightMap = AsyncMutex<HashMap<HostLifecycleKey, Arc<HostInFlight>>>;
+
pub(super) fn host_outcome_to_neutral(
outcome: SubagentRunOutcome,
definition: &crate::agent::harness::host_definition::AgentDefinition,