Skip to content

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

fix(agent): check pending mcp cleanup after config resolution

Steven Enamakel3ddd32d8676f
diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rs
index cfc609e42f..7509a18cff 100644
--- a/crates/openhuman-embed/src/agent/build.rs
+++ b/crates/openhuman-embed/src/agent/build.rs
@@ -184,6 +184,13 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn
// moved `config_path` would silently point this agent at another.
config.config_path = base.config_path.clone();
}
+ // Runtime::agent holds the agent-map lock across instantiate. Check the
+ // final workspace (after the config escape hatch) before creating any
+ // directories, so a new agent cannot reuse an id whose old MCP service
+ // still awaits close acknowledgment.
+ if openhuman_core::mcp::host::agent_close_pending(&config.workspace_dir, &id) {
+ return Err(AgentError::CleanupPending);
+ }
if host_only {
// After the escape hatch, so it cannot loosen either.
Access::readonly().apply(&mut config);
diff --git a/crates/openhuman-embed/src/runtime/mod.rs b/crates/openhuman-embed/src/runtime/mod.rs
index f3650b780d..253444024a 100644
--- a/crates/openhuman-embed/src/runtime/mod.rs
+++ b/crates/openhuman-embed/src/runtime/mod.rs
@@ -365,9 +365,6 @@ impl Runtime {
if agents.contains_key(&id) {
return Err(AgentError::DuplicateId(id));
}
- if openhuman_core::mcp::host::agent_close_pending(&self.base_config.workspace_dir, &id) {
- return Err(AgentError::CleanupPending);
- }
if agents.len() >= self.max_agents {
log::warn!(
"[embed][runtime] agent refused id={id}: {} live agents is the limit",