Skip to content

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

refactor(embed): inline agent admission checks

Steven Enamakelc36a1df9c71a
diff --git a/crates/openhuman-embed/src/runtime/builder_tests.rs b/crates/openhuman-embed/src/runtime/builder_tests.rs
index 72c583d02b..0f7a3225fd 100644
--- a/crates/openhuman-embed/src/runtime/builder_tests.rs
+++ b/crates/openhuman-embed/src/runtime/builder_tests.rs
@@ -14,19 +14,6 @@ fn a_runtime_identifies_as_a_library_host_by_default() {
assert_eq!(RuntimeBuilder::new().host_kind, HostKind::Library);
}
-#[test]
-fn a_retiring_agent_id_is_not_reused_until_cleanup_is_acknowledged() {
- assert!(matches!(
- agent_admission_error("agent", false, true),
- Some(AgentError::CleanupPending)
- ));
- assert_eq!(agent_admission_error("agent", false, false), None);
- assert!(matches!(
- agent_admission_error("agent", true, true),
- Some(AgentError::DuplicateId(id)) if id == "agent"
- ));
-}
-
#[test]
fn inherited_workspace_without_a_host_credential_keeps_installed_session_policy() {
assert_eq!(
diff --git a/crates/openhuman-embed/src/runtime/mod.rs b/crates/openhuman-embed/src/runtime/mod.rs
index 335449902e..f3650b780d 100644
--- a/crates/openhuman-embed/src/runtime/mod.rs
+++ b/crates/openhuman-embed/src/runtime/mod.rs
@@ -362,18 +362,11 @@ impl Runtime {
// 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());
- let cleanup_pending = {
- #[cfg(feature = "mcp")]
- {
- openhuman_core::mcp::host::agent_close_pending(&self.base_config.workspace_dir, &id)
- }
- #[cfg(not(feature = "mcp"))]
- {
- false
- }
- };
- if let Some(error) = agent_admission_error(&id, agents.contains_key(&id), cleanup_pending) {
- return Err(error);
+ 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!(
@@ -638,20 +631,6 @@ impl Runtime {
}
}
-fn agent_admission_error(
- id: &str,
- already_registered: bool,
- cleanup_pending: bool,
-) -> Option<AgentError> {
- if already_registered {
- Some(AgentError::DuplicateId(id.to_owned()))
- } else if cleanup_pending {
- Some(AgentError::CleanupPending)
- } else {
- None
- }
-}
-
impl std::fmt::Debug for Runtime {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Resolved paths and a provider bearer are both in here.