Skip to content

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

fix(runtime): handle missing embed config gracefully

Steven Enamakel8b3be4838357
diff --git a/crates/openhuman-embed/src/runtime/mod.rs b/crates/openhuman-embed/src/runtime/mod.rs
index b454e799a1..0b2cd1a058 100644
--- a/crates/openhuman-embed/src/runtime/mod.rs
+++ b/crates/openhuman-embed/src/runtime/mod.rs
@@ -166,19 +166,20 @@ impl Runtime {
/// agent (any clone of it) is alive.
pub fn agent(&self, spec: AgentSpec) -> Result<Agent, AgentError> {
let id = spec.id().to_string();
- {
- let mut agents = self.agents.lock().unwrap_or_else(|e| e.into_inner());
- agents.retain(|_, weak| weak.strong_count() > 0);
- if agents.contains_key(&id) {
- return Err(AgentError::DuplicateId(id));
- }
+ // Held across `instantiate` (fs layout only, no turn, no await) so a
+ // concurrent `agent()` call for the same id cannot pass the duplicate
+ // check while this one is still being built. Releasing the lock
+ // between the check and the insert let two callers both observe the
+ // id as free and both instantiate, with the second `insert`
+ // silently overwriting the first agent's registry entry.
+ let mut agents = self.agents.lock().unwrap_or_else(|e| e.into_inner());
+ agents.retain(|_, weak| weak.strong_count() > 0);
+ if agents.contains_key(&id) {
+ return Err(AgentError::DuplicateId(id));
}
- let inner = crate::agent::build::instantiate(self, spec)?;
- let inner = Arc::new(inner);
- self.agents
- .lock()
- .unwrap_or_else(|e| e.into_inner())
- .insert(id.clone(), Arc::downgrade(&inner));
+ let inner = Arc::new(crate::agent::build::instantiate(self, spec)?);
+ agents.insert(id.clone(), Arc::downgrade(&inner));
+ drop(agents);
log::debug!("[embed][runtime] agent registered id={id}");
Ok(Agent::from_inner(inner))
}