Skip to content

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

test(memory): settle the memory module before asserting a settled answer\n\n`cargo test --lib -- openhuman::memory` fails on this branch, and the\nfailure is not this branch's: two assertions race the module load.\n\nA module is loaded once per process by whichever caller asks first, and\n`modules::ops::state_of` reports `Loading` for the whole of it. Two\ncorrect answers to that transient are indistinguishable from a\nregression. `MemoryProvider::health` returns `degraded("the memory module\nis loading")`, so `bound_driver_status_reports_id_class_contract_and_\ncapabilities` reads "degraded" where it asserts "ready". A handler that\nreaches the driver refuses with "memory is still starting", so\n`search_entities_rpc_rejects_unknown_entity_kind` gets that instead of\n"unknown entity kind: bogus".\n\nBoth pass alone and both fail in the nine-hundred-test filter — with this\nbranch's four new tests skipped, which is what places the fault outside\nthem. The filter is derived from the changed paths, so it is assembled\nonly by a PR that touches memory broadly; that is why the flake surfaces\nhere rather than on main.\n\n`settle_memory_module` awaits the resolution rather than polling\n`state_of`, which is the difference between closing the window and\nnarrowing it: `Ready` and `Failed` are both terminal — tinybus keeps a\nrefused library mapped, so a resolution is never retried — so the state\ncannot return to `Loading` afterwards. The outcome is ignored on purpose,\nbecause a host with no artifact for its platform resolves to `Failed`,\nwhich is settled too. `binding::test_module_config` is the same\nconfiguration the test-build `module_provider` binds through, named so\nthe wait and the binding cannot drift apart.\n\nFilter run: 900 passed, 0 failed, three times over; 899/1 before.\n

Shanu7f12a6b08798
diff --git a/src/openhuman/memory/binding.rs b/src/openhuman/memory/binding.rs
index 1601763ddd..49c329ec30 100644
--- a/src/openhuman/memory/binding.rs
+++ b/src/openhuman/memory/binding.rs
@@ -370,17 +370,20 @@ fn module_provider(
)
}
+/// The configuration every test-build memory binding loads its module through.
+///
+/// Unit tests do not run the full boot sequence that publishes the module
+/// policy. A native module is loaded once per process and therefore captures
+/// the first workspace it receives. Pin every test binding to the same
+/// workspace as the process-global test client so concurrent tests cannot
+/// win module initialization with an unrelated tempdir and split guarded
+/// writes from legacy read-back calls.
+///
+/// Named rather than inlined into [`module_provider`] so a test can await this
+/// module's resolution through the same configuration the binding will use —
+/// see [`crate::openhuman::memory::test_support::settle_memory_module`].
#[cfg(all(feature = "modules", test))]
-fn module_provider(
- _workspace_dir: &Path,
- memory_subdir: &str,
-) -> (Arc<dyn MemoryProvider>, DriverClass) {
- // Unit tests do not run the full boot sequence that publishes the module
- // policy. A native module is loaded once per process and therefore captures
- // the first workspace it receives. Pin every test binding to the same
- // workspace as the process-global test client so concurrent tests cannot
- // win module initialization with an unrelated tempdir and split guarded
- // writes from legacy read-back calls.
+pub(crate) fn test_module_config() -> crate::openhuman::config::Config {
let workspace_dir = crate::openhuman::memory::ops::shared_memory_test_workspace();
let mut config = crate::openhuman::config::Config::default();
config.workspace_dir = workspace_dir.clone();
@@ -394,10 +397,20 @@ fn module_provider(
path: path.to_string_lossy().into_owned(),
});
}
+ config
+}
+
+#[cfg(all(feature = "modules", test))]
+fn module_provider(
+ _workspace_dir: &Path,
+ memory_subdir: &str,
+) -> (Arc<dyn MemoryProvider>, DriverClass) {
(
Arc::new(
- crate::openhuman::modules::memory::ModuleMemoryProvider::new(Arc::new(config))
- .in_subdir(memory_subdir),
+ crate::openhuman::modules::memory::ModuleMemoryProvider::new(Arc::new(
+ test_module_config(),
+ ))
+ .in_subdir(memory_subdir),
),
DriverClass::Module,
)
diff --git a/src/openhuman/memory/ops/provider_tests.rs b/src/openhuman/memory/ops/provider_tests.rs
index 0d3c9f2f18..16ff10512a 100644
--- a/src/openhuman/memory/ops/provider_tests.rs
+++ b/src/openhuman/memory/ops/provider_tests.rs
@@ -20,6 +20,10 @@ async fn status_without_a_context_reports_an_unresolved_slot() {
#[tokio::test]
async fn bound_driver_status_reports_id_class_contract_and_capabilities() {
+ // `health` below is `degraded` for as long as the module is loading, and
+ // the load is process-wide: without this the assertion races whichever
+ // sibling test asked for the module first (openhuman#6172).
+ crate::openhuman::memory::test_support::settle_memory_module().await;
let workspace = tempfile::tempdir().expect("tempdir");
let cfg = crate::openhuman::config::schema::MemorySubsystemConfig::default();
let binding = crate::openhuman::memory::binding::for_workspace(workspace.path(), &cfg)
diff --git a/src/openhuman/memory/test_support/mod.rs b/src/openhuman/memory/test_support/mod.rs
index 1e943a3739..f32a18428d 100644
--- a/src/openhuman/memory/test_support/mod.rs
+++ b/src/openhuman/memory/test_support/mod.rs
@@ -256,3 +256,40 @@ impl tinymemory_api::traits::Memory for RetainingMemory {
pub(crate) fn retaining_memory() -> Arc<dyn tinymemory_api::traits::Memory> {
Arc::new(RetainingMemory::default())
}
+
+/// Wait out any in-flight load of the memory module.
+///
+/// A module is loaded once per process, by whichever caller asks first, and
+/// `modules::ops::state_of` reports `Loading` for the whole of it. Two correct
+/// answers to that transient are indistinguishable from a regression:
+/// `MemoryProvider::health` returns `degraded("the memory module is loading")`,
+/// and a handler that reaches the driver answers "memory is still starting".
+/// A test asserting a settled value therefore races whichever sibling triggered
+/// the load — invisible when it runs alone, and lost about as often as not when
+/// `cargo test --lib -- openhuman::memory` runs nine hundred of them in one
+/// process (openhuman#6172).
+///
+/// Awaiting the resolution is what makes this race-free, where polling
+/// `state_of` would only narrow the window: `Ready` and `Failed` are both
+/// terminal — tinybus keeps a refused library mapped, so a resolution is never
+/// retried — which means the state cannot return to `Loading` after this
+/// returns. The wait is bounded because a caller that gives up leaves the
+/// resolution running rather than cancelling it.
+///
+/// The outcome is deliberately ignored: a host with no artifact for its
+/// platform resolves to `Failed`, which is settled too, and what the caller
+/// asserts about that is the caller's business.
+#[cfg(feature = "modules")]
+pub(crate) async fn settle_memory_module() {
+ let _ = crate::openhuman::modules::ops::ensure_loaded_within(
+ &crate::openhuman::memory::binding::test_module_config(),
+ crate::openhuman::memory::binding::MODULE_ID,
+ Some(std::time::Duration::from_secs(30)),
+ )
+ .await;
+}
+
+/// Without the `modules` feature nothing loads a module, so nothing can be
+/// caught mid-load.
+#[cfg(not(feature = "modules"))]
+pub(crate) async fn settle_memory_module() {}
diff --git a/src/openhuman/memory/tree/retrieval/rpc_tests_part_01_tests.rs b/src/openhuman/memory/tree/retrieval/rpc_tests_part_01_tests.rs
index 3a7db7fa31..23ea50bc6b 100644
--- a/src/openhuman/memory/tree/retrieval/rpc_tests_part_01_tests.rs
+++ b/src/openhuman/memory/tree/retrieval/rpc_tests_part_01_tests.rs
@@ -268,6 +268,10 @@ async fn search_entities_rpc_parses_valid_kinds_list() {
/// index instead.
#[tokio::test]
async fn search_entities_rpc_rejects_unknown_entity_kind() {
+ // The handler reaches the bound driver, which refuses with "memory is
+ // still starting" for as long as the module is loading — a process-wide
+ // transient this assertion would otherwise race (openhuman#6172).
+ crate::openhuman::memory::test_support::settle_memory_module().await;
let (_tmp, cfg) = test_config();
let req = SearchEntitiesRequest {
query: "x".into(),