Skip to content

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

refactor(agent): keep sub-agent in-flight dedupe in the agent context's slot (#7032)

oxoxDevef1bfaa3902e
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index ed78d48610..6c886c2b06 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -9,7 +9,7 @@ use std::{
collections::HashMap,
fs::OpenOptions,
path::PathBuf,
- sync::{Arc, Mutex, OnceLock},
+ sync::{Arc, Mutex},
};
use async_trait::async_trait;
@@ -212,11 +212,10 @@ fn host_observer_outcome(mut outcome: SubagentRunOutcome) -> SubagentRunOutcome
outcome
}
-static HOST_IN_FLIGHT: OnceLock<AsyncMutex<HashMap<HostLifecycleKey, Arc<HostInFlight>>>> =
- OnceLock::new();
+type HostInFlightMap = AsyncMutex<HashMap<HostLifecycleKey, Arc<HostInFlight>>>;
-fn host_in_flight() -> &'static AsyncMutex<HashMap<HostLifecycleKey, Arc<HostInFlight>>> {
- HOST_IN_FLIGHT.get_or_init(|| AsyncMutex::new(HashMap::new()))
+fn host_in_flight() -> Arc<HostInFlightMap> {
+ crate::core::runtime::current_slot::<HostInFlightMap>()
}
fn absolute_checkpoint_dir(path: PathBuf) -> PathBuf {
@@ -304,7 +303,7 @@ impl OpenHumanSubagentHost {
task_key: task_key.clone(),
};
let (entry, is_leader) = {
- let mut entries = host_in_flight().lock().await;
+ let mut entries = host_in_flight().lock_owned().await;
match entries.get(&lifecycle_key) {
Some(entry) => (entry.clone(), false),
None => {
@@ -342,7 +341,7 @@ impl OpenHumanSubagentHost {
))
.await;
entry.complete(result.as_ref().ok().cloned()).await;
- let mut entries = host_in_flight().lock().await;
+ let mut entries = host_in_flight().lock_owned().await;
if entries
.get(&lifecycle_key)
.is_some_and(|current| Arc::ptr_eq(current, &entry))