Skip to content

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

test(mcp): cover agent unavailability during pending module close

Steven Enamakel6abf083d0575
diff --git a/crates/openhuman-core/src/mcp/module_client_tests.rs b/crates/openhuman-core/src/mcp/module_client_tests.rs
index f6d4c9ba5a..95a99d468c 100644
--- a/crates/openhuman-core/src/mcp/module_client_tests.rs
+++ b/crates/openhuman-core/src/mcp/module_client_tests.rs
@@ -12,6 +12,7 @@ struct FakePort {
transform_requests: Arc<Mutex<Vec<tinymcp_bus::TransformTextRequest>>>,
open_started: Arc<Notify>,
close_started: Arc<Notify>,
+ release_close: Arc<Notify>,
call_started: Arc<Notify>,
release_call: Arc<Notify>,
block_first_open: Arc<std::sync::atomic::AtomicBool>,
@@ -67,7 +68,7 @@ impl McpModulePort for FakePort {
.block_first_close
.swap(false, std::sync::atomic::Ordering::SeqCst)
{
- std::future::pending::<()>().await;
+ self.release_close.notified().await;
}
Ok(Some("close-1".to_owned()))
}
@@ -478,6 +479,59 @@ async fn failed_agent_close_stays_retired_and_can_be_retried() {
assert!(McpConfiguredClient::for_config(&config).is_ok());
}
+#[tokio::test]
+async fn agent_id_stays_unavailable_until_its_cached_module_close_is_acknowledged() {
+ let workspace = tempfile::tempdir().expect("workspace");
+ let alpha_dir = workspace.path().join("agents").join("alpha");
+ let beta_dir = workspace.path().join("agents").join("beta");
+ let mut alpha_config = Config::default();
+ alpha_config.workspace_dir = alpha_dir;
+ alpha_config.modules.enabled = true;
+ let mut beta_config = Config::default();
+ beta_config.workspace_dir = beta_dir;
+ beta_config.modules.enabled = true;
+
+ let alpha_port = FakePort::default();
+ alpha_port
+ .block_first_close
+ .store(true, std::sync::atomic::Ordering::SeqCst);
+ let alpha = McpConfiguredClient::install_test_port(&alpha_config, Box::new(alpha_port.clone()))
+ .expect("install alpha client");
+ alpha
+ .call::<bool>(&configured("alpha"), "ConnectedOverview", ())
+ .await
+ .unwrap();
+ let beta = McpConfiguredClient::install_test_port(&beta_config, Box::new(FakePort::default()))
+ .expect("install beta client");
+ beta.call::<bool>(&configured("beta"), "ConnectedOverview", ())
+ .await
+ .unwrap();
+
+ let closing = tokio::spawn(crate::mcp::host::close_agent(workspace.path(), "alpha"));
+ alpha_port.close_started.notified().await;
+ assert!(crate::mcp::host::agent_close_pending(
+ workspace.path(),
+ "alpha"
+ ));
+ assert!(!crate::mcp::host::agent_close_pending(
+ workspace.path(),
+ "beta"
+ ));
+ assert!(matches!(
+ McpConfiguredClient::for_config(&alpha_config),
+ Err(ModuleCallError::Unavailable)
+ ));
+ assert!(McpConfiguredClient::for_config(&beta_config).is_ok());
+
+ alpha_port.release_close.notify_one();
+ assert!(closing.await.unwrap());
+ assert!(!crate::mcp::host::agent_close_pending(
+ workspace.path(),
+ "alpha"
+ ));
+ assert!(McpConfiguredClient::for_config(&alpha_config).is_ok());
+}
+
#[tokio::test]
async fn a_removed_agent_context_cannot_reopen_its_evicted_client() {
use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};