Skip to content

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

test(mcp): cover concurrent workspace opens through the lifecycle gate

Steven Enamakela44fa1fed050
diff --git a/crates/openhuman-core/src/mcp/module_client_tests.rs b/crates/openhuman-core/src/mcp/module_client_tests.rs
index 645f2f5f3d..7471665336 100644
--- a/crates/openhuman-core/src/mcp/module_client_tests.rs
+++ b/crates/openhuman-core/src/mcp/module_client_tests.rs
@@ -532,3 +532,83 @@ async fn non_utf8_workspace_paths_are_rejected_before_opening() {
#[cfg(test)]
#[path = "module_client/cleanup_tests.rs"]
mod cleanup_tests;
+
+/// A port that models TinyMCP's module-wide lifecycle gate: a second
+/// `open_configured` while another workspace's transition is still pending is
+/// refused instead of queued.
+#[derive(Clone, Default)]
+struct SingleTransitionPort {
+ pending: Arc<std::sync::atomic::AtomicBool>,
+}
+
+#[async_trait]
+impl McpModulePort for SingleTransitionPort {
+ async fn open_configured(
+ &self,
+ data_dir: &str,
+ _config: &McpClientConfig,
+ ) -> Result<OpenConfiguredResponse, ModuleCallError> {
+ if self.pending.swap(true, std::sync::atomic::Ordering::SeqCst) {
+ return Err(ModuleCallError::ModuleFault);
+ }
+ tokio::time::sleep(Duration::from_millis(5)).await;
+ Ok(OpenConfiguredResponse {
+ object_path: format!("/workspace{data_dir}"),
+ transition_id: "open".to_owned(),
+ })
+ }
+
+ async fn close(&self, _data_dir: &str) -> Result<Option<String>, ModuleCallError> {
+ Ok(None)
+ }
+
+ async fn transition_status(
+ &self,
+ _transition_id: &str,
+ ) -> Result<TransitionStatus, ModuleCallError> {
+ tokio::time::sleep(Duration::from_millis(5)).await;
+ self.pending
+ .store(false, std::sync::atomic::Ordering::SeqCst);
+ Ok(TransitionStatus::Complete)
+ }
+
+ async fn call_object(
+ &self,
+ _object_path: &str,
+ _member: &str,
+ _args: Value,
+ _confidential: bool,
+ ) -> Result<Value, ModuleCallError> {
+ Ok(Value::Bool(true))
+ }
+
+ async fn prepare_agent_tools(
+ &self,
+ _request: PrepareAgentToolsRequest,
+ ) -> Result<Vec<McpToolPresentation>, ModuleCallError> {
+ Ok(Vec::new())
+ }
+
+ async fn validate_server_arguments(
+ &self,
+ _request: ValidateServerArgumentsRequest,
+ ) -> Result<ServerArgumentsValidation, ModuleCallError> {
+ Err(ModuleCallError::IncompatibleContract)
+ }
+}
+
+#[tokio::test]
+async fn concurrent_workspaces_open_one_at_a_time_through_the_module_lifecycle_gate() {
+ let port = SingleTransitionPort::default();
+ let first = McpConfiguredClient::with_port("/private/a".to_owned(), Box::new(port.clone()));
+ let second = McpConfiguredClient::with_port("/private/b".to_owned(), Box::new(port));
+ let config = configured("server");
+
+ let (a, b) = tokio::join!(
+ first.call::<bool>(&config, "ConnectedOverview", ()),
+ second.call::<bool>(&config, "ConnectedOverview", ()),
+ );
+
+ assert!(a.expect("first workspace opens"));
+ assert!(b.expect("second workspace opens"));
+}