Skip to content

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

fix(composio): serve module_guard's module storage without the process slot

M3gA-Mind6b304a745640
diff --git a/crates/openhuman-core/src/integrations/composio/module_client.rs b/crates/openhuman-core/src/integrations/composio/module_client.rs
index f7f22220b7..4b31870213 100644
--- a/crates/openhuman-core/src/integrations/composio/module_client.rs
+++ b/crates/openhuman-core/src/integrations/composio/module_client.rs
@@ -314,9 +314,11 @@ pub(crate) static MODULE_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::cons
/// The module lock, and the storage the module keeps its preferences in.
#[cfg(test)]
pub(crate) struct ModuleGuard {
- // Fields drop in order: the previous storage slot comes back before the
- // next test may take the module.
- _storage: crate::storage::test_support::InstalledBackendGuard,
+ // Fields drop in order: the previous module storage comes back before the
+ // next test may take the module. Without the module loader there are no
+ // module calls to serve.
+ #[cfg(feature = "modules")]
+ _storage: crate::modules::storage_host::TestModuleStorage,
_lock: tokio::sync::MutexGuard<'static, ()>,
}
@@ -324,13 +326,15 @@ pub(crate) struct ModuleGuard {
///
/// The module refuses a preference call when the host serves no storage, and
/// a module call carries no workspace for the host to fall back to, so the
-/// guard installs storage as a booted host has it (memory, the one driver
-/// every build has), restored on drop.
+/// guard serves module calls a fresh memory backend, restored on drop. It is
+/// not installed in the process slot: that would make it every concurrent
+/// test's storage (MAIN-57).
#[cfg(test)]
pub(crate) async fn module_guard() -> ModuleGuard {
let lock = module_lock_guard().await;
ModuleGuard {
- _storage: crate::storage::test_support::install_backend_for_test(
+ #[cfg(feature = "modules")]
+ _storage: crate::modules::storage_host::serve_test_module_storage(
crate::storage::test_support::memory_backend(),
),
_lock: lock,
diff --git a/crates/openhuman-core/src/modules/storage_host.rs b/crates/openhuman-core/src/modules/storage_host.rs
index 7e00e71021..d870c81f26 100644
--- a/crates/openhuman-core/src/modules/storage_host.rs
+++ b/crates/openhuman-core/src/modules/storage_host.rs
@@ -576,6 +576,48 @@ pub(crate) fn current_module_scope(
module_scope(tenant.profile.as_deref(), module_id)
}
+/// Storage for module calls in unit tests that hold a module lock (the
+/// connector module's `module_guard`). A module call carries no workspace, so
+/// such a test needs a backend; this one is read only here, so it is never
+/// another test's storage the way an installed process slot is (MAIN-57).
+#[cfg(test)]
+static TEST_MODULE_STORAGE: std::sync::Mutex<Option<Arc<dyn StorageBackend>>> =
+ std::sync::Mutex::new(None);
+
+#[cfg(test)]
+fn test_module_storage() -> Option<Arc<dyn StorageBackend>> {
+ TEST_MODULE_STORAGE
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .clone()
+}
+
+/// Serve `backend` to module calls until the returned guard drops. Hold the
+/// module's test lock for as long as it lives.
+#[cfg(test)]
+pub(crate) fn serve_test_module_storage(backend: Arc<dyn StorageBackend>) -> TestModuleStorage {
+ let previous = TEST_MODULE_STORAGE
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .replace(backend);
+ TestModuleStorage { previous }
+}
+
+/// Restores the previous test module storage on drop.
+#[cfg(test)]
+pub(crate) struct TestModuleStorage {
+ previous: Option<Arc<dyn StorageBackend>>,
+}
+
+#[cfg(test)]
+impl Drop for TestModuleStorage {
+ fn drop(&mut self) {
+ *TEST_MODULE_STORAGE
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner) = self.previous.take();
+ }
+}
+
/// Production wiring: the broker's name owners, the installed backend, the
/// host's scope rule and the compiled grants.
struct Live {
@@ -603,7 +645,10 @@ impl Environment for Live {
// one) wins. An embedder that did not gets the workspace default every
// other store already opens for itself ([`crate::storage::local::backend_for`]),
// so a module is not the one consumer left with no storage.
- crate::storage::installed().or_else(|| {
+ let installed = crate::storage::installed();
+ #[cfg(test)]
+ let installed = installed.or_else(test_module_storage);
+ installed.or_else(|| {
let workspace = crate::core::runtime::DispatchCtx::ambient()
.resolved()?
.workspace_dir()
diff --git a/scripts/ci/process-statics.json b/scripts/ci/process-statics.json
index ed07402fb9..78b00ba65f 100644
--- a/scripts/ci/process-statics.json
+++ b/scripts/ci/process-statics.json
@@ -399,6 +399,16 @@
"reason": "The single tinybus module bus (broker, loader, connection) for the process; tinybus never unloads a module, so there is exactly one. Carries no tenant data: tenant scope is resolved per call by the host callbacks it serves.",
"verification": "modules/runtime_tests.rs: the_module_bus_is_a_singleton_and_serves_proxies"
},
+ {
+ "file": "crates/openhuman-core/src/modules/storage_host.rs",
+ "scope": "",
+ "name": "TEST_MODULE_STORAGE",
+ "type": "std::sync::Mutex<Option<Arc<dyn StorageBackend>>>",
+ "count": 1,
+ "category": "A",
+ "reason": "Test-only (cfg(test)): the backend module calls are served while a unit test holds a module lock (composio module_guard), so that test's module storage is never installed in the process slot, where it would be every concurrent test's storage (MAIN-57). Set and restored only under the module's test lock; no tenant state, not compiled into any shipped build.",
+ "verification": "integrations/composio/ops/scope_prefs_tests.rs: a_saved_pref_survives_a_deferred_legacy_migration"
+ },
{
"file": "crates/openhuman-core/src/modules/wallet_backend.rs",
"scope": "",