Skip to content

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

chore: migrate test mutexes from std to tokio

Steven Enamakel9b405411c5cd
diff --git a/crates/openhuman-core/src/agent/artifacts/ops_tests.rs b/crates/openhuman-core/src/agent/artifacts/ops_tests.rs
index f9b7edc7cf..904d54bcd9 100644
--- a/crates/openhuman-core/src/agent/artifacts/ops_tests.rs
+++ b/crates/openhuman-core/src/agent/artifacts/ops_tests.rs
@@ -321,8 +321,7 @@ struct DefaultFilesDir {
impl DefaultFilesDir {
fn under(tmp: &TempDir) -> Self {
let lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let previous = std::env::var_os("OPENHUMAN_PROJECTS_DIR");
let projects = tmp.path().join("projects");
unsafe {
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs
index 0f1320fb3c..c4955208e3 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs
@@ -7,8 +7,7 @@ use std::sync::MutexGuard;
/// mutex wouldn't prevent that cross-module race.
fn test_guard() -> MutexGuard<'static, ()> {
crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner())
+ .blocking_lock()
}
fn c(task: &str, agent: &str, summary: &str) -> CompletedBackgroundAgent {
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
index 9c99ac6757..afd72bfb83 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
@@ -34,11 +34,16 @@ mod wire_tests;
/// destructive `cancel_all` path is also reachable from the `threads::ops`
/// tests — those hold the same lock, so this prevents a purge there from
/// wiping entries a test here is mid-way through.
-fn test_guard() -> MutexGuard<'static, ()> {
+fn test_guard() -> tokio::sync::MutexGuard<'static, ()> {
// Recover from a poisoned guard so one panicking test doesn't cascade.
crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner())
+ .blocking_lock()
+}
+
+async fn test_guard_async() -> tokio::sync::MutexGuard<'static, ()> {
+ // Recover from a poisoned guard so one panicking test doesn't cascade.
+ crate::config::TEST_ENV_LOCK
+ .lock().await
}
fn dummy_abort() -> AbortHandle {
@@ -102,7 +107,7 @@ fn register_test_with_thread(
#[tokio::test]
async fn task_store_records_spawn_complete_and_cancel() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
// Spawn → the ledger sees a running SubAgent task scoped to the parent.
let tx = register_test("task-ledger-1", "ledger-parent", run_queue());
let running = task_records(Some("ledger-parent"));
@@ -154,7 +159,7 @@ async fn task_store_records_spawn_complete_and_cancel() {
#[tokio::test]
async fn task_id_for_session_enforces_parent_ownership() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let rq = run_queue();
let (tx, rx) = status_channel();
register(
@@ -187,7 +192,7 @@ async fn task_id_for_session_enforces_parent_ownership() {
#[tokio::test]
async fn snapshot_and_block_scope_to_parent_and_reflect_live_status() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let (tx_a, rx_a) = status_channel();
register(
"task-fleet-a".into(),
@@ -356,7 +361,7 @@ async fn snapshot_and_block_scope_to_parent_and_reflect_live_status() {
#[tokio::test]
async fn resume_ref_for_task_includes_resume_fields_and_enforces_ownership() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let (tx, rx) = status_channel();
register(
"task-resume".into(),
@@ -392,7 +397,7 @@ async fn resume_ref_for_task_includes_resume_fields_and_enforces_ownership() {
#[tokio::test]
async fn task_id_for_session_prefers_live_task_over_terminal_task() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let (old_tx, old_rx) = status_channel();
register(
"task-old".into(),
@@ -434,7 +439,7 @@ async fn task_id_for_session_prefers_live_task_over_terminal_task() {
#[tokio::test]
async fn wait_returns_completion_once_published() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let rq = run_queue();
let tx = register_test("task-wait", "session-A", rq);
@@ -467,7 +472,7 @@ async fn wait_returns_completion_once_published() {
#[tokio::test]
async fn wait_times_out_and_leaves_entry_intact() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let rq = run_queue();
let _tx = register_test("task-slow", "session-A", rq);
@@ -493,7 +498,7 @@ async fn wait_times_out_and_leaves_entry_intact() {
#[tokio::test]
async fn cancel_for_thread_aborts_only_matching_entries() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let rq = run_queue();
let _a = register_test_with_thread("task-tA-1", "session-A", Some("thread-X"), rq.clone());
let _b = register_test_with_thread("task-tA-2", "session-A", Some("thread-X"), rq.clone());
@@ -534,7 +539,7 @@ async fn cancel_for_thread_aborts_only_matching_entries() {
#[tokio::test]
async fn cancel_by_task_returns_metadata_and_removes_entry() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let rq = run_queue();
let _tx = register_test_with_thread("task-cbt", "session-Z", Some("thread-cbt"), rq.clone());
let task_id = TaskId::new("task-cbt");
@@ -569,7 +574,7 @@ async fn cancel_by_task_returns_metadata_and_removes_entry() {
/// the user is still a real cancel.
#[tokio::test]
async fn cancel_by_task_flags_a_run_that_already_finished() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let cases = [
(
"task-cbt-done",
@@ -604,7 +609,7 @@ async fn cancel_by_task_flags_a_run_that_already_finished() {
#[tokio::test]
async fn cancel_all_clears_everything() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let rq = run_queue();
let _a = register_test_with_thread("task-all-1", "session-A", Some("thread-1"), rq.clone());
// Headless (no parent thread) — aborted, but contributes no thread id.
@@ -634,7 +639,7 @@ async fn cancel_all_clears_everything() {
#[tokio::test]
async fn stop_for_thread_aborts_the_threads_running_children() {
- let _guard = test_guard();
+ let _guard = test_guard_async().await;
let rq = run_queue();
// A real detached child that would otherwise run forever — the shape the
// Stop button used to leave behind.
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_control_tests.rs b/crates/openhuman-core/src/agent/orchestration/subagent_control_tests.rs
index fcf40a785a..bf1f3242d1 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_control_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_control_tests.rs
@@ -28,8 +28,7 @@ fn require_str_rejects_blank_and_missing() {
#[tokio::test]
async fn cancel_unknown_task_is_a_noop_false() {
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let mut params = Map::new();
params.insert("taskId".into(), json!("sub-does-not-exist"));
let out = handle_subagent_cancel(params).await.expect("handler ok");
@@ -63,8 +62,7 @@ async fn cancel_of_a_finished_run_reports_its_outcome_and_rewrites_nothing() {
use tinyagents_orchestration::subagent::DetachedSubagentStatus;
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("tempdir");
// Snapshot the durable session store before and after: a real cancel
// would `mark_failed` the session and rewrite this file.
@@ -120,8 +118,7 @@ async fn cancel_of_a_finished_run_reports_its_outcome_and_rewrites_nothing() {
#[tokio::test]
async fn steer_unknown_task_is_a_noop_false() {
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let mut params = Map::new();
params.insert("taskId".into(), json!("sub-does-not-exist"));
params.insert("message".into(), json!("redirect"));
diff --git a/crates/openhuman-core/src/agent/orchestration/worktree_schemas_tests.rs b/crates/openhuman-core/src/agent/orchestration/worktree_schemas_tests.rs
index e21aa71d85..93eaaa86ba 100644
--- a/crates/openhuman-core/src/agent/orchestration/worktree_schemas_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/worktree_schemas_tests.rs
@@ -81,8 +81,7 @@ fn list_view_surfaces_managed_worktree() {
#[tokio::test]
async fn handle_list_degrades_for_non_git_action_dir() {
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = tempfile::tempdir().unwrap();
let action_dir = tmp.path().join("actions");
std::fs::create_dir_all(&action_dir).unwrap();
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs
index 4d8c262254..2d0de3cfca 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs
@@ -331,7 +331,7 @@ async fn require_approval_never_silently_allows_a_plain_tool() {
#[cfg(feature = "modules")]
#[tokio::test]
async fn desktop_default_skips_channel_and_external_approval_parks() {
- let _guard = crate::config::TEST_ENV_LOCK.lock().unwrap();
+ let _guard = crate::config::TEST_ENV_LOCK.lock().await;
let previous = std::env::var_os("OPENHUMAN_WORKSPACE");
let temp = tempfile::tempdir().unwrap();
std::fs::write(
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_approval_guard_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_approval_guard_tests.rs
index 711fa51856..2f535e06da 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_approval_guard_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_approval_guard_tests.rs
@@ -42,7 +42,7 @@ fn desktop_external_effect_keeps_metadata_but_skips_approval_when_disabled() {
#[cfg(feature = "modules")]
async fn desktop_external_effect_inner() {
- let _guard = crate::config::TEST_ENV_LOCK.lock().unwrap();
+ let _guard = crate::config::TEST_ENV_LOCK.lock().await;
let previous = std::env::var_os("OPENHUMAN_WORKSPACE");
let temp = tempfile::tempdir().unwrap();
std::fs::write(
diff --git a/crates/openhuman-core/src/agent/tools/run_workflow_tests.rs b/crates/openhuman-core/src/agent/tools/run_workflow_tests.rs
index 17e5b51bdf..fd7c5892f5 100644
--- a/crates/openhuman-core/src/agent/tools/run_workflow_tests.rs
+++ b/crates/openhuman-core/src/agent/tools/run_workflow_tests.rs
@@ -75,14 +75,14 @@ fn reentrancy_key_distinguishes_inputs() {
// under cargo's parallel runner. The RAII `AwaitGuard` frees its slot + key
// on drop, so these leave no residue (unlike the spawn backstop, which is
// monotonic by design — see its test).
-fn guard_serial() -> &'static std::sync::Mutex<()> {
- static L: std::sync::OnceLock<std::sync::Mutex<()>> = std::sync::OnceLock::new();
- L.get_or_init(|| std::sync::Mutex::new(()))
+fn guard_serial() -> &'static tokio::sync::Mutex<()> {
+ static L: std::sync::OnceLock<tokio::sync::Mutex<()>> = std::sync::OnceLock::new();
+ L.get_or_init(|| tokio::sync::Mutex::new(()))
}
#[test]
fn acquire_await_rejects_the_same_key_reentrantly() {
- let _s = guard_serial().lock().unwrap();
+ let _s = guard_serial().blocking_lock();
let key = "reentry-test\u{1}null".to_string();
let held = super::guard::acquire_await(key.clone()).expect("first acquire");
let again = super::guard::acquire_await(key.clone());
@@ -94,7 +94,7 @@ fn acquire_await_rejects_the_same_key_reentrantly() {
#[test]
fn acquire_await_caps_concurrent_awaits() {
- let _s = guard_serial().lock().unwrap();
+ let _s = guard_serial().blocking_lock();
// MAX_ACTIVE_AWAITS is 8; hold 8 distinct keys, then the 9th must reject.
let mut held = Vec::new();
for i in 0..8 {
@@ -118,7 +118,7 @@ async fn unknown_workflow_id_does_not_burn_a_spawn_slot() {
// exhaust the 500-spawn budget for legitimate runs. Asserts the counter
// DELTA is zero (the counter is global + monotonic, so absolute value is
// shared with the backstop test — hence the serial lock + delta check).
- let _s = guard_serial().lock().unwrap();
+ let _s = guard_serial().lock().await;
let before = super::guard::total_spawns();
let t = RunWorkflowTool::new();
// wait_seconds: 0 → fire-and-forget path (no await slot taken); the
@@ -145,7 +145,7 @@ async fn unknown_workflow_id_does_not_burn_a_spawn_slot() {
#[test]
fn account_spawn_trips_the_process_backstop() {
- let _s = guard_serial().lock().unwrap();
+ let _s = guard_serial().blocking_lock();
// TOTAL_SPAWN_BACKSTOP is 500 and the counter is process-global +
// monotonic (no reset by design — it's a runaway-loop backstop). Drive
// well past it and assert it trips. NOTE: this permanently trips the
diff --git a/crates/openhuman-core/src/agent/tools/todo_tests.rs b/crates/openhuman-core/src/agent/tools/todo_tests.rs
index cc739a6ef6..5237c4e4f0 100644
--- a/crates/openhuman-core/src/agent/tools/todo_tests.rs
+++ b/crates/openhuman-core/src/agent/tools/todo_tests.rs
@@ -5,7 +5,11 @@ use serde_json::{json, Value};
/// Serialize tests that share the process-global scratch store. Same lock
/// as `todos::ops` — otherwise the two test modules race under `cargo test`'s
/// thread pool.
-fn scratch_lock() -> std::sync::MutexGuard<'static, ()> {
+fn scratch_lock() -> tokio::sync::MutexGuard<'static, ()> {
+ crate::agent::todos::ops::scratch_test_lock()
+}
+
+async fn scratch_lock_async() -> tokio::sync::MutexGuard<'static, ()> {
crate::agent::todos::ops::scratch_test_lock()
}
@@ -30,7 +34,7 @@ fn payload(result: &ToolResult) -> Value {
#[tokio::test]
async fn a_write_replaces_the_whole_list_and_a_read_returns_it() {
- let _guard = scratch_lock();
+ let _guard = scratch_lock_async().await;
let workspace_dir = test_workspace();
reset_scratch(&workspace_dir).await;
let tool = TodoTool::new(workspace_dir.clone());
diff --git a/crates/openhuman-core/src/backend/transport/transport_tests.rs b/crates/openhuman-core/src/backend/transport/transport_tests.rs
index 4f7fc171a5..15c6f962c9 100644
--- a/crates/openhuman-core/src/backend/transport/transport_tests.rs
+++ b/crates/openhuman-core/src/backend/transport/transport_tests.rs
@@ -45,9 +45,9 @@ impl BackendTransport for NamedTransport {
}
/// The global slot is process state; serialise the tests that touch it.
-fn global_lock() -> &'static std::sync::Mutex<()> {
- static LOCK: std::sync::OnceLock<std::sync::Mutex<()>> = std::sync::OnceLock::new();
- LOCK.get_or_init(|| std::sync::Mutex::new(()))
+fn global_lock() -> &'static tokio::sync::Mutex<()> {
+ static LOCK: std::sync::OnceLock<tokio::sync::Mutex<()>> = std::sync::OnceLock::new();
+ LOCK.get_or_init(|| tokio::sync::Mutex::new(()))
}
#[test]
@@ -141,7 +141,7 @@ fn parse_body_text_handles_empty_json_and_plain_text() {
#[test]
fn global_install_replaces_and_clears() {
- let _guard = global_lock().lock().unwrap();
+ let _guard = global_lock().blocking_lock();
clear_backend_transport();
assert!(installed_backend_transport().is_none());
@@ -157,7 +157,7 @@ fn global_install_replaces_and_clears() {
#[test]
fn resolve_prefers_global_over_test_fallback() {
- let _guard = global_lock().lock().unwrap();
+ let _guard = global_lock().blocking_lock();
clear_backend_transport();
// Under cfg(test) the plain transport is the floor, never `Unavailable`.
assert_eq!(resolve_backend_transport().unwrap().name(), "plain-test");
@@ -295,7 +295,7 @@ async fn backend_client_reports_unavailable_when_transport_returns_unavailable()
}
}
- let _guard = global_lock().lock().unwrap();
+ let _guard = global_lock().lock().await;
install_backend_transport(Arc::new(Absent));
let client = crate::backend::BackendClient::new("https://api.example.test").unwrap();
let err = client
diff --git a/crates/openhuman-core/src/channels/bus/delivery_tests.rs b/crates/openhuman-core/src/channels/bus/delivery_tests.rs
index 790ba985ae..ffbd4f8dfe 100644
--- a/crates/openhuman-core/src/channels/bus/delivery_tests.rs
+++ b/crates/openhuman-core/src/channels/bus/delivery_tests.rs
@@ -14,8 +14,7 @@ fn outbound_body_has_stable_idempotency_key() {
#[tokio::test]
async fn sender_methods_report_unavailable_without_a_hosted_session() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|error| error.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("temporary workspace");
let _workspace_env = EnvVarGuard::workspace_unlocked(workspace.path());
let sender = BackendProgressiveSender;
diff --git a/crates/openhuman-core/src/channels/runtime/session_tests.rs b/crates/openhuman-core/src/channels/runtime/session_tests.rs
index fe3fa7439b..ce57938575 100644
--- a/crates/openhuman-core/src/channels/runtime/session_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/session_tests.rs
@@ -4,7 +4,7 @@ use std::sync::Arc;
#[tokio::test]
async fn independent_local_runtime_does_not_need_an_account_session() {
- let _guard = crate::inference::inference_test_guard();
+ let _guard = crate::inference::inference_test_guard_async().await;
let _signed_out = crate::cron::scheduler_gate::SignedOutTestGuard::set(true);
run_in_session(CancellationToken::new(), async { Ok(()) })
.await
@@ -64,8 +64,7 @@ async fn clear_session_invalidates_old_channels_and_opens_a_fresh_generation() {
// Logout resolves the signed-out workspace through HOME. Keep the real
// user profile untouched and restore the process environment on panic too.
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
struct RestoreHome(Option<std::ffi::OsString>);
impl Drop for RestoreHome {
fn drop(&mut self) {
diff --git a/crates/openhuman-core/src/config/app_env_tests.rs b/crates/openhuman-core/src/config/app_env_tests.rs
index c31dcd8148..bafa569287 100644
--- a/crates/openhuman-core/src/config/app_env_tests.rs
+++ b/crates/openhuman-core/src/config/app_env_tests.rs
@@ -15,8 +15,7 @@ fn app_env_from_env_reads_runtime_var() {
// resolving the root openhuman dir. Hold the crate-wide env lock too,
// in the established order (TEST_ENV_LOCK before the backend lock).
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let _guard = env_test_lock();
let prev = std::env::var(APP_ENV_VAR).ok();
std::env::set_var(APP_ENV_VAR, "staging");
@@ -32,8 +31,7 @@ fn app_env_from_env_reads_runtime_var() {
fn app_env_empty_primary_falls_through_to_secondary() {
// Same staging-root hazard as `app_env_from_env_reads_runtime_var`.
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let _guard = env_test_lock();
let prev_p = std::env::var(APP_ENV_VAR).ok();
let prev_s = std::env::var(VITE_APP_ENV_VAR).ok();
diff --git a/crates/openhuman-core/src/config/ops/loader_io_chain_tests.rs b/crates/openhuman-core/src/config/ops/loader_io_chain_tests.rs
index 4f64ae39b5..d7f4874ade 100644
--- a/crates/openhuman-core/src/config/ops/loader_io_chain_tests.rs
+++ b/crates/openhuman-core/src/config/ops/loader_io_chain_tests.rs
@@ -96,8 +96,7 @@ async fn load_config_with_timeout_rejects_directory_config() {
std::fs::create_dir(&config_path).unwrap();
let _g = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let prev = std::env::var("OPENHUMAN_WORKSPACE").ok();
std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path().to_str().unwrap());
diff --git a/crates/openhuman-core/src/config/schema/load_active_user_and_dirs_tests.rs b/crates/openhuman-core/src/config/schema/load_active_user_and_dirs_tests.rs
index 88818adaae..cae31212b0 100644
--- a/crates/openhuman-core/src/config/schema/load_active_user_and_dirs_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load_active_user_and_dirs_tests.rs
@@ -103,8 +103,7 @@ async fn resolve_dirs_uses_active_user_when_present() {
// `resolve_runtime_config_dirs` reads `OPENHUMAN_WORKSPACE`; hold the shared
// env lock and clear it so a sibling test's override cannot leak in.
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let prior_workspace = std::env::var_os("OPENHUMAN_WORKSPACE");
std::env::remove_var("OPENHUMAN_WORKSPACE");
let tmp = tempfile::tempdir().unwrap();
@@ -154,8 +153,7 @@ fn default_root_dir_name_uses_staging_suffix_for_staging_env() {
// stops finding `active_user.toml` once the root becomes `.openhuman-staging`).
// Take the same lock those tests hold.
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let prior = std::env::var(crate::config::app_env::APP_ENV_VAR).ok();
std::env::set_var(crate::config::app_env::APP_ENV_VAR, "staging");
diff --git a/crates/openhuman-core/src/config/schema/load_tests.rs b/crates/openhuman-core/src/config/schema/load_tests.rs
index b04cb82c33..2861edc584 100644
--- a/crates/openhuman-core/src/config/schema/load_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load_tests.rs
@@ -81,7 +81,7 @@ async fn write_file(path: &std::path::Path, contents: &str) {
const CORRUPTED_TOML: &str = "{{{ bad table header\n";
fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner())
+ ENV_LOCK.blocking_lock()
}
async fn load_or_init_for_workspace(root: &std::path::Path) -> Config {
diff --git a/crates/openhuman-core/src/config/schema/proxy_tests.rs b/crates/openhuman-core/src/config/schema/proxy_tests.rs
index 797733e87b..6253d99d03 100644
--- a/crates/openhuman-core/src/config/schema/proxy_tests.rs
+++ b/crates/openhuman-core/src/config/schema/proxy_tests.rs
@@ -423,8 +423,7 @@ fn supported_service_selectors_is_nonempty() {
#[test]
fn apply_and_clear_process_env_follow_the_proxy_scope() {
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let keys = [
"HTTP_PROXY",
"HTTPS_PROXY",
diff --git a/crates/openhuman-core/src/config/schemas_tests.rs b/crates/openhuman-core/src/config/schemas_tests.rs
index b916aead7c..28bdb9dc64 100644
--- a/crates/openhuman-core/src/config/schemas_tests.rs
+++ b/crates/openhuman-core/src/config/schemas_tests.rs
@@ -310,7 +310,7 @@ use crate::config::TEST_ENV_LOCK;
#[tokio::test]
async fn handle_get_autonomy_settings_returns_current_value() {
- let _g = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _g = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().unwrap();
unsafe {
std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path());
@@ -340,7 +340,7 @@ async fn handle_get_autonomy_settings_returns_current_value() {
#[tokio::test]
async fn handle_update_autonomy_settings_rejects_invalid_value() {
- let _g = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _g = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().unwrap();
unsafe {
std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path());
@@ -378,7 +378,7 @@ async fn handle_get_agent_paths_returns_action_workspace_and_projects() {
// the action sandbox / internal workspace paths instead of the hard-coded
// `~/OpenHuman/projects` / `~/.openhuman/workspace` strings that drift
// when an operator sets OPENHUMAN_ACTION_DIR.
- let _g = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _g = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().unwrap();
unsafe {
std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path());
@@ -427,7 +427,7 @@ async fn handle_get_agent_paths_reflects_openhuman_action_dir_env_override() {
// must show that override in the panel. The override is honoured by
// default_action_dir() at Config load time; this test verifies the RPC
// surface forwards the loaded value unchanged.
- let _g = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _g = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().unwrap();
let custom_actions = tmp.path().join("custom-actions-3237");
std::fs::create_dir_all(&custom_actions).expect("create custom action dir");
diff --git a/crates/openhuman-core/src/config/workspace/ops_tests.rs b/crates/openhuman-core/src/config/workspace/ops_tests.rs
index d6cf6fe283..23c05a34c1 100644
--- a/crates/openhuman-core/src/config/workspace/ops_tests.rs
+++ b/crates/openhuman-core/src/config/workspace/ops_tests.rs
@@ -72,7 +72,7 @@ fn bootstrap_files_contain_soul_and_identity() {
#[tokio::test]
async fn init_workspace_creates_dirs_and_files_in_fresh_workspace() {
- let _g = ENV_LOCK.lock().unwrap_or_else(|p| p.into_inner());
+ let _g = ENV_LOCK.lock().await;
let tmp = tempdir().unwrap();
let _env = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -112,7 +112,7 @@ async fn init_workspace_creates_dirs_and_files_in_fresh_workspace() {
#[tokio::test]
async fn init_workspace_reports_existing_entries_on_second_call_without_force() {
- let _g = ENV_LOCK.lock().unwrap_or_else(|p| p.into_inner());
+ let _g = ENV_LOCK.lock().await;
let tmp = tempdir().unwrap();
let _env = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -146,7 +146,7 @@ async fn init_workspace_reports_existing_entries_on_second_call_without_force()
#[tokio::test]
async fn init_workspace_with_force_overwrites_existing_bootstrap_files() {
- let _g = ENV_LOCK.lock().unwrap_or_else(|p| p.into_inner());
+ let _g = ENV_LOCK.lock().await;
let tmp = tempdir().unwrap();
let _env = EnvVarGuard::workspace_unlocked(tmp.path());
diff --git a/crates/openhuman-core/src/core/dispatch_tests.rs b/crates/openhuman-core/src/core/dispatch_tests.rs
index 67bc5a24f6..10a14b6796 100644
--- a/crates/openhuman-core/src/core/dispatch_tests.rs
+++ b/crates/openhuman-core/src/core/dispatch_tests.rs
@@ -67,7 +67,7 @@ async fn dispatch_delegates_to_tier2_for_domain_method() {
// Tier 2 dispatcher handles `openhuman.security_policy_info`, so
// it must succeed and return a policy object.
let workspace = tempfile::tempdir().expect("temporary workspace");
- let _workspace_env = EnvVarGuard::workspace(workspace.path());
+ let _workspace_env = EnvVarGuard::workspace_async(workspace.path()).await;
let out = dispatch(test_state(), "openhuman.security_policy_info", json!({}))
.await
.expect("security_policy_info should route via tier 2");
diff --git a/crates/openhuman-core/src/core/runtime/subscribers_tests.rs b/crates/openhuman-core/src/core/runtime/subscribers_tests.rs
index 3b1a5e608f..8cd56b7726 100644
--- a/crates/openhuman-core/src/core/runtime/subscribers_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/subscribers_tests.rs
@@ -206,7 +206,7 @@ async fn tool_timeout_seeds_on_channelless_core_boot() {
// Clear the operator override behind a panic-safe RAII guard: if any assertion
// below panics, `Drop` still restores the previous value, so sibling tests that
// share `TEST_ENV_LOCK` never inherit the cleared var.
- let _env = EnvVarGuard::locked_unset_many(&["OPENHUMAN_TOOL_TIMEOUT_SECS"]);
+ let _env = EnvVarGuard::locked_unset_many_async(&["OPENHUMAN_TOOL_TIMEOUT_SECS"]).await;
// Distinctive, in-range (1..=3600) value so the assertion can only pass on a
// real seed, never on the default. Channel-less: `channels_config` stays empty,
diff --git a/crates/openhuman-core/src/cron/scheduler_gate/gate_tests.rs b/crates/openhuman-core/src/cron/scheduler_gate/gate_tests.rs
index 2b961c3cfb..80f555cd21 100644
--- a/crates/openhuman-core/src/cron/scheduler_gate/gate_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_gate/gate_tests.rs
@@ -8,16 +8,21 @@ use std::sync::Mutex;
use std::time::Instant;
use tokio::time::{timeout, Duration as TokioDuration};
-static GATE_TEST_LOCK: Mutex<()> = Mutex::new(());
+static GATE_TEST_LOCK: Mutex<()> = tokio::sync::Mutex::const_new(());
-fn lock() -> std::sync::MutexGuard<'static, ()> {
+fn lock() -> tokio::sync::MutexGuard<'static, ()> {
// Tolerate poisoning so a panicking test doesn't block the rest.
- GATE_TEST_LOCK.lock().unwrap_or_else(|p| p.into_inner())
+ GATE_TEST_LOCK.blocking_lock()
+}
+
+async fn lock_async() -> tokio::sync::MutexGuard<'static, ()> {
+ // Tolerate poisoning so a panicking test doesn't block the rest.
+ GATE_TEST_LOCK.lock().await
}
#[tokio::test]
async fn wait_for_capacity_returns_permit_when_gate_uninit() {
- let _g = lock();
+ let _g = lock_async().await;
let permit = wait_for_capacity().await;
assert!(
permit.is_some(),
@@ -38,7 +43,7 @@ async fn wait_for_capacity_returns_permit_when_gate_uninit() {
// jitter under full-suite load cannot flip it; the "must have waited" check
// compares against a 40ms sleep that strictly precedes the release.
async fn second_waiter_blocks_until_first_drops() {
- let _g = lock();
+ let _g = lock_async().await;
let first = wait_for_capacity().await.expect("first permit");
assert_eq!(available_llm_permits(), 0);
@@ -106,7 +111,7 @@ async fn signed_out_is_ignored_when_gate_uninit() {
// flag would let any earlier test that set it (`clear_session`, RPC 401
// dispatch, `SessionExpiredSubscriber`) deadlock every subsequent caller
// of `wait_for_capacity`.
- let _g = lock();
+ let _g = lock_async().await;
if skip_if_gate_initialised("signed_out_is_ignored_when_gate_uninit") {
return;
}
@@ -130,7 +135,7 @@ async fn wait_for_capacity_acquires_immediately_when_signed_out_and_uninit() {
// gate, every subsequent `wait_for_capacity()` polls forever on the
// 60-second `paused_poll_ms` fallback (STATE is None in tests, so
// the fallback is the unconfigured default).
- let _g = lock();
+ let _g = lock_async().await;
if skip_if_gate_initialised("wait_for_capacity_acquires_immediately_when_signed_out_and_uninit")
{
return;
@@ -158,7 +163,7 @@ async fn set_signed_out_is_a_noop_when_gate_uninit() {
// implementations of `set_signed_out` and `is_signed_out` is
// unreachable here. The gate we exercise is exclusively the
// `STATE.get().is_none()` early-return.
- let _g = lock();
+ let _g = lock_async().await;
if skip_if_gate_initialised("set_signed_out_is_a_noop_when_gate_uninit") {
return;
}
@@ -180,7 +185,7 @@ async fn set_signed_out_is_a_noop_when_gate_uninit() {
#[tokio::test]
async fn semaphore_size_is_one() {
- let _g = lock();
+ let _g = lock_async().await;
let p1 = wait_for_capacity().await.expect("first permit");
// Try-acquire must fail while the slot is held.
assert!(
@@ -198,7 +203,7 @@ async fn semaphore_size_is_one() {
/// `resume_notify` must hand back one process-wide instance.
#[tokio::test]
async fn resume_notify_is_a_stable_singleton() {
- let _g = lock();
+ let _g = lock_async().await;
assert!(
Arc::ptr_eq(&resume_notify(), &resume_notify()),
"resume_notify must return one shared instance"
@@ -210,7 +215,7 @@ async fn resume_notify_is_a_stable_singleton() {
/// end-to-end (fire on one handle, wake on another).
#[tokio::test]
async fn resume_notify_wakes_a_parked_waiter() {
- let _g = lock();
+ let _g = lock_async().await;
let waiter = resume_notify();
let parked = tokio::spawn(async move { waiter.notified().await });
// Yield so the spawned task reaches `.notified()` before we fire.
@@ -233,7 +238,7 @@ async fn resume_notify_wakes_a_parked_waiter() {
#[tokio::test]
async fn resume_transitions_fire_the_notify() {
use crate::config::SchedulerGateMode;
- let _g = lock();
+ let _g = lock_async().await;
// Ensure STATE is initialised. `set` is a no-op if an earlier test
// already promoted it — that's fine, we re-drive the transition below.
diff --git a/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs b/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs
index 7e9cb51592..7f05574750 100644
--- a/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs
+++ b/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs
@@ -439,8 +439,7 @@ async fn the_active_workspace_s_outage_is_announced() {
// cleared while this lock is still held. Releasing the lock early would
// let the next test set its own override and have this guard erase it.
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let active = tempfile::TempDir::new().unwrap();
let _guard = EnvVarGuard::workspace_unlocked(active.path());
@@ -467,8 +466,7 @@ async fn a_switched_away_workspace_s_outage_is_not_announced() {
// cleared while this lock is still held. Releasing the lock early would
// let the next test set its own override and have this guard erase it.
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let active = tempfile::TempDir::new().unwrap();
let switched_away = tempfile::TempDir::new().unwrap();
let _guard = EnvVarGuard::workspace_unlocked(active.path());
diff --git a/crates/openhuman-core/src/desktop/provider_surfaces/ops_tests.rs b/crates/openhuman-core/src/desktop/provider_surfaces/ops_tests.rs
index b2f24c4cd1..2a2bfc25b5 100644
--- a/crates/openhuman-core/src/desktop/provider_surfaces/ops_tests.rs
+++ b/crates/openhuman-core/src/desktop/provider_surfaces/ops_tests.rs
@@ -3,7 +3,7 @@ use std::sync::Mutex;
/// Serializes tests that mutate the process-global RESPOND_QUEUE so cargo's
/// default parallel test runner cannot interleave clear/insert/assert cycles.
-static TEST_MUTEX: Mutex<()> = Mutex::new(());
+static TEST_MUTEX: Mutex<()> = tokio::sync::Mutex::const_new(());
fn sample_event(entity_id: &str) -> ProviderEvent {
ProviderEvent {
@@ -25,7 +25,7 @@ fn sample_event(entity_id: &str) -> ProviderEvent {
#[tokio::test]
async fn ingest_event_upserts_queue_item() {
- let _lock = TEST_MUTEX.lock().unwrap_or_else(|p| p.into_inner());
+ let _lock = TEST_MUTEX.lock().await;
store::clear_queue();
let first = ingest_event(sample_event("entity-1")).await.unwrap();
let second = ingest_event(sample_event("entity-1")).await.unwrap();
@@ -46,7 +46,7 @@ async fn ingest_event_upserts_queue_item() {
#[tokio::test]
async fn list_queue_returns_newest_first() {
- let _lock = TEST_MUTEX.lock().unwrap_or_else(|p| p.into_inner());
+ let _lock = TEST_MUTEX.lock().await;
store::clear_queue();
ingest_event(sample_event("entity-1")).await.unwrap();
ingest_event(sample_event("entity-2")).await.unwrap();
diff --git a/crates/openhuman-core/src/flows/ops_agent_binding_tests.rs b/crates/openhuman-core/src/flows/ops_agent_binding_tests.rs
index 3ecd1e825a..9bb5bb004e 100644
--- a/crates/openhuman-core/src/flows/ops_agent_binding_tests.rs
+++ b/crates/openhuman-core/src/flows/ops_agent_binding_tests.rs
@@ -347,7 +347,7 @@ async fn flows_run_fails_cleanly_without_invoking_engine_when_inference_not_read
#[tokio::test]
async fn local_agent_flow_is_ready_without_openhuman_session() {
- let _inference = crate::inference::inference_test_guard();
+ let _inference = crate::inference::inference_test_guard_async().await;
let _signed_out = crate::cron::scheduler_gate::SignedOutTestGuard::set(true);
let tmp = TempDir::new().unwrap();
let mut config = test_config(&tmp);
@@ -369,7 +369,7 @@ async fn local_agent_flow_is_ready_without_openhuman_session() {
#[tokio::test]
async fn claude_agent_flow_readiness_does_not_require_an_openhuman_session() {
- let _inference = crate::inference::inference_test_guard();
+ let _inference = crate::inference::inference_test_guard_async().await;
let _signed_out = crate::cron::scheduler_gate::SignedOutTestGuard::set(true);
// Isolate the caller's session classification from CLI installation/auth
// and provider availability. Layer 1 must still reject managed inference
@@ -435,7 +435,7 @@ fn harness_readiness_uses_runtime_role_and_node_override() {
#[tokio::test]
async fn harness_readiness_checks_session_for_execution_provider() {
- let _inference = crate::inference::inference_test_guard();
+ let _inference = crate::inference::inference_test_guard_async().await;
let _signed_out = crate::cron::scheduler_gate::SignedOutTestGuard::set(true);
let _model =
crate::inference::provider::factory::test_provider_override::install_model(Arc::new(
diff --git a/crates/openhuman-core/src/flows/ops_inference_gate_tests.rs b/crates/openhuman-core/src/flows/ops_inference_gate_tests.rs
index 698869e05c..ec1d7cbf65 100644
--- a/crates/openhuman-core/src/flows/ops_inference_gate_tests.rs
+++ b/crates/openhuman-core/src/flows/ops_inference_gate_tests.rs
@@ -110,7 +110,7 @@ async fn inference_gate_passes_when_model_constructs() {
// network at all. Construction still observes the process-global test
// provider seam, so serialize this probe with tests that install an
// override.
- let _inference = crate::inference::inference_test_guard();
+ let _inference = crate::inference::inference_test_guard_async().await;
let tmp = TempDir::new().unwrap();
let mut config = test_config(&tmp);
config.memory_provider = Some("ollama:llama3".to_string());
@@ -136,7 +136,7 @@ async fn inference_gate_surfaces_construction_error() {
// the gate must surface that failure, naming the offending node.
// Construction must FAIL here, so no test may have the process-global
// `test_provider_override` installed meanwhile; its installers hold this.
- let _inference = crate::inference::inference_test_guard();
+ let _inference = crate::inference::inference_test_guard_async().await;
let tmp = TempDir::new().unwrap();
let mut config = test_config(&tmp);
seed_app_session_for_gate_test(&tmp);
@@ -227,7 +227,7 @@ async fn inference_gate_probes_every_distinct_agent_node_role() {
// incorrectly pass. Both failures must be named.
// Construction must FAIL here, so no test may have the process-global
// `test_provider_override` installed meanwhile; its installers hold this.
- let _inference = crate::inference::inference_test_guard();
+ let _inference = crate::inference::inference_test_guard_async().await;
let tmp = TempDir::new().unwrap();
let mut config = test_config(&tmp);
seed_app_session_for_gate_test(&tmp);
diff --git a/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs b/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs
index 63bb7c5881..9c0f871bc8 100644
--- a/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs
@@ -87,7 +87,7 @@ async fn from_string_external_provider_emits_egress_realpath() {
#[tokio::test]
async fn caller_owned_models_build_without_openhuman_session() {
- let _guard = crate::inference::inference_test_guard();
+ let _guard = crate::inference::inference_test_guard_async().await;
let _signed_out = crate::cron::scheduler_gate::SignedOutTestGuard::set(true);
let dir = tempfile::tempdir().unwrap();
let config = Config {
@@ -132,7 +132,7 @@ async fn caller_owned_models_build_without_openhuman_session() {
}
#[tokio::test]
async fn local_aliases_build_without_a_session_and_preserve_model_ids() {
- let _guard = crate::inference::inference_test_guard();
+ let _guard = crate::inference::inference_test_guard_async().await;
let _signed_out = crate::cron::scheduler_gate::SignedOutTestGuard::set(true);
let config = Config::default();
for (prefix, canonical) in [
diff --git a/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs b/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
index 52d00d7802..ec331d927b 100644
--- a/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
@@ -10,8 +10,7 @@ fn enforce_local_only_inference_errors_on_external_when_local_only() {
// cloud-model construction cannot observe this temporary LocalOnly mode.
let _inference = crate::inference::inference_test_guard();
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
use crate::config::PrivacyMode;
use crate::security::SecurityPolicy;
let ws = std::env::temp_dir().join("openhuman_factory_privacy_test");
@@ -78,7 +77,7 @@ async fn create_chat_model_uses_native_test_override() {
use tinyinference_llm::message::Message;
use tinyinference_llm::model::ModelRequest;
- let _guard = crate::inference::inference_test_guard();
+ let _guard = crate::inference::inference_test_guard_async().await;
// The factory consults this override under cfg(test), so `create_chat_model`
// resolves to the mock without needing configured cloud providers.
@@ -121,7 +120,7 @@ async fn one_shot_chat_models_preserve_factory_temperature_as_request_default()
}
}
- let _guard = crate::inference::inference_test_guard();
+ let _guard = crate::inference::inference_test_guard_async().await;
let seen = Arc::new(Mutex::new(Vec::new()));
let _override = test_provider_override::install_model(Arc::new(TemperatureProbe {
seen: Arc::clone(&seen),
@@ -405,7 +404,7 @@ async fn openhuman_jwt_slug_discloses_pinned_model() {
use crate::security::egress::{EgressDescriptor, EgressReason};
use std::time::Duration;
- let _guard = crate::inference::inference_test_guard();
+ let _guard = crate::inference::inference_test_guard_async().await;
crate::core::bus::init().await.expect("bus init");
let mut rx = crate::core::bus::BUS.get().unwrap().receiver();
@@ -455,7 +454,7 @@ async fn native_claude_turn_routes_disclose_pinned_models() {
use crate::security::egress::EgressDescriptor;
use std::time::Duration;
- let _guard = crate::inference::inference_test_guard();
+ let _guard = crate::inference::inference_test_guard_async().await;
crate::core::bus::init().await.expect("bus init");
let mut rx = crate::core::bus::BUS.get().unwrap().receiver();
diff --git a/crates/openhuman-core/src/inference/tokenjuice/mod_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/mod_tests.rs
index 08706f0d76..fa37f9ea69 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/mod_tests.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/mod_tests.rs
@@ -139,8 +139,7 @@ async fn an_off_profile_still_discloses_a_registered_summary() {
#[tokio::test]
async fn a_module_disabled_in_configuration_discloses_a_wanted_summary() {
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let previous = std::env::var_os("TINYJUICE_TEST_MODULE");
// SAFETY: serialized by TEST_ENV_LOCK; restored below for every exit path.
unsafe { std::env::remove_var("TINYJUICE_TEST_MODULE") };
diff --git a/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs b/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs
index 9a10b7fe2e..feaac308db 100644
--- a/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs
@@ -171,7 +171,7 @@ fn sandbox_unset_leaves_per_action_execute_to_downstream() {
use crate::config::TEST_ENV_LOCK;
// Lock order module -> env, matching the ops tests (no inversion).
let _serialised = super::super::module_client::module_guard().await;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.blocking_lock();
let tmp = tempfile::tempdir().expect("tempdir");
let _workspace_guard = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -206,7 +206,7 @@ fn contract_gate_surfaces_full_contract_then_proceeds_on_retry() {
// the network.
use crate::config::TEST_ENV_LOCK;
use crate::integrations::composio::catalog::{seed_live_catalog_cache, ToolContract};
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.blocking_lock();
let toolkit = "cgateexec";
let slug = "CGATEEXEC_FETCH_ITEMS";
@@ -359,7 +359,7 @@ fn mode_toggle_between_calls_is_observed() {
// that also points it somewhere. Taken before `TEST_ENV_LOCK`, the
// order the ops tests use, so the two never deadlock.
let _serialised = super::super::module_client::module_guard().await;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.blocking_lock();
// ── Backend half ────────────────────────────────────────────
let tmp_backend = tempfile::tempdir().expect("tempdir backend");
@@ -439,7 +439,7 @@ fn deferred_instance_returns_live_config_for_redaction() {
use crate::integrations::composio::catalog::{seed_live_catalog_cache, ToolContract};
// Lock order module -> env, matching the ops tests (no inversion).
let _serialised = super::super::module_client::module_guard().await;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.blocking_lock();
let toolkit = "deferredredact";
let slug = "DEFERREDREDACT_FETCH_ITEMS";
@@ -507,7 +507,7 @@ fn configured_instance_resolves_live_config_not_the_stale_snapshot() {
// `Some(snapshot)` branch, which reloads from `config_path` rather than
// trusting the captured snapshot.
use crate::config::TEST_ENV_LOCK;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.blocking_lock();
let tmp = tempfile::tempdir().expect("tempdir");
diff --git a/crates/openhuman-core/src/integrations/composio/client/network_tests.rs b/crates/openhuman-core/src/integrations/composio/client/network_tests.rs
index d44c535eea..3407b0edfc 100644
--- a/crates/openhuman-core/src/integrations/composio/client/network_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/client/network_tests.rs
@@ -10,8 +10,7 @@ const HTTPS_BASE: &str = "https://backend.composio.dev/api/v3";
/// Run `body` with a runtime proxy config installed, then restore the old one.
fn with_proxy<T>(config: ProxyConfig, body: impl FnOnce() -> T) -> T {
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let previous = runtime_proxy_config();
set_runtime_proxy_config(config);
let result = body();
diff --git a/crates/openhuman-core/src/integrations/composio/client_tests.rs b/crates/openhuman-core/src/integrations/composio/client_tests.rs
index 9325d26b6d..f7784cbd50 100644
--- a/crates/openhuman-core/src/integrations/composio/client_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/client_tests.rs
@@ -539,8 +539,7 @@ async fn direct_reads_go_through_the_hosts_runtime_proxy() {
let _module = module_guard().await;
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = tempfile::tempdir().unwrap();
let config = module_test_config(&tmp);
let (proxy, proxied) = connect_proxy();
diff --git a/crates/openhuman-core/src/integrations/composio/ops_direct_mode_and_error_classification_tests.rs b/crates/openhuman-core/src/integrations/composio/ops_direct_mode_and_error_classification_tests.rs
index f8c825de2a..4e52c83a32 100644
--- a/crates/openhuman-core/src/integrations/composio/ops_direct_mode_and_error_classification_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops_direct_mode_and_error_classification_tests.rs
@@ -5,7 +5,7 @@ async fn composio_set_api_key_rejects_invalid_direct_key_before_persisting() {
use crate::config::TEST_ENV_LOCK;
use crate::security::credentials::get_composio_api_key;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let app = Router::new().route(
"/connected_accounts",
get(|| async {
@@ -43,7 +43,7 @@ async fn composio_set_api_key_validates_candidate_key_even_when_stored_key_exist
use crate::security::credentials::{get_composio_api_key, store_composio_api_key};
use std::sync::{Arc, Mutex};
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let seen_keys = Arc::new(Mutex::new(Vec::<String>::new()));
let app = Router::new()
.route(
diff --git a/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs b/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs
index e309a878d0..a571390011 100644
--- a/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs
@@ -9,12 +9,12 @@ async fn composio_get_user_profile_via_mock_returns_provider_profile() {
// earlier test in the same binary happened to run first.
use crate::config::TEST_ENV_LOCK;
let _cache_guard = cache_guard();
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
// This test mutates BACKEND_URL below via EnvVarGuard, which races with
// openhuman_tinyhumans::backend::url / core::cli_tests tests
// that mutate the same process-global var under the crate-wide lock —
// TEST_ENV_LOCK alone does not serialize against those. Hold both.
- let _backend_env_guard = crate::config::app_env::env_test_lock();
+ let _backend_env_guard = crate::config::app_env::env_test_lock_async().await;
let app = Router::new()
.route(
diff --git a/crates/openhuman-core/src/integrations/composio/tools_direct_mode_routing_tests.rs b/crates/openhuman-core/src/integrations/composio/tools_direct_mode_routing_tests.rs
index 56942c6d1f..c1c6b2155e 100644
--- a/crates/openhuman-core/src/integrations/composio/tools_direct_mode_routing_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools_direct_mode_routing_tests.rs
@@ -83,7 +83,7 @@ async fn list_tools_in_direct_mode_returns_empty_without_hitting_backend() {
// call which reads from disk — see the matching note on
// `execute_tool_per_call_factory_means_no_baked_client`.
use crate::config::TEST_ENV_LOCK;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
let _workspace_guard = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -140,7 +140,7 @@ async fn execute_tool_per_call_factory_means_no_baked_client() {
// `OPENHUMAN_WORKSPACE` at a tempdir, and persist the test's
// `Config` to that tempdir's `config.toml` before invoking the tool.
use crate::config::TEST_ENV_LOCK;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().unwrap();
let _workspace_guard = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -188,7 +188,7 @@ async fn list_toolkits_in_direct_mode_returns_empty_without_hitting_backend() {
// call which reads from disk — see the matching note on
// `execute_tool_per_call_factory_means_no_baked_client`.
use crate::config::TEST_ENV_LOCK;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
let _workspace_guard = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -260,8 +260,8 @@ async fn authorize_in_direct_mode_refuses_with_app_composio_dev_hint() {
// Also hold the composio cache lock so we don't race against ops_tests
// that mutate INTEGRATIONS_CACHE at the same time as we reload config.
let _cache_guard =
- crate::integrations::composio::connected_integrations::composio_cache_test_lock();
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ crate::integrations::composio::connected_integrations::composio_cache_test_lock_async().await;
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
let _workspace_guard = EnvVarGuard::workspace_unlocked(tmp.path());
diff --git a/crates/openhuman-core/src/integrations/composio/tools_metadata_and_sandbox_tests.rs b/crates/openhuman-core/src/integrations/composio/tools_metadata_and_sandbox_tests.rs
index d62b78a442..c9f9538565 100644
--- a/crates/openhuman-core/src/integrations/composio/tools_metadata_and_sandbox_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools_metadata_and_sandbox_tests.rs
@@ -421,7 +421,7 @@ async fn sandbox_read_only_passes_through_read_scope_actions_to_downstream_gates
// config nor races the shared env var against the other
// config-loading composio tests.
use crate::config::TEST_ENV_LOCK;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
let _workspace_guard = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -457,7 +457,7 @@ async fn sandbox_unset_leaves_all_scopes_to_downstream_gates() {
// so this test neither reads the dev's real config nor races the
// shared env var against the other config-loading composio tests.
use crate::config::TEST_ENV_LOCK;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
let _workspace_guard = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -492,7 +492,7 @@ async fn sandbox_sandboxed_mode_does_not_trigger_readonly_gate() {
// config nor races the shared env var against the other
// config-loading composio tests.
use crate::config::TEST_ENV_LOCK;
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
let _workspace_guard = EnvVarGuard::workspace_unlocked(tmp.path());
diff --git a/crates/openhuman-core/src/mcp/audit/schemas_tests.rs b/crates/openhuman-core/src/mcp/audit/schemas_tests.rs
index 1c9cc5a1f4..deef8554d8 100644
--- a/crates/openhuman-core/src/mcp/audit/schemas_tests.rs
+++ b/crates/openhuman-core/src/mcp/audit/schemas_tests.rs
@@ -24,8 +24,7 @@ fn domain_schema_exports_match_internal_controller() {
#[tokio::test]
async fn handle_list_returns_persisted_audit_records() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|err| err.into_inner());
+ .lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
unsafe {
std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path());
diff --git a/crates/openhuman-core/src/mcp/server/tools_tests_tag_and_dispatch_tests.rs b/crates/openhuman-core/src/mcp/server/tools_tests_tag_and_dispatch_tests.rs
index 895d646c87..e575433d70 100644
--- a/crates/openhuman-core/src/mcp/server/tools_tests_tag_and_dispatch_tests.rs
+++ b/crates/openhuman-core/src/mcp/server/tools_tests_tag_and_dispatch_tests.rs
@@ -165,8 +165,7 @@ fn tree_tag_accepts_max_size_tags() {
#[tokio::test]
async fn call_tool_records_write_argument_rejection() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|err| err.into_inner());
+ .lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
unsafe {
std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path());
diff --git a/crates/openhuman-core/src/memory/ops/files_tests.rs b/crates/openhuman-core/src/memory/ops/files_tests.rs
index bcb213f719..14b464dc3e 100644
--- a/crates/openhuman-core/src/memory/ops/files_tests.rs
+++ b/crates/openhuman-core/src/memory/ops/files_tests.rs
@@ -7,8 +7,7 @@ use crate::config::TEST_ENV_LOCK;
#[tokio::test]
async fn write_read_and_list_memory_files_roundtrip() {
let _guard = TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let tmp = TempDir::new().expect("tempdir");
let _workspace = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -62,8 +61,7 @@ async fn write_read_and_list_memory_files_roundtrip() {
#[tokio::test]
async fn list_memory_files_skips_internal_sqlite_artifacts() {
let _guard = TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let tmp = TempDir::new().expect("tempdir");
let _workspace = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -96,8 +94,7 @@ async fn list_memory_files_skips_internal_sqlite_artifacts() {
#[tokio::test]
async fn list_memory_files_rejects_non_directory_target() {
let _guard = TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let tmp = TempDir::new().expect("tempdir");
let _workspace = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -122,8 +119,7 @@ async fn list_memory_files_rejects_non_directory_target() {
#[tokio::test]
async fn read_and_write_memory_files_reject_path_traversal() {
let _guard = TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let tmp = TempDir::new().expect("tempdir");
let _workspace = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -146,8 +142,7 @@ async fn read_and_write_memory_files_reject_path_traversal() {
#[tokio::test]
async fn list_and_read_memory_files_reject_absolute_paths() {
let _guard = TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let tmp = TempDir::new().expect("tempdir");
let _workspace = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -177,8 +172,7 @@ async fn list_and_read_memory_files_reject_absolute_paths() {
#[tokio::test]
async fn read_memory_file_surfaces_missing_file_error() {
let _guard = TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let tmp = TempDir::new().expect("tempdir");
let _workspace = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -196,8 +190,7 @@ async fn read_memory_file_surfaces_missing_file_error() {
#[tokio::test]
async fn read_memory_file_surfaces_invalid_utf8_error() {
let _guard = TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let tmp = TempDir::new().expect("tempdir");
let _workspace = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -222,8 +215,7 @@ async fn write_memory_file_rejects_symlink_targets() {
use std::os::unix::fs::symlink;
let _guard = TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let tmp = TempDir::new().expect("tempdir");
let _workspace = EnvVarGuard::workspace_unlocked(tmp.path());
@@ -251,8 +243,7 @@ async fn list_memory_files_skips_symlink_entries() {
use std::os::unix::fs::symlink;
let _guard = TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let tmp = TempDir::new().expect("tempdir");
let _workspace = EnvVarGuard::workspace_unlocked(tmp.path());
diff --git a/crates/openhuman-core/src/memory/ops/sync_tests.rs b/crates/openhuman-core/src/memory/ops/sync_tests.rs
index d2319e4545..ba6bfd4761 100644
--- a/crates/openhuman-core/src/memory/ops/sync_tests.rs
+++ b/crates/openhuman-core/src/memory/ops/sync_tests.rs
@@ -10,9 +10,9 @@ use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
use tinybus::EventHandler;
-fn test_mutex() -> &'static std::sync::Mutex<()> {
- static LOCK: OnceLock<std::sync::Mutex<()>> = OnceLock::new();
- LOCK.get_or_init(|| std::sync::Mutex::new(()))
+fn test_mutex() -> &'static tokio::sync::Mutex<()> {
+ static LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
+ LOCK.get_or_init(|| tokio::sync::Mutex::new(()))
}
/// A config on its own temp workspace with a driver bound that reports
@@ -96,8 +96,7 @@ fn sync_result_structs_serialize_expected_fields() {
async fn memory_sync_channel_publishes_targeted_event() {
let _serial = crate::memory::ops::GLOBAL_MEMORY_TEST_LOCK.lock().await;
let _guard = test_mutex()
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let _ = crate::core::bus::init().await;
let (tx, mut rx) = mpsc::unbounded_channel();
let _subscription = BUS
@@ -123,8 +122,7 @@ async fn memory_sync_channel_publishes_targeted_event() {
async fn memory_sync_all_publishes_broadcast_event() {
let _serial = crate::memory::ops::GLOBAL_MEMORY_TEST_LOCK.lock().await;
let _guard = test_mutex()
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
let _ = crate::core::bus::init().await;
let (tx, mut rx) = mpsc::unbounded_channel();
let _subscription = BUS
diff --git a/crates/openhuman-core/src/memory/query/ingest_document_tests.rs b/crates/openhuman-core/src/memory/query/ingest_document_tests.rs
index 8945275e5b..b3f97107df 100644
--- a/crates/openhuman-core/src/memory/query/ingest_document_tests.rs
+++ b/crates/openhuman-core/src/memory/query/ingest_document_tests.rs
@@ -8,7 +8,7 @@ use serde_json::json;
use tinytools::Tool;
async fn isolated_config(tmp: &TempDir) -> (EnvVarGuard, Config) {
- let guard = EnvVarGuard::workspace(tmp.path());
+ let guard = EnvVarGuard::workspace_async(tmp.path()).await;
let config = Config::load_or_init().await.expect("load config");
// `list_chunks_rpc` reads through the bound driver now, and a unit-test
// workspace binds the null one — which serves no Chunks family and
diff --git a/crates/openhuman-core/src/memory/sources/rpc_tests.rs b/crates/openhuman-core/src/memory/sources/rpc_tests.rs
index 2f752ee787..9f2c40fa61 100644
--- a/crates/openhuman-core/src/memory/sources/rpc_tests.rs
+++ b/crates/openhuman-core/src/memory/sources/rpc_tests.rs
@@ -216,7 +216,7 @@ async fn add_generates_an_id_and_caps_a_request_that_left_its_limits_unset() {
let tmp = tempfile::TempDir::new().expect("tempdir");
let workspace = tmp.path().join("workspace");
std::fs::create_dir_all(&workspace).expect("workspace dir");
- let _env = EnvVarGuard::workspace(&workspace);
+ let _env = EnvVarGuard::workspace_async(&workspace).await;
let added = add_rpc(github_add_request())
.await
diff --git a/crates/openhuman-core/src/memory/sync/composio/bus_tests.rs b/crates/openhuman-core/src/memory/sync/composio/bus_tests.rs
index a62b27764b..2e683bfade 100644
--- a/crates/openhuman-core/src/memory/sync/composio/bus_tests.rs
+++ b/crates/openhuman-core/src/memory/sync/composio/bus_tests.rs
@@ -67,7 +67,7 @@ async fn a_driver_that_cannot_answer_makes_a_toolkit_not_registrable() {
// items these assert on (`TRIAGE_DISABLED_ENV`, the parser). They belong here,
// against the module that actually defines them.
-static TRIAGE_ENV_GUARD: Mutex<()> = Mutex::new(());
+static TRIAGE_ENV_GUARD: Mutex<()> = tokio::sync::Mutex::const_new(());
#[tokio::test]
async fn ignores_non_composio_events() {
@@ -94,8 +94,8 @@ async fn handles_trigger_event_without_panic() {
// (acquired before `TRIAGE_ENV_GUARD` for a stable lock order) and
// point `OPENHUMAN_WORKSPACE` at an isolated, persisted config.
use crate::config::{Config, TEST_ENV_LOCK};
- let _env_lock = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
- let _guard = TRIAGE_ENV_GUARD.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_lock = TEST_ENV_LOCK.lock().await;
+ let _guard = TRIAGE_ENV_GUARD.lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
unsafe {
@@ -127,7 +127,7 @@ async fn handles_trigger_event_without_panic() {
#[test]
fn triage_disabled_flag_parser() {
- let _guard = TRIAGE_ENV_GUARD.lock().unwrap_or_else(|e| e.into_inner());
+ let _guard = TRIAGE_ENV_GUARD.blocking_lock();
// Truthy values disable triage.
for val in ["1", "true", "TRUE", "yes", "YES"] {
std::env::set_var(TRIAGE_DISABLED_ENV, val);
@@ -204,8 +204,8 @@ async fn trigger_subscriber_skips_triage_when_env_disabled() {
// this test must isolate `OPENHUMAN_WORKSPACE` under `TEST_ENV_LOCK`
// (acquired before `TRIAGE_ENV_GUARD`).
use crate::config::{Config, TEST_ENV_LOCK};
- let _env_lock = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
- let _guard = TRIAGE_ENV_GUARD.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_lock = TEST_ENV_LOCK.lock().await;
+ let _guard = TRIAGE_ENV_GUARD.lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
unsafe {
@@ -250,7 +250,7 @@ async fn handles_connection_created_event_without_panic() {
// var is deliberately left set to the isolated dir — the next
// `TEST_ENV_LOCK` holder re-points it to its own workspace.
use crate::config::{Config, TEST_ENV_LOCK};
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
unsafe {
@@ -341,7 +341,7 @@ async fn connection_subscriber_skips_when_no_provider_registered() {
// hold `TEST_ENV_LOCK`, point `OPENHUMAN_WORKSPACE` at a leaked
// persisted tempdir, and drain the spawn before releasing the lock.
use crate::config::{Config, TEST_ENV_LOCK};
- let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_guard = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
unsafe {
diff --git a/crates/openhuman-core/src/memory/sync_events_bridge_tests.rs b/crates/openhuman-core/src/memory/sync_events_bridge_tests.rs
index 9277a3ddf5..f6cd139395 100644
--- a/crates/openhuman-core/src/memory/sync_events_bridge_tests.rs
+++ b/crates/openhuman-core/src/memory/sync_events_bridge_tests.rs
@@ -3,9 +3,9 @@ use std::sync::{Arc, Mutex, OnceLock};
use crate::core::bus::BUS;
-fn test_mutex() -> &'static std::sync::Mutex<()> {
- static LOCK: OnceLock<std::sync::Mutex<()>> = OnceLock::new();
- LOCK.get_or_init(|| std::sync::Mutex::new(()))
+fn test_mutex() -> &'static tokio::sync::Mutex<()> {
+ static LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
+ LOCK.get_or_init(|| tokio::sync::Mutex::new(()))
}
#[derive(Clone, Default)]
@@ -33,8 +33,7 @@ impl EventHandler<DomainEvent> for StageCollector {
#[tokio::test]
async fn document_canonicalized_emits_stored_and_queued_stages() {
let _guard = test_mutex()
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
crate::core::bus::init().await.expect("bus init");
// The bridge emits through `tinymemory_api::events`' sink, and these tests
// used to get it installed as a side effect of the memory host seams. Those
@@ -78,8 +77,7 @@ async fn document_canonicalized_emits_stored_and_queued_stages() {
#[tokio::test]
async fn memory_ingestion_started_emits_ingesting_stage() {
let _guard = test_mutex()
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
crate::core::bus::init().await.expect("bus init");
// The bridge emits through `tinymemory_api::events`' sink, and these tests
// used to get it installed as a side effect of the memory host seams. Those
@@ -163,8 +161,7 @@ fn extract_mem_src_id_returns_the_source_segment_of_mem_src_ids() {
#[tokio::test]
async fn bridge_populates_source_id_for_stored_and_queued_from_mem_src() {
let _guard = test_mutex()
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
crate::core::bus::init().await.expect("bus init");
// The bridge emits through `tinymemory_api::events`' sink, and these tests
// used to get it installed as a side effect of the memory host seams. Those
@@ -217,8 +214,7 @@ async fn bridge_populates_source_id_for_stored_and_queued_from_mem_src() {
#[tokio::test]
async fn bridge_source_id_is_none_for_non_mem_src_canonicalized() {
let _guard = test_mutex()
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
crate::core::bus::init().await.expect("bus init");
// The bridge emits through `tinymemory_api::events`' sink, and these tests
// used to get it installed as a side effect of the memory host seams. Those
@@ -270,8 +266,7 @@ async fn bridge_source_id_is_none_for_non_mem_src_canonicalized() {
#[tokio::test]
async fn bridge_populates_source_id_for_ingesting_from_mem_src() {
let _guard = test_mutex()
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
crate::core::bus::init().await.expect("bus init");
// The bridge emits through `tinymemory_api::events`' sink, and these tests
// used to get it installed as a side effect of the memory host seams. Those
@@ -329,8 +324,7 @@ async fn bridge_populates_source_id_for_ingesting_from_mem_src() {
#[tokio::test]
async fn bridge_source_id_is_none_for_ingesting_non_mem_src() {
let _guard = test_mutex()
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
crate::core::bus::init().await.expect("bus init");
// The bridge emits through `tinymemory_api::events`' sink, and these tests
// used to get it installed as a side effect of the memory host seams. Those
diff --git a/crates/openhuman-core/src/memory/tools/goals_tests.rs b/crates/openhuman-core/src/memory/tools/goals_tests.rs
index d6afc7f47e..aeb97736dc 100644
--- a/crates/openhuman-core/src/memory/tools/goals_tests.rs
+++ b/crates/openhuman-core/src/memory/tools/goals_tests.rs
@@ -41,7 +41,7 @@ async fn reset_shared_goals() {
async fn add_then_list_reflects_change() {
let _serial = crate::memory::ops::GLOBAL_MEMORY_TEST_LOCK.lock().await;
let tmp = TempDir::new().expect("tempdir");
- let _workspace = EnvVarGuard::workspace(tmp.path());
+ let _workspace = EnvVarGuard::workspace_async(tmp.path()).await;
reset_shared_goals().await;
let goals = GoalsTool::new(tmp.path().to_path_buf());
@@ -59,7 +59,7 @@ async fn add_then_list_reflects_change() {
async fn edit_and_delete_unknown_id_error() {
let _serial = crate::memory::ops::GLOBAL_MEMORY_TEST_LOCK.lock().await;
let tmp = TempDir::new().expect("tempdir");
- let _workspace = EnvVarGuard::workspace(tmp.path());
+ let _workspace = EnvVarGuard::workspace_async(tmp.path()).await;
reset_shared_goals().await;
let goals = GoalsTool::new(tmp.path().to_path_buf());
@@ -83,7 +83,7 @@ async fn edit_and_delete_unknown_id_error() {
async fn add_refuses_pii_bearing_text_with_the_specific_reason() {
let _serial = crate::memory::ops::GLOBAL_MEMORY_TEST_LOCK.lock().await;
let tmp = TempDir::new().expect("tempdir");
- let _workspace = EnvVarGuard::workspace(tmp.path());
+ let _workspace = EnvVarGuard::workspace_async(tmp.path()).await;
reset_shared_goals().await;
let add = GoalsTool::new(tmp.path().to_path_buf());
diff --git a/crates/openhuman-core/src/memory/tools/tool_memory/guard_tests.rs b/crates/openhuman-core/src/memory/tools/tool_memory/guard_tests.rs
index c4563cf495..cf7bea2736 100644
--- a/crates/openhuman-core/src/memory/tools/tool_memory/guard_tests.rs
+++ b/crates/openhuman-core/src/memory/tools/tool_memory/guard_tests.rs
@@ -36,7 +36,7 @@ fn scoped_tier(autonomy: AutonomyLevel) -> live_policy::TestPolicyGuard {
}
async fn isolated_config(tmp: &TempDir) -> (EnvVarGuard, Config) {
- let guard = EnvVarGuard::workspace(tmp.path());
+ let guard = EnvVarGuard::workspace_async(tmp.path()).await;
let config = Config::load_or_init().await.expect("load config");
(guard, config)
}
diff --git a/crates/openhuman-core/src/memory/tree/tree_runtime/cli_tests.rs b/crates/openhuman-core/src/memory/tree/tree_runtime/cli_tests.rs
index 10685664bc..75cc355d48 100644
--- a/crates/openhuman-core/src/memory/tree/tree_runtime/cli_tests.rs
+++ b/crates/openhuman-core/src/memory/tree/tree_runtime/cli_tests.rs
@@ -7,8 +7,12 @@ use crate::config::TEST_ENV_LOCK;
use super::*;
use crate::config::test_env::EnvVarGuard;
-fn lock_env() -> std::sync::MutexGuard<'static, ()> {
- TEST_ENV_LOCK.lock().unwrap_or_else(|err| err.into_inner())
+fn lock_env() -> tokio::sync::MutexGuard<'static, ()> {
+ TEST_ENV_LOCK.blocking_lock()
+}
+
+async fn lock_env_async() -> tokio::sync::MutexGuard<'static, ()> {
+ TEST_ENV_LOCK.lock().await
}
#[test]
diff --git a/crates/openhuman-core/src/modules/connectors_tests.rs b/crates/openhuman-core/src/modules/connectors_tests.rs
index 742f611cfb..925181b875 100644
--- a/crates/openhuman-core/src/modules/connectors_tests.rs
+++ b/crates/openhuman-core/src/modules/connectors_tests.rs
@@ -95,8 +95,7 @@ fn direct_mode_hands_the_module_the_hosts_proxy_policy() {
use crate::config::{runtime_proxy_config, set_runtime_proxy_config};
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let mut config = bare_config();
config.composio.mode = COMPOSIO_MODE_DIRECT.to_string();
config.composio.api_key = Some("sk-from-file".to_string());
diff --git a/crates/openhuman-core/src/platform/update/ops_tests.rs b/crates/openhuman-core/src/platform/update/ops_tests.rs
index 341366fadd..8e36b63efd 100644
--- a/crates/openhuman-core/src/platform/update/ops_tests.rs
+++ b/crates/openhuman-core/src/platform/update/ops_tests.rs
@@ -218,7 +218,7 @@ async fn supervisor_strategy_message_mentions_supervisor() {
#[tokio::test]
async fn update_run_rejected_when_rpc_mutations_disabled() {
use crate::config::TEST_ENV_LOCK;
- let _lock = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _lock = TEST_ENV_LOCK.lock().await;
let tmp = tempfile::TempDir::new().unwrap();
// Write a config with mutations disabled.
diff --git a/crates/openhuman-core/src/platform/update/ops_tests_2_tests.rs b/crates/openhuman-core/src/platform/update/ops_tests_2_tests.rs
index 4db2302462..7e1b90e048 100644
--- a/crates/openhuman-core/src/platform/update/ops_tests_2_tests.rs
+++ b/crates/openhuman-core/src/platform/update/ops_tests_2_tests.rs
@@ -100,7 +100,7 @@ fn validate_asset_name_rejects_unprefixed_asset() {
// `update_apply` so the three cases serialise on the same mutex.
#[tokio::test]
async fn update_apply_rejects_non_github_url_before_network_call() {
- let _guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _guard = TEST_ENV_LOCK.lock().await;
let outcome = update_apply(
"https://evil.example.com/asset".to_string(),
"openhuman-core-x86_64.tar.gz".to_string(),
@@ -116,7 +116,7 @@ async fn update_apply_rejects_non_github_url_before_network_call() {
#[tokio::test]
async fn update_apply_rejects_unsafe_asset_name() {
- let _guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _guard = TEST_ENV_LOCK.lock().await;
let outcome = update_apply(
"https://github.com/owner/repo/releases/download/v1/x".to_string(),
"../etc/passwd".to_string(),
@@ -132,7 +132,7 @@ async fn update_apply_rejects_unsafe_asset_name() {
#[tokio::test]
async fn update_apply_rejects_when_rpc_mutations_disabled() {
- let _guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _guard = TEST_ENV_LOCK.lock().await;
let tmp = TempDir::new().unwrap();
let _workspace_guard = EnvVarGuard::workspace_unlocked(tmp.path());
write_update_policy(
diff --git a/crates/openhuman-core/src/sandbox/docker_exec_tests.rs b/crates/openhuman-core/src/sandbox/docker_exec_tests.rs
index c728f041a5..0266f82ad4 100644
--- a/crates/openhuman-core/src/sandbox/docker_exec_tests.rs
+++ b/crates/openhuman-core/src/sandbox/docker_exec_tests.rs
@@ -39,8 +39,7 @@ fn recorded(out: &Path) -> Vec<String> {
/// Run `f` with `bin` first on `PATH`, serialised against other env tests.
fn with_fake_path<T>(bin: &Path, f: impl FnOnce() -> T) -> T {
let _guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let prev = std::env::var_os("PATH");
let mut paths = vec![bin.to_path_buf()];
if let Some(p) = &prev {
@@ -263,8 +262,7 @@ fn missing_docker_binary_is_an_execution_error() {
std::fs::create_dir_all(&ws).unwrap();
// Replace PATH wholesale so no `docker` can be found.
let _guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let prev = std::env::var_os("PATH");
std::env::set_var("PATH", tmp.path());
let err = block_on(docker_exec(
diff --git a/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs b/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs
index c2452e72c6..69586f24ff 100644
--- a/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs
@@ -172,8 +172,7 @@ async fn auto_approve_tool_skips_prompt() {
// (the `live_policy` module test + the autonomy `ops` tests, which all
// take this same lock) so a parallel install can't clobber ours mid-test.
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let (gate, dir) = test_gate();
// A tool name unique to this test so leaving it in the global allowlist
@@ -214,8 +213,7 @@ async fn auto_approve_tool_skips_prompt() {
#[tokio::test]
async fn auto_approve_all_resolves_allow() {
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let (gate, dir) = test_gate();
let policy = crate::security::SecurityPolicy {
auto_approve_all: true,
@@ -249,8 +247,7 @@ async fn auto_approve_all_resolves_allow() {
#[tokio::test]
async fn auto_approve_all_off_still_parks() {
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let (gate, dir) = test_gate();
let policy = crate::security::SecurityPolicy {
auto_approve_all: false,
@@ -302,8 +299,7 @@ async fn auto_approve_all_off_still_parks() {
#[tokio::test]
async fn auto_approve_all_does_not_override_unknown() {
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let (gate, dir) = test_gate();
let policy = crate::security::SecurityPolicy {
auto_approve_all: true,
@@ -341,8 +337,7 @@ async fn auto_approve_all_does_not_override_unknown() {
#[tokio::test]
async fn auto_approve_all_overrides_require_approval_workflow() {
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let (gate, dir) = test_gate();
let policy = crate::security::SecurityPolicy {
auto_approve_all: true,
@@ -397,8 +392,7 @@ async fn auto_approve_all_allows_a_remote_triage_dispatch_without_an_audit_row()
use crate::agent::triage::{remote_trigger_origin, TriggerEnvelope};
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let (gate, dir) = test_gate();
let policy = crate::security::SecurityPolicy {
auto_approve_all: true,
diff --git a/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs b/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs
index 3ae58342e4..14c3e9f9ae 100644
--- a/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs
@@ -267,8 +267,7 @@ async fn intercept_audited_bounded_abandons_park_and_leaves_row_pending() {
#[test]
fn effective_ttl_uses_env_override_when_valid() {
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let (gate, _dir) = test_gate_with_ttl(BOOT_TTL_UNDER_TEST);
unsafe { std::env::set_var("OPENHUMAN_APPROVAL_TTL_SECS", "42") };
assert_eq!(
@@ -282,8 +281,7 @@ fn effective_ttl_uses_env_override_when_valid() {
#[test]
fn effective_ttl_falls_back_to_boot_ttl_for_garbage_value() {
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let (gate, _dir) = test_gate_with_ttl(BOOT_TTL_UNDER_TEST);
unsafe { std::env::set_var("OPENHUMAN_APPROVAL_TTL_SECS", "not-a-number") };
assert_eq!(
@@ -297,8 +295,7 @@ fn effective_ttl_falls_back_to_boot_ttl_for_garbage_value() {
#[test]
fn effective_ttl_falls_back_to_boot_ttl_when_unset() {
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let (gate, _dir) = test_gate_with_ttl(BOOT_TTL_UNDER_TEST);
unsafe { std::env::remove_var("OPENHUMAN_APPROVAL_TTL_SECS") };
assert_eq!(
diff --git a/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_bearer_token_tests.rs b/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_bearer_token_tests.rs
index 058b3eb940..10c2d96a77 100644
--- a/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_bearer_token_tests.rs
+++ b/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_bearer_token_tests.rs
@@ -101,8 +101,7 @@ fn lookup_openai_bearer_token_returns_ok_when_nearly_expiring_and_refresh_fails(
#[tokio::test(flavor = "multi_thread")]
async fn lookup_openai_bearer_token_does_not_persist_blank_refreshed_access_token() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = tempdir().unwrap();
let config = test_config(&tmp);
let store = AuthProfilesStore::new(tmp.path(), false);
diff --git a/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_lifecycle_tests.rs b/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_lifecycle_tests.rs
index f6f0dad28b..2d703f3dc1 100644
--- a/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_lifecycle_tests.rs
+++ b/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_lifecycle_tests.rs
@@ -441,8 +441,7 @@ fn codex_import_user_state_errors_classify_as_expected() {
#[tokio::test]
async fn inference_import_codex_cli_surfaces_error_when_auth_missing() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = tempdir().unwrap();
let config = test_config(&tmp);
let _env_guard = EnvVarGuard::set("CODEX_HOME", tmp.path());
diff --git a/crates/openhuman-core/src/security/credentials/ops/boot_env_tests.rs b/crates/openhuman-core/src/security/credentials/ops/boot_env_tests.rs
index 623fbf1a84..723b440eef 100644
--- a/crates/openhuman-core/src/security/credentials/ops/boot_env_tests.rs
+++ b/crates/openhuman-core/src/security/credentials/ops/boot_env_tests.rs
@@ -15,8 +15,7 @@ fn config_in(tmp: &TempDir) -> Config {
#[test]
fn api_key_env_seeds_only_an_empty_store() {
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let tmp = TempDir::new().unwrap();
let config = config_in(&tmp);
let _guard = EnvVarGuard::unset(BACKEND_API_KEY_ENV);
@@ -47,8 +46,7 @@ fn api_key_env_seeds_only_an_empty_store() {
#[tokio::test]
async fn session_env_is_ignored_without_a_subject_and_when_unset() {
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
let config = config_in(&tmp);
let _guard = EnvVarGuard::unset(BACKEND_SESSION_TOKEN_ENV);
diff --git a/crates/openhuman-core/src/security/credentials/ops/user_scope_tests.rs b/crates/openhuman-core/src/security/credentials/ops/user_scope_tests.rs
index 6198ddccc4..48d98a84e2 100644
--- a/crates/openhuman-core/src/security/credentials/ops/user_scope_tests.rs
+++ b/crates/openhuman-core/src/security/credentials/ops/user_scope_tests.rs
@@ -2,7 +2,7 @@ use super::*;
#[test]
fn explicit_scratch_workspace_cannot_activate_operator_user() {
- let _guard = crate::config::TEST_ENV_LOCK.lock().unwrap();
+ let _guard = crate::config::TEST_ENV_LOCK.blocking_lock();
let previous = std::env::var_os("OPENHUMAN_WORKSPACE");
let scratch = tempfile::tempdir().unwrap();
unsafe {
diff --git a/crates/openhuman-core/src/security/credentials/ops_credential_tests.rs b/crates/openhuman-core/src/security/credentials/ops_credential_tests.rs
index 6716d0be0d..21584678e2 100644
--- a/crates/openhuman-core/src/security/credentials/ops_credential_tests.rs
+++ b/crates/openhuman-core/src/security/credentials/ops_credential_tests.rs
@@ -115,8 +115,7 @@ async fn set_credential_requires_a_user_id_for_a_session() {
#[tokio::test]
async fn set_credential_installs_a_session_without_touching_the_backend() {
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
@@ -165,8 +164,7 @@ async fn set_credential_installs_a_session_without_touching_the_backend() {
#[tokio::test]
async fn set_credential_derives_the_user_id_from_the_jwt_subject() {
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
@@ -192,8 +190,7 @@ async fn set_credential_derives_the_user_id_from_the_jwt_subject() {
#[tokio::test]
async fn set_credential_with_the_same_token_and_user_is_a_cheap_refresh() {
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
@@ -237,8 +234,7 @@ async fn set_credential_with_the_same_token_and_user_is_a_cheap_refresh() {
#[tokio::test]
async fn set_credential_for_a_different_user_signs_the_previous_one_out_first() {
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
@@ -320,8 +316,7 @@ async fn set_and_clear_api_key_credential() {
#[tokio::test]
async fn clearing_the_session_preserves_a_coexisting_api_key() {
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
@@ -395,8 +390,7 @@ async fn clearing_the_session_preserves_a_coexisting_api_key() {
#[tokio::test]
async fn clearing_the_session_preserves_the_active_key_over_a_stale_destination_key() {
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
@@ -473,8 +467,7 @@ async fn clearing_the_session_preserves_the_active_key_over_a_stale_destination_
#[tokio::test]
async fn clearing_without_a_kind_removes_a_user_scoped_api_key_at_its_source() {
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
@@ -527,8 +520,7 @@ async fn clearing_without_a_kind_removes_a_user_scoped_api_key_at_its_source() {
#[tokio::test]
async fn clear_credential_without_a_kind_removes_everything() {
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
@@ -563,8 +555,7 @@ async fn clear_credential_without_a_kind_removes_everything() {
#[tokio::test]
async fn store_session_local_token_rejects_missing_user_payload() {
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
@@ -586,8 +577,7 @@ async fn store_session_local_token_rejects_missing_user_payload() {
#[tokio::test]
async fn store_session_local_token_succeeds_without_network_and_forces_local_user_id() {
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
diff --git a/crates/openhuman-core/src/security/credentials/ops_provider_oauth_tests.rs b/crates/openhuman-core/src/security/credentials/ops_provider_oauth_tests.rs
index 4c895876d9..bed8588e13 100644
--- a/crates/openhuman-core/src/security/credentials/ops_provider_oauth_tests.rs
+++ b/crates/openhuman-core/src/security/credentials/ops_provider_oauth_tests.rs
@@ -11,8 +11,7 @@ async fn clear_session_on_empty_store_reports_removed_false() {
// e.g. `deferred_session_without_user_id_does_not_replace_active_user_profile`,
// whose active-session guard then silently stops firing.
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
let config = test_config(&tmp);
@@ -371,8 +370,7 @@ async fn clear_session_on_one_account_does_not_affect_another() {
// See `clear_session_on_empty_store_reports_removed_false`: `clear_session`
// reaches the HOME-derived root, so this test must own HOME while it runs.
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp_a = TempDir::new().unwrap();
let tmp_b = TempDir::new().unwrap();
let _home = EnvVarGuard::set("HOME", tmp_a.path());
@@ -486,8 +484,7 @@ async fn start_login_gated_services_completes_with_all_services_disabled() {
// background services. (These are the same semantics `TEST_ENV_LOCK` gives
// the HOME-mutating tests.)
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = TempDir::new().unwrap();
// Under `#[cfg(test)]` `start_login_gated_services` skips the real services
// by default (they leak across the parallel test run); opt this one test
diff --git a/crates/openhuman-core/src/security/keyring/store_tests.rs b/crates/openhuman-core/src/security/keyring/store_tests.rs
index 25a512bbb3..af37d54589 100644
--- a/crates/openhuman-core/src/security/keyring/store_tests.rs
+++ b/crates/openhuman-core/src/security/keyring/store_tests.rs
@@ -31,7 +31,7 @@ use crate::security::keyring;
/// store followed the env var around.
#[test]
fn test_builds_ignore_the_process_wide_workspace_env_var() {
- let _env_lock = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_lock = TEST_ENV_LOCK.blocking_lock();
let tmp = tempfile::tempdir().expect("tempdir");
let _guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", tmp.path());
@@ -46,7 +46,7 @@ fn test_builds_ignore_the_process_wide_workspace_env_var() {
/// This is the half that guarantees the fix is test-only.
#[test]
fn production_resolution_still_honours_the_workspace_env_var() {
- let _env_lock = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let _env_lock = TEST_ENV_LOCK.blocking_lock();
let tmp = tempfile::tempdir().expect("tempdir");
let _guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", tmp.path());
diff --git a/crates/openhuman-core/src/security/live_policy_tests.rs b/crates/openhuman-core/src/security/live_policy_tests.rs
index 91c1e09a49..3a26d14ace 100644
--- a/crates/openhuman-core/src/security/live_policy_tests.rs
+++ b/crates/openhuman-core/src/security/live_policy_tests.rs
@@ -5,8 +5,7 @@ use crate::security::AutonomyLevel;
#[test]
fn scoped_policy_is_thread_local_and_restored() {
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let workspace = std::env::temp_dir().join("openhuman_scoped_policy_test");
install(
Arc::new(SecurityPolicy::default()),
@@ -47,8 +46,7 @@ fn install_then_reload_swaps_policy_and_bumps_generation() {
// (the approval-gate auto_approve test and the autonomy `ops` tests),
// which all take this same lock — otherwise a parallel install races.
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let workspace = std::env::temp_dir().join("openhuman_live_policy_test");
let initial = Arc::new(SecurityPolicy {
autonomy: AutonomyLevel::Supervised,
@@ -82,8 +80,7 @@ fn install_then_reload_swaps_policy_and_bumps_generation() {
fn reload_privacy_swaps_mode_and_survives_autonomy_reload() {
// Same process-global lock as the other live-policy tests.
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let workspace = std::env::temp_dir().join("openhuman_privacy_live_test");
let initial = Arc::new(SecurityPolicy {
autonomy: AutonomyLevel::Supervised,
@@ -136,8 +133,7 @@ fn set_action_dir_swaps_root_and_bumps_generation() {
// Same process-global lock as the reload test — these install/swap the
// shared live policy and would race each other otherwise.
let _env = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
let workspace = std::env::temp_dir().join("openhuman_set_action_dir_test_ws");
let action = std::env::temp_dir().join("openhuman_set_action_dir_test_action_a");
let initial = Arc::new(SecurityPolicy {
diff --git a/crates/openhuman-core/src/security/ops_tests.rs b/crates/openhuman-core/src/security/ops_tests.rs
index 83fb534331..b40ed98f52 100644
--- a/crates/openhuman-core/src/security/ops_tests.rs
+++ b/crates/openhuman-core/src/security/ops_tests.rs
@@ -79,8 +79,7 @@ async fn load_and_get_security_policy_info_reflects_env_overlay() {
// Serialize against every other test that mutates process env —
// load_tests.rs uses the same lock so we cannot race with it.
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
+ .lock().await;
for budget in [42_u32, 0_u32] {
// Point the loader at a throwaway workspace so the test does not
diff --git a/crates/openhuman-core/src/skills/catalog/ops_tests.rs b/crates/openhuman-core/src/skills/catalog/ops_tests.rs
index 9d1d40f766..e5d54cff1d 100644
--- a/crates/openhuman-core/src/skills/catalog/ops_tests.rs
+++ b/crates/openhuman-core/src/skills/catalog/ops_tests.rs
@@ -67,10 +67,14 @@ use std::sync::Arc;
const CACHE_DIR_ENV: &str = "OPENHUMAN_SKILL_REGISTRY_CACHE_DIR";
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {
crate::skills::catalog::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner())
+ .blocking_lock()
+}
+
+async fn env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {
+ crate::skills::catalog::TEST_ENV_LOCK
+ .lock().await
}
fn sample_entry() -> CatalogEntry {
@@ -86,7 +90,7 @@ fn sample_entry() -> CatalogEntry {
#[tokio::test]
async fn fresh_cache_skips_fetch() {
- let _env = env_lock();
+ let _env = env_lock_async().await;
let tmp = tempfile::tempdir().unwrap();
std::env::set_var(CACHE_DIR_ENV, tmp.path());
store::save_catalog_cache(&[sample_entry()]);
@@ -112,7 +116,7 @@ async fn fresh_cache_skips_fetch() {
#[tokio::test]
async fn concurrent_cache_miss_coalesces_to_single_fetch() {
- let _env = env_lock();
+ let _env = env_lock_async().await;
let tmp = tempfile::tempdir().unwrap();
std::env::set_var(CACHE_DIR_ENV, tmp.path());
store::clear_cache();
@@ -164,7 +168,7 @@ fn write_cache_at(dir: &std::path::Path, entries: Vec<CatalogEntry>, epoch: u64)
#[tokio::test]
async fn browse_serves_stale_without_a_foreground_fetch() {
- let _env = env_lock();
+ let _env = env_lock_async().await;
let tmp = tempfile::tempdir().unwrap();
std::env::set_var(CACHE_DIR_ENV, tmp.path());
write_cache_at(tmp.path(), vec![sample_entry()], 1); // epoch 1 => stale
@@ -193,7 +197,7 @@ async fn browse_serves_stale_without_a_foreground_fetch() {
#[tokio::test]
async fn search_rejects_stale_and_fetches_fresh() {
- let _env = env_lock();
+ let _env = env_lock_async().await;
let tmp = tempfile::tempdir().unwrap();
std::env::set_var(CACHE_DIR_ENV, tmp.path());
write_cache_at(tmp.path(), vec![sample_entry()], 1); // stale: 1 entry
@@ -225,7 +229,7 @@ async fn search_rejects_stale_and_fetches_fresh() {
#[tokio::test]
async fn search_ranks_installable_entries_before_uninstallable_ones() {
- let _env = env_lock();
+ let _env = env_lock_async().await;
let tmp = tempfile::tempdir().unwrap();
std::env::set_var(CACHE_DIR_ENV, tmp.path());
let agent = parse_hermes_entry(&json!({
diff --git a/crates/openhuman-core/src/skills/catalog/tools_tests.rs b/crates/openhuman-core/src/skills/catalog/tools_tests.rs
index d5d3800c04..aa2b17e7f1 100644
--- a/crates/openhuman-core/src/skills/catalog/tools_tests.rs
+++ b/crates/openhuman-core/src/skills/catalog/tools_tests.rs
@@ -32,8 +32,7 @@ async fn search_page(args: serde_json::Value) -> serde_json::Value {
async fn search_tool_returns_a_bounded_page_and_where_the_next_one_starts() {
// #6286: a broad query used to return every match in one result.
let _env = crate::skills::catalog::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = tempfile::tempdir().unwrap();
std::env::set_var("OPENHUMAN_SKILL_REGISTRY_CACHE_DIR", tmp.path());
let catalog: Vec<_> = (0..45)
diff --git a/crates/openhuman-core/src/threads/ops/live_state_tests.rs b/crates/openhuman-core/src/threads/ops/live_state_tests.rs
index 471270462c..436a79a02d 100644
--- a/crates/openhuman-core/src/threads/ops/live_state_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/live_state_tests.rs
@@ -24,7 +24,7 @@ struct WorkspaceGuard {
impl WorkspaceGuard {
fn new() -> Self {
- let lock = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let lock = TEST_ENV_LOCK.blocking_lock();
let tmp = tempfile::tempdir().expect("tempdir");
unsafe {
std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path());
diff --git a/crates/openhuman-core/src/threads/ops_conversion_tests.rs b/crates/openhuman-core/src/threads/ops_conversion_tests.rs
index 430d8fc89f..33b47e7a8a 100644
--- a/crates/openhuman-core/src/threads/ops_conversion_tests.rs
+++ b/crates/openhuman-core/src/threads/ops_conversion_tests.rs
@@ -181,8 +181,7 @@ fn title_log_prefix_is_grep_friendly_and_stable() {
#[tokio::test]
async fn message_append_returns_typed_not_found_for_stale_thread() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
let thread_id = "thread-missing";
@@ -213,8 +212,7 @@ async fn message_append_returns_typed_not_found_for_stale_thread() {
#[tokio::test]
async fn generate_title_returns_typed_not_found_for_stale_thread() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
let thread_id = "thread-missing";
@@ -238,8 +236,7 @@ async fn generate_title_returns_typed_not_found_for_stale_thread() {
#[tokio::test]
async fn generate_title_leaves_custom_title_unchanged() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
let thread_id = "thread-custom";
@@ -279,8 +276,7 @@ async fn generate_title_leaves_custom_title_unchanged() {
#[tokio::test]
async fn generate_title_returns_existing_title_when_no_user_message_exists() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
let thread_id = "thread-no-user";
@@ -302,8 +298,7 @@ async fn generate_title_returns_existing_title_when_no_user_message_exists() {
#[tokio::test]
async fn generate_title_falls_back_to_first_user_message_when_assistant_missing() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
let thread_id = "thread-fallback";
@@ -343,8 +338,7 @@ async fn generate_title_falls_back_to_first_user_message_when_assistant_missing(
#[tokio::test]
async fn thread_delete_removes_persisted_turn_state_snapshot() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
let thread_id = "thread-delete";
@@ -396,8 +390,7 @@ async fn thread_delete_removes_persisted_turn_state_snapshot() {
#[tokio::test]
async fn threads_purge_removes_valid_and_corrupted_turn_state_files() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
create_thread_with_title(&workspace, "thread-a", "Chat Jan 1 1:00 AM").await;
@@ -456,8 +449,7 @@ async fn threads_purge_removes_valid_and_corrupted_turn_state_files() {
#[tokio::test]
async fn turn_state_clear_reports_false_when_snapshot_is_absent() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
@@ -475,8 +467,7 @@ async fn turn_state_clear_reports_false_when_snapshot_is_absent() {
#[tokio::test]
async fn thread_update_title_rejects_empty_and_whitespace_only_titles() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
diff --git a/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs b/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs
index ddb1edd7b9..87bb44490f 100644
--- a/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs
+++ b/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs
@@ -3,8 +3,7 @@ use super::*;
#[tokio::test]
async fn thread_update_title_persists_new_title() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
@@ -29,8 +28,7 @@ async fn thread_update_title_persists_new_title() {
#[tokio::test]
async fn thread_update_title_returns_error_for_missing_thread() {
let _env_lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let workspace = tempfile::tempdir().expect("workspace");
let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());
diff --git a/crates/openhuman-core/src/tools/impl/system/shell_tests_schema_and_env_tests.rs b/crates/openhuman-core/src/tools/impl/system/shell_tests_schema_and_env_tests.rs
index c2fff0a872..c012a38fec 100644
--- a/crates/openhuman-core/src/tools/impl/system/shell_tests_schema_and_env_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/system/shell_tests_schema_and_env_tests.rs
@@ -420,7 +420,7 @@ async fn shell_missing_command_surfaces_127_with_dependency_hint() {
#[cfg(not(windows))]
#[tokio::test(flavor = "current_thread")]
async fn shell_does_not_leak_api_key() {
- let _g1 = EnvVarGuard::locked_set("API_KEY", "sk-test-secret-12345");
+ let _g1 = EnvVarGuard::locked_set_async("API_KEY", "sk-test-secret-12345").await;
let tool = ShellTool::new(test_security_with_env_cmd(), test_runtime(), test_audit());
let result = tool
diff --git a/crates/openhuman-core/src/tools/ops_tests_execution_and_serde_tests.rs b/crates/openhuman-core/src/tools/ops_tests_execution_and_serde_tests.rs
index 7637c4bf0a..78c73a07f5 100644
--- a/crates/openhuman-core/src/tools/ops_tests_execution_and_serde_tests.rs
+++ b/crates/openhuman-core/src/tools/ops_tests_execution_and_serde_tests.rs
@@ -316,8 +316,7 @@ fn all_tools_registers_brave_engine_lsp_and_tool_stats_when_enabled() {
cfg.learning.tool_tracking_enabled = true;
let _env_guard = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .blocking_lock();
unsafe {
std::env::set_var(crate::tools::implementations::LSP_ENABLED_ENV, "1");
}
diff --git a/crates/openhuman-core/src/tools/registry/ops_tests.rs b/crates/openhuman-core/src/tools/registry/ops_tests.rs
index ecc9d15dc9..75c1c2b505 100644
--- a/crates/openhuman-core/src/tools/registry/ops_tests.rs
+++ b/crates/openhuman-core/src/tools/registry/ops_tests.rs
@@ -89,8 +89,7 @@ fn diagnostics_reports_inventory_and_policy_surfaces() {
#[tokio::test]
async fn diagnostics_loads_active_capability_provider_config() {
let _lock = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
let tmp = tempfile::tempdir().expect("tempdir");
let _env = EnvVarGuard::set("OPENHUMAN_WORKSPACE", tmp.path());
std::fs::write(
diff --git a/crates/openhuman-core/src/voice/local_speech_tests.rs b/crates/openhuman-core/src/voice/local_speech_tests.rs
index 30a4433ed3..616c040498 100644
--- a/crates/openhuman-core/src/voice/local_speech_tests.rs
+++ b/crates/openhuman-core/src/voice/local_speech_tests.rs
@@ -18,7 +18,7 @@ async fn synthesize_piper_rejects_empty_text() {
async fn synthesize_piper_surfaces_binary_lookup_failure() {
// Make sure a missing PIPER_BIN
// produces an actionable error, not a panic in the spawn path.
- let _env = crate::config::test_env::EnvVarGuard::locked_unset("PIPER_BIN");
+ let _env = crate::config::test_env::EnvVarGuard::locked_unset_async("PIPER_BIN").await;
let config = Config::default();
let opts = PiperOptions::default();
diff --git a/crates/openhuman-core/src/voice/ops_tests.rs b/crates/openhuman-core/src/voice/ops_tests.rs
index 6bfd14b27e..5c2fdb555b 100644
--- a/crates/openhuman-core/src/voice/ops_tests.rs
+++ b/crates/openhuman-core/src/voice/ops_tests.rs
@@ -62,7 +62,7 @@ async fn voice_status_detects_stub_binaries() {
.expect("chmod");
}
- let _guard = EnvVarGuard::locked_set("PIPER_BIN", &piper_stub.display().to_string());
+ let _guard = EnvVarGuard::locked_set_async("PIPER_BIN", &piper_stub.display().to_string()).await;
let mut config = Config::default();
config.workspace_dir = tmp.path().join("workspace");
diff --git a/crates/openhuman-core/src/voice/postprocess_tests.rs b/crates/openhuman-core/src/voice/postprocess_tests.rs
index 50b5868d4b..c8bcf32e40 100644
--- a/crates/openhuman-core/src/voice/postprocess_tests.rs
+++ b/crates/openhuman-core/src/voice/postprocess_tests.rs
@@ -5,7 +5,7 @@ use super::*;
#[tokio::test]
async fn disabled_cleanup_returns_raw_text() {
- let _g = crate::inference::inference_test_guard();
+ let _g = crate::inference::inference_test_guard_async().await;
let mut config = Config::default();
config.local_ai.voice_llm_cleanup_enabled = false;
let service = local_ai::global(&config);
@@ -20,7 +20,7 @@ async fn enabled_but_llm_not_ready_returns_raw_text() {
// Covers the branch where cleanup is enabled in config but the
// local LLM hasn't reached the ready/degraded state yet —
// cleanup must gracefully fall back to the raw transcript.
- let _g = crate::inference::inference_test_guard();
+ let _g = crate::inference::inference_test_guard_async().await;
let config = Config::default(); // voice_llm_cleanup_enabled = true by default
let service = local_ai::global(&config);
let previous = service.replace_status_state("not_ready");
diff --git a/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs
index 6fe82fbc48..c9e08cd931 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs
@@ -301,7 +301,7 @@ async fn wedged_turn_hits_wall_clock_backstop_and_emits_turn_timeout_chat_error(
// below unwinds, this guard still clears `OPENHUMAN_WEB_TURN_TIMEOUT_SECS` so
// a 1s backstop can't leak into unrelated tests sharing this process.
let _env_guard =
- crate::config::test_env::EnvVarGuard::locked_set("OPENHUMAN_WEB_TURN_TIMEOUT_SECS", "1");
+ crate::config::test_env::EnvVarGuard::locked_set_async("OPENHUMAN_WEB_TURN_TIMEOUT_SECS", "1").await;
let block = make_block();
set_test_run_chat_task_block(Some(block.clone())).await;
@@ -546,8 +546,7 @@ fn classify_genuine_param_400_keeps_model_mismatch_copy_not_glitch() {
async fn unscoped_cancel_stops_the_threads_detached_subagents() {
let _serial = FORCED_ERROR_TEST_LOCK.lock().await;
let _registry = crate::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
+ .lock().await;
use crate::agent::orchestration::running_subagents;
let thread_id = "stop-detached-subagent-thread";
diff --git a/tests/inference_provider_e2e.rs b/tests/inference_provider_e2e.rs
index 0f8c0af56e..65e0509e47 100644
--- a/tests/inference_provider_e2e.rs
+++ b/tests/inference_provider_e2e.rs
@@ -29,15 +29,17 @@ use openhuman_rpc::server::build_core_http_router;
// this lock first to prevent races when cargo runs tests in parallel threads
// within the same process.
-static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
+static ENV_LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
static RPC_AUTH_INIT: OnceLock<()> = OnceLock::new();
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- let m = ENV_LOCK.get_or_init(|| Mutex::new(()));
- match m.lock() {
- Ok(g) => g,
- Err(p) => p.into_inner(),
- }
+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {
+ let m = ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));
+ m.blocking_lock()
+}
+
+async fn env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {
+ let m = ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));
+ m.lock().await
}
const TEST_RPC_TOKEN: &str = "inference-provider-e2e-token";
@@ -62,7 +64,7 @@ fn ensure_rpc_auth() {
#[tokio::test]
async fn http_endpoint_chat_completions_no_bearer_returns_401() {
- let _lock = env_lock();
+ let _lock = env_lock_async().await;
ensure_rpc_auth();
let body = json!({
@@ -84,7 +86,7 @@ async fn http_endpoint_chat_completions_no_bearer_returns_401() {
#[tokio::test]
async fn http_endpoint_models_no_bearer_returns_401() {
- let _lock = env_lock();
+ let _lock = env_lock_async().await;
ensure_rpc_auth();
let req = Request::builder()
@@ -101,7 +103,7 @@ async fn http_endpoint_models_no_bearer_returns_401() {
#[tokio::test]
async fn http_endpoint_models_with_bearer_returns_model_list() {
- let _lock = env_lock();
+ let _lock = env_lock_async().await;
ensure_rpc_auth();
let tmp = tempdir().expect("tempdir");
@@ -145,7 +147,7 @@ async fn http_endpoint_models_with_bearer_returns_model_list() {
#[tokio::test]
async fn http_endpoint_chat_completions_with_bearer_passes_auth() {
- let _lock = env_lock();
+ let _lock = env_lock_async().await;
ensure_rpc_auth();
let body = json!({
diff --git a/tests/keyring_secretstore_fresh_e2e.rs b/tests/keyring_secretstore_fresh_e2e.rs
index 0d8b315ba5..754555d514 100644
--- a/tests/keyring_secretstore_fresh_e2e.rs
+++ b/tests/keyring_secretstore_fresh_e2e.rs
@@ -5,9 +5,14 @@ use openhuman_core::config::schema::{Config, StreamMode, TelegramConfig};
use openhuman_core::security::keyring;
use std::sync::{Mutex, OnceLock};
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
- LOCK.get_or_init(|| Mutex::new(())).lock().unwrap()
+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {
+ static LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
+ LOCK.get_or_init(|| tokio::sync::Mutex::new(())).blocking_lock()
+}
+
+async fn env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {
+ static LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
+ LOCK.get_or_init(|| tokio::sync::Mutex::new(())).lock().await
}
fn parse_keyring_payload(json: &str) -> serde_json::Value {
@@ -16,7 +21,7 @@ fn parse_keyring_payload(json: &str) -> serde_json::Value {
#[tokio::test]
async fn config_secrets_create_master_key_in_keyring_on_fresh_install() {
- let _guard = env_lock();
+ let _guard = env_lock_async().await;
let tmp = tempfile::tempdir().expect("tempdir");
let openhuman_dir = tmp.path().join("fresh-user");
let workspace_dir = openhuman_dir.join("workspace");
diff --git a/tests/live_flows_demo_e2e.rs b/tests/live_flows_demo_e2e.rs
index 9b065d1024..6cb7533ed5 100644
--- a/tests/live_flows_demo_e2e.rs
+++ b/tests/live_flows_demo_e2e.rs
@@ -35,16 +35,18 @@ use tempfile::tempdir;
use openhuman_core::core::auth::{init_rpc_token, CORE_TOKEN_ENV_VAR};
use openhuman_rpc::server::build_core_http_router;
-static LIVE_E2E_ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
+static LIVE_E2E_ENV_LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
static LIVE_RPC_AUTH_INIT: OnceLock<()> = OnceLock::new();
const TEST_RPC_TOKEN: &str = "live-flows-demo-e2e-local-token";
-fn live_e2e_env_lock() -> std::sync::MutexGuard<'static, ()> {
- let mutex = LIVE_E2E_ENV_LOCK.get_or_init(|| Mutex::new(()));
- match mutex.lock() {
- Ok(guard) => guard,
- Err(poisoned) => poisoned.into_inner(),
- }
+fn live_e2e_env_lock() -> tokio::sync::MutexGuard<'static, ()> {
+ let mutex = LIVE_E2E_ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));
+ mutex.blocking_lock()
+}
+
+async fn live_e2e_env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {
+ let mutex = LIVE_E2E_ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));
+ mutex.lock().await
}
fn required_env(name: &str) -> String {
@@ -200,7 +202,7 @@ fn opus_sonnet_demo_graph() -> Value {
#[tokio::test]
#[ignore = "requires live backend URL + valid token"]
async fn live_flows_demo_discover_build_save_run() {
- let _env_lock = live_e2e_env_lock();
+ let _env_lock = live_e2e_env_lock_async().await;
let api_url = required_env("OPENHUMAN_LIVE_API_URL");
let token = required_env("OPENHUMAN_LIVE_TOKEN");
diff --git a/tests/live_routing_e2e.rs b/tests/live_routing_e2e.rs
index c22feb93f9..aa9a12cb62 100644
--- a/tests/live_routing_e2e.rs
+++ b/tests/live_routing_e2e.rs
@@ -29,16 +29,18 @@ use tokio::time::timeout;
use openhuman_core::core::auth::{init_rpc_token, CORE_TOKEN_ENV_VAR};
use openhuman_rpc::server::build_core_http_router;
-static LIVE_E2E_ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
+static LIVE_E2E_ENV_LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
static LIVE_RPC_AUTH_INIT: OnceLock<()> = OnceLock::new();
const TEST_RPC_TOKEN: &str = "live-routing-e2e-local-token";
-fn live_e2e_env_lock() -> std::sync::MutexGuard<'static, ()> {
- let mutex = LIVE_E2E_ENV_LOCK.get_or_init(|| Mutex::new(()));
- match mutex.lock() {
- Ok(guard) => guard,
- Err(poisoned) => poisoned.into_inner(),
- }
+fn live_e2e_env_lock() -> tokio::sync::MutexGuard<'static, ()> {
+ let mutex = LIVE_E2E_ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));
+ mutex.blocking_lock()
+}
+
+async fn live_e2e_env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {
+ let mutex = LIVE_E2E_ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));
+ mutex.lock().await
}
fn required_env(name: &str) -> String {
@@ -170,7 +172,7 @@ fn ensure_test_rpc_auth() {
#[tokio::test]
#[ignore = "requires live backend URL + valid token"]
async fn live_channel_web_chat_routing_cases_trigger_real_backend() {
- let _env_lock = live_e2e_env_lock();
+ let _env_lock = live_e2e_env_lock_async().await;
let api_url = required_env("OPENHUMAN_LIVE_API_URL");
let token = required_env("OPENHUMAN_LIVE_TOKEN");
diff --git a/tests/memory_roundtrip_e2e.rs b/tests/memory_roundtrip_e2e.rs
index 45cc157acd..a65f64da11 100644
--- a/tests/memory_roundtrip_e2e.rs
+++ b/tests/memory_roundtrip_e2e.rs
@@ -53,15 +53,16 @@ use openhuman_core::memory::rpc_models::{RecallContextRequest, RecallMemoriesReq
// ── Env isolation ────────────────────────────────────────────────────
/// Serialises tests: `HOME` + `OPENHUMAN_WORKSPACE` are process-global.
-static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
+static ENV_LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();
static TEST_ROOT: OnceLock<tempfile::TempDir> = OnceLock::new();
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- match ENV_LOCK.get_or_init(|| Mutex::new(())).lock() {
- Ok(guard) => guard,
- Err(poisoned) => poisoned.into_inner(),
- }
+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {
+ ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(())).blocking_lock()
+}
+
+async fn env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {
+ ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(())).lock().await
}
/// This integration target calls memory operations without constructing a core
@@ -138,7 +139,7 @@ fn recall_context_request() -> RecallContextRequest {
/// 8.1.1 store + 8.1.2 recall — the happy-path round-trip.
#[tokio::test]
async fn doc_put_then_recall_memories_returns_canary() {
- let _lock = env_lock();
+ let _lock = env_lock_async().await;
let tmp = test_root();
let _home = EnvVarGuard::set_to_path("HOME", tmp.path());
let workspace_path = tmp.path().join("workspace");
@@ -169,7 +170,7 @@ async fn doc_put_then_recall_memories_returns_canary() {
/// block, not only in the raw memory list view.
#[tokio::test]
async fn doc_put_then_recall_context_renders_llm_context_message() {
- let _lock = env_lock();
+ let _lock = env_lock_async().await;
let tmp = test_root();
let _home = EnvVarGuard::set_to_path("HOME", tmp.path());
let workspace_path = tmp.path().join("workspace");
@@ -200,7 +201,7 @@ async fn doc_put_then_recall_context_renders_llm_context_message() {
/// required by gitbooks/developing/testing-strategy.md.
#[tokio::test]
async fn clear_namespace_removes_canary_from_recall() {
- let _lock = env_lock();
+ let _lock = env_lock_async().await;
let tmp = test_root();
let _home = EnvVarGuard::set_to_path("HOME", tmp.path());
let workspace_path = tmp.path().join("workspace");
@@ -308,7 +309,7 @@ async fn seed_namespace(namespace: &str, count: usize) {
/// Ingesting a batch large enough to queue leaves an exact, reconciled count.
#[tokio::test]
async fn namespace_summaries_reconcile_after_a_batch_large_enough_to_queue() {
- let _lock = env_lock();
+ let _lock = env_lock_async().await;
let tmp = test_root();
let _home = EnvVarGuard::set_to_path("HOME", tmp.path());
let workspace_path = tmp.path().join("workspace");
diff --git a/tests/skills_mcp_registry_live.rs b/tests/skills_mcp_registry_live.rs
index 8ddba32f87..eb3c09c1dd 100644
--- a/tests/skills_mcp_registry_live.rs
+++ b/tests/skills_mcp_registry_live.rs
@@ -35,13 +35,18 @@ use openhuman_rpc::server::build_core_http_router;
const TEST_RPC_TOKEN: &str = "skills-mcp-live-token";
static AUTH_INIT: OnceLock<()> = OnceLock::new();
-static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
+static ENV_LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- let mutex = ENV_LOCK.get_or_init(|| Mutex::new(()));
+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {
+ let mutex = ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));
mutex
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .blocking_lock()
+}
+
+async fn env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {
+ let mutex = ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));
+ mutex
+ .lock().await
}
/// A core RPC stack over a throwaway `HOME`, with no registry overrides.
@@ -140,7 +145,7 @@ fn installed_skill_count(home: &Path) -> usize {
#[tokio::test]
#[ignore = "live: real skill catalog + SKILL.md hosts"]
async fn live_every_skill_catalog_source_offers_installable_skills() {
- let _lock = env_lock();
+ let _lock = env_lock_async().await;
let stack = live_stack().await;
let browse = rpc(
@@ -237,7 +242,7 @@ async fn live_every_skill_catalog_source_offers_installable_skills() {
#[tokio::test]
#[ignore = "live: official MCP registry + npm/pypi packages"]
async fn live_official_mcp_registry_server_declares_connects_and_answers_a_tool_call() {
- let _lock = env_lock();
+ let _lock = env_lock_async().await;
let stack = live_stack().await;
let query = std::env::var("OPENHUMAN_LIVE_MCP_QUERY").unwrap_or_else(|_| "everything".into());