The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(tests): migrate e2e test lock from std to tokio mutex
Steven Enamakel970933a32b7e
diff --git a/tests/json_rpc_e2e.rs b/tests/json_rpc_e2e.rsindex 118cd6b4ea..f0150956d3 100644--- a/tests/json_rpc_e2e.rs+++ b/tests/json_rpc_e2e.rs@@ -42,22 +42,28 @@ static JSON_RPC_AUTH_INIT: OnceLock<()> = OnceLock::new();/// Serializes tests in this binary: `HOME` / `OPENHUMAN_WORKSPACE` / backend URL overrides are/// process-global, so parallel tests would clobber each other and hit the wrong `config.toml` or/// inherited `VITE_BACKEND_URL`.-static JSON_RPC_E2E_ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();+static JSON_RPC_E2E_ENV_LOCK: OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = OnceLock::new();static JSON_RPC_E2E_KEYRING_INIT: OnceLock<()> = OnceLock::new();static JSON_RPC_E2E_MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();static CHAT_COMPLETION_MODELS: OnceLock<Mutex<Vec<String>>> = OnceLock::new();static CHAT_COMPLETION_REQUESTS: OnceLock<Mutex<Vec<Value>>> = OnceLock::new();-fn json_rpc_e2e_env_lock() -> std::sync::MutexGuard<'static, ()> {+fn json_rpc_e2e_env_lock() -> tokio::sync::MutexGuard<'static, ()> {JSON_RPC_E2E_KEYRING_INIT.get_or_init(|| unsafe {std::env::set_var("OPENHUMAN_KEYRING_BACKEND", "file");});- let mutex = JSON_RPC_E2E_ENV_LOCK.get_or_init(|| Mutex::new(()));+ let mutex = JSON_RPC_E2E_ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));// Recover from poison so that a panic in one test does not cascade to all others.- match mutex.lock() {- Ok(guard) => guard,- Err(poisoned) => poisoned.into_inner(),- }+ mutex.blocking_lock()+}++async fn json_rpc_e2e_env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {+ JSON_RPC_E2E_KEYRING_INIT.get_or_init(|| unsafe {+ std::env::set_var("OPENHUMAN_KEYRING_BACKEND", "file");+ });+ let mutex = JSON_RPC_E2E_ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));+ // Recover from poison so that a panic in one test does not cascade to all others.+ mutex.lock().await}/// The one memory workspace every case in this binary shares.@@ -1229,7 +1235,7 @@ fn ensure_test_rpc_auth() {#[tokio::test]async fn json_rpc_discovers_codex_and_claude_sessions_for_memory_ingestion() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let _home_guard = EnvVarGuard::set_to_path("HOME", home);@@ -1281,7 +1287,7 @@ async fn json_rpc_discovers_codex_and_claude_sessions_for_memory_ingestion() {#[tokio::test]async fn json_rpc_config_update_browser_settings_persists_backend() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -1351,7 +1357,7 @@ async fn json_rpc_config_update_browser_settings_persists_backend() {#[tokio::test]async fn json_rpc_reasoning_effort_persists_and_rejects_unknown_levels() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -1428,7 +1434,7 @@ async fn json_rpc_reasoning_effort_persists_and_rejects_unknown_levels() {#[tokio::test]async fn json_rpc_tokenjuice_detect_and_cache_stats() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;let rpc_base = format!("http://{rpc_addr}");@@ -1466,7 +1472,7 @@ async fn json_rpc_tokenjuice_detect_and_cache_stats() {#[tokio::test]async fn json_rpc_tokenjuice_settings_and_savings() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;let rpc_base = format!("http://{rpc_addr}");@@ -1542,7 +1548,7 @@ async fn json_rpc_tokenjuice_settings_and_savings() {#[tokio::test]async fn json_rpc_tool_registry_lists_and_gets_entries() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;let rpc_base = format!("http://{rpc_addr}");@@ -1635,7 +1641,7 @@ async fn json_rpc_tool_registry_lists_and_gets_entries() {#[tokio::test]async fn json_rpc_harness_init_status_returns_snapshot_envelope() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;let rpc_base = format!("http://{rpc_addr}");@@ -1680,7 +1686,7 @@ async fn json_rpc_harness_init_status_returns_snapshot_envelope() {#[tokio::test]async fn json_rpc_agent_registry_manages_defaults_and_custom_agents() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -2280,7 +2286,7 @@ fn json_rpc_protocol_auth_and_agent_hello() {}async fn json_rpc_protocol_auth_and_agent_hello_inner() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -2417,7 +2423,7 @@ fn json_rpc_prompt_injection_is_rejected_before_model_call() {}async fn json_rpc_prompt_injection_is_rejected_before_model_call_inner() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -2517,7 +2523,7 @@ async fn json_rpc_prompt_injection_is_rejected_before_model_call_inner() {#[tokio::test]async fn json_rpc_thread_labels_create_and_update() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -2628,7 +2634,7 @@ async fn json_rpc_thread_labels_create_and_update() {/// queued (no active turn at all, here) is a no-op, not an error — see C3.#[tokio::test]async fn json_rpc_thread_goal_and_todos_get_and_queue_remove_are_wired() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -2719,7 +2725,7 @@ async fn json_rpc_plan_review_decide_unknown_and_invalid() {// The plan-review gate is in-memory and parks a live turn; over RPC we can// still exercise the decision surface: deciding an unknown/expired request// resolves nothing (`resolved: false`), and an invalid decision errors.- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -2778,7 +2784,7 @@ async fn json_rpc_plan_review_decide_unknown_and_invalid() {#[tokio::test]async fn json_rpc_thread_title_create_and_update() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -2872,7 +2878,7 @@ async fn json_rpc_thread_title_create_and_update() {#[tokio::test]async fn json_rpc_thread_not_found_errors_are_structured() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -2939,7 +2945,7 @@ async fn json_rpc_thread_not_found_errors_are_structured() {#[tokio::test]async fn json_rpc_thread_generate_title_falls_back_when_provider_path_is_unavailable() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -3048,7 +3054,7 @@ async fn json_rpc_thread_generate_title_falls_back_when_provider_path_is_unavail#[tokio::test]async fn json_rpc_thread_turn_state_lifecycle() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -3255,7 +3261,7 @@ async fn json_rpc_thread_turn_state_lifecycle() {#[tokio::test]async fn json_rpc_run_ledger_lifecycle() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -3372,7 +3378,7 @@ async fn json_rpc_run_ledger_lifecycle() {#[tokio::test]async fn json_rpc_agent_work_list_groups_runs_by_bucket() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -3478,7 +3484,7 @@ async fn json_rpc_agent_work_list_groups_runs_by_bucket() {#[tokio::test]async fn json_rpc_workflow_run_definitions_and_runs_roundtrip() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -3583,7 +3589,7 @@ async fn json_rpc_workflow_run_definitions_and_runs_roundtrip() {#[tokio::test]async fn json_rpc_agent_team_coordination_roundtrip() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -3929,7 +3935,7 @@ async fn json_rpc_agent_team_coordination_roundtrip() {#[tokio::test]async fn json_rpc_memory_sync_and_learn() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -4148,7 +4154,7 @@ async fn json_rpc_memory_sync_and_learn() {#[tokio::test]async fn json_rpc_memory_tree_end_to_end() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -4333,7 +4339,7 @@ async fn json_rpc_memory_tree_end_to_end() {/// exercises the not-yet-sealed (no Tree row) raw-leaf fallback end to end.#[tokio::test]async fn json_rpc_memory_tree_cover_window_end_to_end() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -4456,7 +4462,7 @@ fn json_rpc_web_chat_routing_cases_use_expected_backend_models() {}async fn json_rpc_web_chat_routing_cases_use_expected_backend_models_inner() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -4830,7 +4836,7 @@ fn json_rpc_web_chat_custom_chat_provider_with_auth_none_omits_auth_header() {}async fn json_rpc_web_chat_custom_chat_provider_with_auth_none_omits_auth_header_inner() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -4996,7 +5002,7 @@ async fn json_rpc_web_chat_custom_chat_provider_with_auth_none_omits_auth_header#[tokio::test]async fn json_rpc_rejects_non_object_params_with_clear_error() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -5037,7 +5043,7 @@ async fn json_rpc_rejects_non_object_params_with_clear_error() {#[tokio::test]async fn json_rpc_removed_screen_intelligence_methods_are_not_found() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -5070,7 +5076,7 @@ async fn json_rpc_removed_screen_intelligence_methods_are_not_found() {#[tokio::test]async fn json_rpc_app_state_snapshot_returns_runtime_shape() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -5157,7 +5163,7 @@ async fn json_rpc_app_state_snapshot_returns_runtime_shape() {#[tokio::test]async fn json_rpc_wallet_setup_round_trips_status() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -5265,7 +5271,7 @@ async fn json_rpc_wallet_setup_round_trips_status() {#[tokio::test]#[ignore = "drives the loaded wallet module; run alone with an installed tinywallet artifact"]async fn json_rpc_wallet_execution_surface_round_trips() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -5554,7 +5560,7 @@ async fn json_rpc_wallet_execution_surface_round_trips() {/// chain are rejected before any network call).#[tokio::test]async fn json_rpc_wallet_tx_reads_and_web3_gates_round_trip() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -5980,7 +5986,7 @@ async fn wallet_setup_via_rpc(rpc_base: &str, encrypted_mnemonic: &str) {#[tokio::test]#[ignore = "drives the loaded wallet module; run alone with an installed tinywallet artifact"]async fn json_rpc_wallet_evm_base_network_prepare_execute_round_trips() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -6065,7 +6071,7 @@ async fn json_rpc_wallet_evm_base_network_prepare_execute_round_trips() {#[tokio::test]#[ignore = "drives the loaded wallet module; run alone with an installed tinywallet artifact"]async fn json_rpc_wallet_btc_prepare_execute_round_trips() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -6157,7 +6163,7 @@ async fn json_rpc_wallet_btc_prepare_execute_round_trips() {/// Solana: native SOL transfer end-to-end through controllers.#[tokio::test]async fn json_rpc_wallet_solana_prepare_execute_round_trips() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -6227,7 +6233,7 @@ async fn json_rpc_wallet_solana_prepare_execute_round_trips() {#[tokio::test]#[ignore = "drives the loaded wallet module; run alone with an installed tinywallet artifact"]async fn json_rpc_wallet_tron_prepare_execute_round_trips() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -6316,7 +6322,7 @@ async fn json_rpc_wallet_tron_prepare_execute_round_trips() {#[tokio::test]#[ignore = "drives the loaded wallet module; run alone with an installed tinywallet artifact"]async fn json_rpc_wallet_tron_trc20_prepare_execute_round_trips() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -6406,7 +6412,7 @@ async fn json_rpc_wallet_tron_trc20_prepare_execute_round_trips() {/// Solana, and Tron, with chain_id populated for EVM rows.#[tokio::test]async fn json_rpc_wallet_network_defaults_lists_all_chains() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -6471,7 +6477,7 @@ async fn json_rpc_wallet_network_defaults_lists_all_chains() {/// (its serde default). The field is deprecated but still surfaced for backward compat.#[tokio::test]async fn json_rpc_app_state_snapshot_chat_onboarding_defaults_false() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -6535,7 +6541,7 @@ encrypt = false/// `unreachable` and no runtime binary on PATH may have been executed.#[tokio::test]async fn json_rpc_inference_status_reports_unreachable_without_spawning_a_runtime() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -6712,7 +6718,7 @@ async fn json_rpc_inference_status_reports_unreachable_without_spawning_a_runtim/// whatever that floor is gets `below_minimum` and one over it gets `ok`.#[tokio::test]async fn json_rpc_local_ai_ollama_diagnostics_rejects_a_short_context_model() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -6876,7 +6882,7 @@ async fn json_rpc_local_ai_ollama_diagnostics_rejects_a_short_context_model() {#[tokio::test]async fn json_rpc_local_ai_lm_studio_config_diagnostics_and_prompt() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -7027,7 +7033,7 @@ async fn json_rpc_local_ai_lm_studio_config_diagnostics_and_prompt() {#[tokio::test]async fn json_rpc_local_ai_ollama_endpoint_normalizes_bind_address_and_clears() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -7087,7 +7093,7 @@ async fn json_rpc_local_ai_ollama_endpoint_normalizes_bind_address_and_clears()#[tokio::test]async fn json_rpc_inference_namespace_lm_studio_prompt_and_status() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -7256,7 +7262,7 @@ async fn json_rpc_inference_namespace_lm_studio_prompt_and_status() {#[tokio::test]async fn json_rpc_inference_prompt_requires_external_ollama_runtime_when_unreachable() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -7324,7 +7330,7 @@ async fn json_rpc_inference_prompt_requires_external_ollama_runtime_when_unreach/// exactly as the desktop app or a CI script would.#[tokio::test]async fn billing_rpc_e2e() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -7474,7 +7480,7 @@ async fn billing_rpc_e2e() {/// session JWT, then exercises every team controller through the RPC surface.#[tokio::test]async fn team_rpc_e2e() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -7605,7 +7611,7 @@ async fn team_rpc_e2e() {#[tokio::test]async fn about_app_rpc_list_lookup_and_search() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -7717,7 +7723,7 @@ async fn about_app_rpc_list_lookup_and_search() {#[tokio::test]async fn voice_status_returns_availability() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -7782,7 +7788,7 @@ async fn voice_status_returns_availability() {#[tokio::test]async fn notification_settings_roundtrip_and_disabled_ingest_skip() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -7873,7 +7879,7 @@ async fn credentials_crud_roundtrip() {//// Provider credentials are stored locally (auth-profiles.json) and require// no upstream network calls, so no mock session/JWT is needed.- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -8018,7 +8024,7 @@ async fn credentials_crud_roundtrip() {/// (controller registration, param decoding, response shape) was not.#[tokio::test]async fn skills_uninstall_rpc_e2e() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();@@ -8126,7 +8132,7 @@ async fn skills_uninstall_rpc_e2e() {/// POST /rpc without any Authorization header → 401 with error=unauthorized.#[tokio::test]async fn rpc_rejects_unauthenticated_request() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth();let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;@@ -8153,7 +8159,7 @@ async fn rpc_rejects_unauthenticated_request() {/// POST /rpc with a syntactically valid but wrong bearer token → 401.#[tokio::test]async fn rpc_rejects_wrong_token() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth();let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;@@ -8184,7 +8190,7 @@ async fn rpc_rejects_wrong_token() {/// headers) so the assertion is `!= 401`, not `.is_success()`.#[tokio::test]async fn public_paths_accessible_without_token() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth();let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;@@ -8263,7 +8269,7 @@ async fn public_paths_accessible_without_token() {/// GET /events/webhooks with neither header nor query token → 401.#[tokio::test]async fn webhook_sse_rejects_unauthenticated() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth();let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;@@ -8290,7 +8296,7 @@ async fn webhook_sse_rejects_unauthenticated() {/// `encodeURIComponent(null)` / `encodeURIComponent("")` mishaps on the FE.#[tokio::test]async fn webhook_sse_rejects_empty_query_token() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth();let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;@@ -8310,7 +8316,7 @@ async fn webhook_sse_rejects_empty_query_token() {/// GET /events/webhooks?token=garbage → 401.#[tokio::test]async fn webhook_sse_rejects_wrong_query_token() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth();let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;@@ -8335,7 +8341,7 @@ async fn webhook_sse_rejects_wrong_query_token() {/// GET /events/webhooks?token=<valid> → 200 (SSE stream opens).#[tokio::test]async fn webhook_sse_accepts_valid_query_token() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth();let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;@@ -8373,7 +8379,7 @@ async fn webhook_sse_accepts_valid_query_token() {/// when the token itself is hex-only).#[tokio::test]async fn webhook_sse_accepts_percent_encoded_query_token() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth();let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;@@ -8413,7 +8419,7 @@ async fn webhook_sse_accepts_percent_encoded_query_token() {/// CLI / non-browser callers should still be able to subscribe the header way.#[tokio::test]async fn webhook_sse_accepts_valid_bearer_header() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth();let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;@@ -8438,7 +8444,7 @@ async fn webhook_sse_accepts_valid_bearer_header() {/// Simulate an external process using a guessed token — must be rejected.#[tokio::test]async fn external_process_with_guessed_token_is_rejected() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth(); // server validates against TEST_RPC_TOKENlet (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;@@ -8471,7 +8477,7 @@ async fn external_process_with_guessed_token_is_rejected() {#[tokio::test]async fn rpc_update_apply_can_be_disabled_by_config_policy() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;ensure_test_rpc_auth();let tmp = tempdir().expect("tempdir");@@ -8542,7 +8548,7 @@ async fn rpc_update_apply_can_be_disabled_by_config_policy() {/// the transport layer, not just at the unit level.#[tokio::test]async fn channels_status_reflects_managed_dm_credential_e2e() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -8635,7 +8641,7 @@ async fn channels_status_reflects_managed_dm_credential_e2e() {#[tokio::test]async fn whatsapp_memory_doc_ingest_e2e() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -8754,7 +8760,7 @@ async fn whatsapp_memory_doc_ingest_e2e() {/// which proves the method is wired all the way through.#[tokio::test]async fn voice_cloud_transcribe_registered_e2e() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -8830,7 +8836,7 @@ async fn voice_cloud_transcribe_registered_e2e() {#[tokio::test]async fn mcp_clients_lifecycle() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -8972,7 +8978,7 @@ async fn mcp_clients_lifecycle() {/// is how a user adds any server now — the registry is browse-only.#[tokio::test]async fn mcp_clients_declare_connect_tool_call_happy_path() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -9143,7 +9149,7 @@ async fn mcp_clients_declare_connect_tool_call_happy_path() {/// and asserts the response carries `enabled=false` (issue #3196).#[tokio::test]async fn mcp_clients_set_enabled_smoke() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -9227,7 +9233,7 @@ async fn mcp_clients_set_enabled_smoke() {/// removes that one value; (d) dropping the entry uninstalls the server.#[tokio::test]async fn mcp_clients_config_round_trip_merges_credentials_and_removes_absent_servers() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -9409,7 +9415,7 @@ async fn installed_server_id(rpc_base: &str, id: i64, name: &str) -> String {/// gap A6).#[tokio::test]async fn mcp_clients_registry_settings_roundtrip() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -9526,7 +9532,7 @@ async fn mcp_clients_registry_settings_roundtrip() {#[tokio::test]async fn json_rpc_config_autonomy_settings_roundtrip() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -9705,7 +9711,7 @@ async fn json_rpc_config_autonomy_settings_roundtrip() {/// uses), with the same bounds the UI shows and a validation error on garbage.#[tokio::test]async fn json_rpc_config_agent_timeout_settings_roundtrip() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -9838,7 +9844,7 @@ async fn json_rpc_config_agent_timeout_settings_roundtrip() {#[tokio::test]async fn port_conflict_recovery_core_starts_on_fallback_port_e2e() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;// ── 1. occupy port 7788 with a dummy listener ─────────────────────────// Use std::net so the binding is synchronous and stable before we call@@ -9934,7 +9940,7 @@ async fn port_conflict_recovery_core_starts_on_fallback_port_e2e() {/// rather than hanging.#[tokio::test]async fn json_rpc_task_sources_crud_and_status() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -10094,7 +10100,7 @@ async fn json_rpc_task_sources_crud_and_status() {/// end to end over RPC rather than a successful fetch.#[tokio::test]async fn json_rpc_task_sources_fetch_pipeline_e2e() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -10235,7 +10241,7 @@ async fn json_rpc_task_sources_fetch_pipeline_e2e() {/// `HOME` isolates per-test.#[tokio::test]async fn json_rpc_workflows_lifecycle_round_trip() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -10419,7 +10425,7 @@ fn approval_gated_graph_json() -> Value {#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_lifecycle_round_trip() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;// 1. Create an approval-gated flow.@@ -10643,7 +10649,7 @@ async fn json_rpc_flows_lifecycle_round_trip() {#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_run_detached_returns_before_run_completes() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;// 1. Create a trivial, immediately-completable flow.@@ -10757,7 +10763,7 @@ async fn json_rpc_flows_run_detached_returns_before_run_completes() {#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_update_forces_require_approval_on_side_effect_graph() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;// 1. Create a trigger-only (read-only) flow with require_approval: false.@@ -10852,7 +10858,7 @@ async fn json_rpc_flows_update_forces_require_approval_on_side_effect_graph() {#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_suggestion_lifecycle_methods_are_wired() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;// Empty to start.@@ -11046,7 +11052,7 @@ fn json_rpc_flows_full_arc_discover_build_create_run() {#[cfg(feature = "flows")]async fn json_rpc_flows_full_arc_discover_build_create_run_inner() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;// Drain the scripted-completion FIFO even if an assertion below panics, so a// leftover entry can't bleed into another test sharing this binary.let _fifo_guard = ScriptedFifoGuard;@@ -11291,7 +11297,7 @@ async fn json_rpc_flows_full_arc_discover_build_create_run_inner() {#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_resume_deny_routes_to_error_port() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;let graph = json!({@@ -11380,7 +11386,7 @@ async fn json_rpc_flows_resume_deny_routes_to_error_port() {#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_validate_reports_warnings_and_errors() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;// 1. Webhook trigger — structurally valid, but does not fire yet → warning.@@ -11521,7 +11527,7 @@ async fn json_rpc_flows_validate_reports_warnings_and_errors() {#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_import_native_and_n8n() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;// 1. Native import — a valid tinyflows graph, warning-free.@@ -11633,7 +11639,7 @@ async fn json_rpc_flows_import_native_and_n8n() {#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_list_connections_aggregates_secret_free() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;// Seed an HTTP credential through the same encrypted-at-rest store the op@@ -11698,7 +11704,7 @@ fn json_rpc_channel_web_chat_with_speak_reply_invokes_reply_speech() {}async fn json_rpc_channel_web_chat_with_speak_reply_invokes_reply_speech_inner() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -11815,7 +11821,7 @@ async fn json_rpc_channel_web_chat_with_speak_reply_invokes_reply_speech_inner()/// "unknown param 'always_on_enabled'" before reaching the handler).#[tokio::test]async fn json_rpc_voice_server_settings_roundtrip_always_on_and_wake_word() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -11896,7 +11902,7 @@ async fn json_rpc_voice_server_settings_roundtrip_always_on_and_wake_word() {/// persists → switch to Manual only → confirm the flag flips.#[tokio::test]async fn json_rpc_memory_sync_settings_roundtrip_interval_and_manual() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -12029,7 +12035,7 @@ async fn json_rpc_memory_sync_settings_roundtrip_interval_and_manual() {/// layer by `env_overlay_memory_sync_interval_parses_and_honours_zero`.)#[tokio::test]async fn json_rpc_memory_sync_settings_env_override_is_reflected() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -12078,7 +12084,7 @@ async fn json_rpc_memory_sync_settings_env_override_is_reflected() {#[tokio::test]async fn json_rpc_memory_sources_conversation_crud() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let _home_guard = EnvVarGuard::set_to_path("HOME", home);@@ -12213,7 +12219,7 @@ async fn json_rpc_memory_sources_conversation_crud() {/// unsummarised with no way to see or repair it.#[tokio::test]async fn json_rpc_memory_sources_reconcile_reports_pending_raw_files() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let _home_guard = EnvVarGuard::set_to_path("HOME", home);@@ -12404,7 +12410,7 @@ fn memory_sources_from_list(result: &Value) -> &Vec<Value> {/// mock Composio `/connected_accounts` endpoint.#[tokio::test]async fn json_rpc_memory_sources_list_filters_to_active_connections() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -12507,7 +12513,7 @@ async fn json_rpc_memory_sources_list_filters_to_active_connections() {/// inactive".#[tokio::test]async fn json_rpc_memory_sources_list_shows_all_when_scan_unavailable() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -12575,7 +12581,7 @@ fn mock_composio_two_gmail_accounts_router() -> Router {/// from the active scan) is still hidden.#[tokio::test]async fn json_rpc_memory_sources_list_keeps_multiple_active_connections_per_toolkit() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -12670,7 +12676,7 @@ fn json_rpc_workflow_run_engine_executes_builtin_to_completion() {}async fn json_rpc_workflow_run_engine_executes_builtin_to_completion_inner() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -12815,7 +12821,7 @@ fn json_rpc_agent_team_live_member_run_roundtrip() {/// quality gate with the worker output as evidence, and returns to idle —/// surfaced by polling `agent_team_get`.async fn json_rpc_agent_team_live_member_run_roundtrip_inner() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -13120,7 +13126,7 @@ async fn poll_team_members_status(/// the composer footer seeds itself from when a thread is selected.#[tokio::test]async fn json_rpc_threads_token_usage_reads_persisted_thread_totals() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -13309,7 +13315,7 @@ fn seed_raw_transcript(workspace: &Path, stem: &str, thread_id: &str, body: &[&s#[tokio::test]async fn json_rpc_threads_transcript_get_projects_and_paginates() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");// Config resolves the runtime workspace to `OPENHUMAN_WORKSPACE/workspace`// (see resolve_config_dir_for_workspace), so seed transcripts there.@@ -13526,7 +13532,7 @@ async fn memory_flavour_agent_tool_e2e_5172() {use openhuman_core::tools::MemoryFlavourTool;use tinytools::Tool;- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let mut cfg = Config::default();cfg.workspace_dir = tmp.path().to_path_buf();@@ -13571,7 +13577,7 @@ async fn memory_flavour_agent_tool_e2e_5172() {/// so a change that deleted too much fails here rather than passing quietly.#[tokio::test]async fn json_rpc_memory_diff_surface_is_gone_and_memory_still_answers() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -13714,7 +13720,7 @@ async fn auth_store_provider_credentials_writes_an_owner_only_store_file() {return;}- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -13794,7 +13800,7 @@ async fn auth_store_provider_credentials_writes_an_owner_only_store_file() {/// the handler reports success without calling a provider.#[tokio::test]async fn voice_test_provider_honours_validate_only_for_the_stt_workload() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -13960,7 +13966,7 @@ fn strict_create_refusal(response: &Value) -> Option<String> {#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_strict_create_refuses_binding_to_undeclared_agent_field() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;let create = post_json_rpc(@@ -14000,7 +14006,7 @@ async fn json_rpc_flows_strict_create_refuses_binding_to_undeclared_agent_field(#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_strict_create_accepts_binding_to_schemaless_agent() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;let create = post_json_rpc(@@ -14046,7 +14052,7 @@ async fn json_rpc_flows_strict_create_accepts_binding_to_schemaless_agent() {#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_strict_create_accepts_prose_prompt_beside_real_messages() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;let create = post_json_rpc(@@ -14093,7 +14099,7 @@ async fn json_rpc_flows_strict_create_accepts_prose_prompt_beside_real_messages(#[cfg(feature = "flows")]#[tokio::test]async fn json_rpc_flows_strict_create_still_refuses_prose_prompt_without_messages() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;let create = post_json_rpc(@@ -14147,7 +14153,7 @@ async fn json_rpc_flows_strict_create_still_refuses_prose_prompt_without_message/// `migration_helpers::ops_tests::apply_refuses_and_names_the_build_when_no_memory_module_is_compiled_in`.#[tokio::test]async fn json_rpc_migrate_hermes_refuses_null_driver_without_naming_openclaw() {- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -14267,7 +14273,7 @@ async fn json_rpc_agent_run_mode_set_and_get_round_trip() {// thread's Plan/Build mode through the per-thread `RunModeHandle`// registry (`agent::tinyagents::run_mode`) — no thread/session bootstrap// needed since the registry is a bare thread_id-keyed map.- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -14351,7 +14357,7 @@ async fn json_rpc_agent_context_breakdown_default_agent_returns_sections() {// system/tools sections as a stacked-bar-friendly list. Called with no// params it must default `agent_id` to "orchestrator" and still work// against a bare `write_min_config` setup (no thread bootstrap needed).- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -14416,7 +14422,7 @@ async fn json_rpc_commands_list_merges_builtins() {// `commands.list` (wire method `openhuman.commands_list`, no params) must// at least surface the fixed built-in slash commands (skills.list /// flows.list are best-effort and may be empty in this bare setup).- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -14504,7 +14510,7 @@ async fn json_rpc_threads_edit_message_truncates_and_restarts_turn_inner() {// (which does have a reply, per the module's own doc comment on the// "editing the newest unanswered message" gap), and verifies the store// was actually mutated rather than just accepting the RPC.- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");@@ -14713,7 +14719,7 @@ async fn json_rpc_threads_regenerate_truncates_and_restarts_turn_inner() {// the old reply from the message log, then restarts with the same user// prompt. Verifies the old reply id is gone and a fresh one appears once// the new turn completes.- let _env_lock = json_rpc_e2e_env_lock();+ let _env_lock = json_rpc_e2e_env_lock_async().await;let tmp = tempdir().expect("tempdir");let home = tmp.path();let openhuman_home = home.join(".openhuman");diff --git a/tests/raw_coverage/agent_orchestration_e2e.rs b/tests/raw_coverage/agent_orchestration_e2e.rsindex 9cd710ec04..9bc29fbc37 100644--- a/tests/raw_coverage/agent_orchestration_e2e.rs+++ b/tests/raw_coverage/agent_orchestration_e2e.rs@@ -43,13 +43,18 @@ static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();/// The crate-wide env lock, not a private one. Every aggregated suite in/// `raw_coverage_all` shares one process, so libtest runs them concurrently/// and a lock local to this file would isolate nothing.-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .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}/// Initialise the process RPC token (idempotent) and return the bearer the@@ -274,7 +279,7 @@ fn str_at<'a>(value: &'a Value, pointer: &str) -> &'a str {/// either way is that after a stop the run is **not** `running`.#[tokio::test]async fn workflow_run_stop_then_resume_preserves_the_phase_ledger() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let started = h@@ -403,7 +408,7 @@ async fn workflow_run_stop_then_resume_preserves_the_phase_ledger() {/// is nothing to resume, and the caller asked for something specific).#[tokio::test]async fn workflow_run_stop_is_idempotent_where_resume_is_not() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let stopped = h@@ -464,7 +469,7 @@ async fn workflow_run_stop_is_idempotent_where_resume_is_not() {/// rather than as a missing run.#[tokio::test]async fn agent_work_control_validates_verb_and_message_before_touching_the_ledger() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let unknown_verb = h@@ -557,7 +562,7 @@ async fn agent_work_control_validates_verb_and_message_before_touching_the_ledge/// bucket to the other.#[tokio::test]async fn agent_team_close_flips_the_status_the_list_filter_selects_on() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let created = h@@ -696,7 +701,7 @@ async fn agent_team_close_flips_the_status_the_list_filter_selects_on() {/// a wrongly typed pagination field must not silently become "all teams".#[tokio::test]async fn agent_team_list_and_close_reject_malformed_input() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let bad_limit = h@@ -756,7 +761,7 @@ async fn agent_team_list_and_close_reject_malformed_input() {/// further and says *why* it did nothing.#[tokio::test]async fn subagent_steer_honours_and_defaults_the_queue_mode() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let collect = h@@ -825,7 +830,7 @@ fn experience(id: &str, summary: &str, lesson: &str, tools: &[&str], tags: &[&st/// retrieval **without** deleting it.#[tokio::test]async fn agent_experience_capture_list_retrieve_and_dismiss_round_trip() {- let _lock = env_lock();+ let _lock = env_lock_async().await;ensure_memory_seams();let h = setup().await;@@ -1007,7 +1012,7 @@ async fn agent_experience_capture_list_retrieve_and_dismiss_round_trip() {/// instead of being defaulted into a silently wrong record.#[tokio::test]async fn agent_experience_controllers_reject_malformed_params() {- let _lock = env_lock();+ let _lock = env_lock_async().await;ensure_memory_seams();let h = setup().await;diff --git a/tests/raw_coverage/automation_scheduling_e2e.rs b/tests/raw_coverage/automation_scheduling_e2e.rsindex 59fabac2ab..4f48ded935 100644--- a/tests/raw_coverage/automation_scheduling_e2e.rs+++ b/tests/raw_coverage/automation_scheduling_e2e.rs@@ -37,13 +37,18 @@ static AUTH_INIT: OnceLock<()> = OnceLock::new();/// The crate-wide env lock, not a private one. Every aggregated suite in/// `raw_coverage_all` shares one process, so libtest runs them concurrently/// and a lock local to this file would isolate nothing.-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .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}/// Initialise the process RPC token (idempotent) and return the bearer the@@ -259,7 +264,7 @@ fn str_at<'a>(value: &'a Value, pointer: &str) -> &'a str {/// that completes without a model.#[tokio::test]async fn cron_run_records_history_and_remove_is_not_idempotent() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let job = h@@ -404,7 +409,7 @@ async fn cron_run_records_history_and_remove_is_not_idempotent() {/// `~/tinyhuman/bugs/e2e-wave-task_sources-fetch-pipeline-unavailable.md`.#[tokio::test]async fn task_sources_sync_reports_one_outcome_per_enabled_source() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let empty = h.ok(2201, "openhuman.task_sources_sync", json!({})).await;@@ -498,7 +503,7 @@ async fn task_sources_sync_reports_one_outcome_per_enabled_source() {/// `~/tinyhuman/bugs/e2e-wave-task_sources-fetch-pipeline-unavailable.md`.#[tokio::test]async fn task_sources_list_databases_is_unavailable_for_every_provider() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;for (id, provider) in [@@ -575,7 +580,7 @@ fn write_user_hooks(home: &Path) {/// real moment.#[tokio::test]async fn hooks_reload_list_and_test_round_trip_a_deny_rule() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;// Before the file exists, reload must produce an empty, warning-free config@@ -759,7 +764,7 @@ async fn hooks_reload_list_and_test_round_trip_a_deny_rule() {/// does — the endpoint exists so an author never has to guess.#[tokio::test]async fn hooks_test_rejects_unknown_events_and_malformed_payloads() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let unknown = h@@ -805,7 +810,7 @@ async fn hooks_test_rejects_unknown_events_and_malformed_payloads() {/// believes that file is running, so `list` must say why it is not.#[tokio::test]async fn hooks_reload_surfaces_a_malformed_file_as_a_warning() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let dir = h.home().join(".openhuman");@@ -845,7 +850,7 @@ async fn hooks_reload_surfaces_a_malformed_file_as_a_warning() {/// not.#[tokio::test]async fn harness_init_run_completes_offline_and_force_bypasses_the_probes() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let snapshot = h.ok(2701, "openhuman.harness_init_run", json!({})).await;diff --git a/tests/raw_coverage/channels_round26_raw_coverage_e2e.rs b/tests/raw_coverage/channels_round26_raw_coverage_e2e.rsindex 65eb303eb0..48f6f95c54 100644--- a/tests/raw_coverage/channels_round26_raw_coverage_e2e.rs+++ b/tests/raw_coverage/channels_round26_raw_coverage_e2e.rs@@ -136,16 +136,21 @@ async fn telegram_media()}-fn env_lock() -> std::sync::MutexGuard<'static, ()> {- static LOCK: &std::sync::OnceLock<std::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;- LOCK.get_or_init(|| std::sync::Mutex::new(()))- .lock()- .unwrap_or_else(|e| e.into_inner())+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {+ static LOCK: &std::sync::OnceLock<tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;+ LOCK.get_or_init(|| tokio::sync::Mutex::new(()))+ .blocking_lock()+}++async fn env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {+ static LOCK: &std::sync::OnceLock<tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;+ LOCK.get_or_init(|| tokio::sync::Mutex::new(()))+ .lock().await}#[tokio::test]async fn telegram_loopback_covers_reaction_text_fallback_and_media_send_paths() {- let _env = env_lock();+ let _env = env_lock_async().await;let (base, state) = spawn_telegram_mock().await;let _guard = EnvVarGuard::set("OPENHUMAN_TELEGRAM_BOT_API_BASE", base);let _legacy_guard = EnvVarGuard::unset("OPENHUMAN_TELEGRAM_API_BASE");diff --git a/tests/raw_coverage/composio_raw_coverage_e2e.rs b/tests/raw_coverage/composio_raw_coverage_e2e.rsindex 82f93074eb..6553a653e9 100644--- a/tests/raw_coverage/composio_raw_coverage_e2e.rs+++ b/tests/raw_coverage/composio_raw_coverage_e2e.rs@@ -21,7 +21,7 @@ use openhuman_core::integrations::composio::{use tinytools::Tool;-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;#[tokio::test]async fn composio_connected_integrations_public_helpers_handle_empty_auth_and_identity_edges() {diff --git a/tests/raw_coverage/connectivity_raw_coverage_e2e.rs b/tests/raw_coverage/connectivity_raw_coverage_e2e.rsindex a30924553f..3be5a12542 100644--- a/tests/raw_coverage/connectivity_raw_coverage_e2e.rs+++ b/tests/raw_coverage/connectivity_raw_coverage_e2e.rs@@ -22,7 +22,7 @@ use openhuman_rpc::server::build_core_http_router;const TEST_RPC_TOKEN: &str = "connectivity-raw-coverage-e2e-token";static AUTH_INIT: OnceLock<()> = OnceLock::new();-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;struct TestHarness {_tmp: TempDir,@@ -46,12 +46,14 @@ impl Drop for ProbeListener {}}-fn env_lock() -> std::sync::MutexGuard<'static, ()> {- let mutex = ENV_LOCK.get_or_init(|| Mutex::new(()));- match mutex.lock() {- Ok(guard) => guard,- Err(poisoned) => poisoned.into_inner(),- }+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {+ let mutex = ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));+ mutex.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}fn ensure_rpc_auth() {@@ -211,7 +213,7 @@ fn spawn_probe_listener_from(#[tokio::test]async fn connectivity_diag_rpc_reports_live_listener_port_and_process() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;let rpc_port = harness.rpc_base@@ -249,7 +251,7 @@ async fn connectivity_diag_rpc_reports_live_listener_port_and_process() {#[tokio::test]async fn pick_listen_port_identifies_ipv6_openhuman_listener_when_supported() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let Some(probe) =try_spawn_probe_listener_on("::1", "200 OK", r#"{"name":"openhuman","ok":true}"#).awaitelse {diff --git a/tests/raw_coverage/flows_lifecycle_e2e.rs b/tests/raw_coverage/flows_lifecycle_e2e.rsindex 077f31d950..3343d61fde 100644--- a/tests/raw_coverage/flows_lifecycle_e2e.rs+++ b/tests/raw_coverage/flows_lifecycle_e2e.rs@@ -44,16 +44,21 @@ static AUTH_INIT: OnceLock<()> = OnceLock::new();/// The crate-wide env lock, not a private one. Every aggregated suite in/// `raw_coverage_all` shares one process, so libtest runs them concurrently/// and a lock local to this file would isolate nothing.-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;/// Serializes every case in this binary: `HOME` and the backend-URL overrides/// are process-global, so two cases running in parallel would resolve each/// other's `config.toml` and each other's flows database.-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .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}/// Initialise the process RPC token (idempotent) and return the bearer the@@ -256,7 +261,7 @@ fn str_at<'a>(value: &'a Value, pointer: &str) -> &'a str {/// the draft, so the draft store is empty afterwards and the flow store is not.#[tokio::test]async fn flows_draft_surface_round_trips_and_promotes_into_a_saved_flow() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let draft = h@@ -407,7 +412,7 @@ async fn flows_draft_surface_round_trips_and_promotes_into_a_saved_flow() {/// first, and honour its limit.#[tokio::test]async fn flows_list_all_runs_spans_flows_and_prune_reports_the_retention_cap() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let first = h@@ -505,7 +510,7 @@ async fn flows_list_all_runs_spans_flows_and_prune_reports_the_retention_cap() {/// is not an error), while a contract fetch for a named action is.#[tokio::test]async fn flows_tool_catalog_surface_degrades_without_composio_credentials() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let search = h@@ -601,7 +606,7 @@ async fn flows_tool_catalog_surface_degrades_without_composio_credentials() {/// Stop must never kill a newer turn.#[tokio::test]async fn flows_build_cancel_reports_no_turn_in_flight_without_erroring() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let h = setup().await;let unscoped = hdiff --git a/tests/raw_coverage/inference_local_admin_raw_coverage_e2e.rs b/tests/raw_coverage/inference_local_admin_raw_coverage_e2e.rsindex 6bf66ab444..1ad056ab1c 100644--- a/tests/raw_coverage/inference_local_admin_raw_coverage_e2e.rs+++ b/tests/raw_coverage/inference_local_admin_raw_coverage_e2e.rs@@ -41,17 +41,23 @@ struct MockState {/// unavailable while another points it at a mock and asserts it is available./// Each env-mutating test holds this guard for its whole body; declaring it/// before any `EnvVarGuard` makes it drop last, after the env is restored.-fn env_lock() -> MutexGuard<'static, ()> {- static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {+ static ENV_LOCK: &OnceLock<tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .get_or_init(|| tokio::sync::Mutex::new(()))+ .blocking_lock()+}++async fn env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {+ static ENV_LOCK: &OnceLock<tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;+ ENV_LOCK+ .get_or_init(|| tokio::sync::Mutex::new(()))+ .lock().await}#[tokio::test]async fn local_admin_covers_diagnostics_and_endpoint_probe_without_spawning() {- let _env_guard = env_lock();+ let _env_guard = env_lock_async().await;let (base, state) = serve_mock().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);@@ -119,7 +125,7 @@ async fn local_admin_covers_diagnostics_and_endpoint_probe_without_spawning() {#[tokio::test]async fn provider_model_listing_covers_local_synthesis_and_openrouter_failures() {- let _env_guard = env_lock();+ let _env_guard = env_lock_async().await;let (base, _state) = serve_mock().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);@@ -193,7 +199,7 @@ async fn provider_model_listing_covers_local_synthesis_and_openrouter_failures()#[tokio::test]async fn local_admin_reports_unhealthy_runtime_and_lm_studio_issue_shapes() {- let _env_guard = env_lock();+ let _env_guard = env_lock_async().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);config.local_ai.runtime_enabled = true;diff --git a/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rs b/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rsindex f7dfb1eaa7..057864ccad 100644--- a/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rs+++ b/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rs@@ -55,13 +55,18 @@ use openhuman_core::inference::host_runtime::all_local_inference_registered_contuse serde_json::{json, Value};use tempfile::{tempdir, TempDir};-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .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}/// Point the Ollama health probe at a closed loopback port and clear the@@ -209,7 +214,7 @@ fn local_inference_controllers_pin_their_registered_wire_method_names() {/// text and the `output_path` the caller chose.#[tokio::test]async fn inference_tts_controller_covers_disabled_missing_binary_and_stubbed_synthesis() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);config.local_ai.runtime_enabled = false;@@ -308,7 +313,7 @@ async fn inference_tts_controller_covers_disabled_missing_binary_and_stubbed_syn/// trim, the unreadable-file branch and the empty-file branch.#[tokio::test]async fn inference_transcribe_controllers_cover_params_trimming_and_local_rejections() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);config.local_ai.runtime_enabled = true;@@ -417,7 +422,7 @@ async fn inference_transcribe_controllers_cover_params_trimming_and_local_reject/// (`ops_part_01.rs:267`) rather than in the model call.#[tokio::test]async fn inference_agent_chat_simple_controller_covers_params_and_prompt_guard() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);config.local_ai.runtime_enabled = false;@@ -494,7 +499,7 @@ async fn inference_agent_chat_simple_controller_covers_params_and_prompt_guard()/// scheme contract, which nothing else does.#[tokio::test]async fn inference_status_controllers_tolerate_extra_params_and_reject_bad_urls() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let _ollama = pin_offline_ollama();let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);diff --git a/tests/raw_coverage/inference_provider_admin_round22_raw_coverage_e2e.rs b/tests/raw_coverage/inference_provider_admin_round22_raw_coverage_e2e.rsindex 7c18edfb27..878a235643 100644--- a/tests/raw_coverage/inference_provider_admin_round22_raw_coverage_e2e.rs+++ b/tests/raw_coverage/inference_provider_admin_round22_raw_coverage_e2e.rs@@ -54,18 +54,23 @@ struct SeenRequest {/// as a flaky failure under `cargo llvm-cov` (the coverage job does not pass/// `--test-threads=1`). Every test takes this guard up front so the suite is/// effectively serialized regardless of the runner's thread count.-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|e| e.into_inner())+ .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}#[tokio::test]async fn provider_admin_model_listing_covers_openrouter_validation_and_local_synthesis() {- let _env = env_lock();+ let _env = env_lock_async().await;let (base, state) = serve_mock().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);@@ -148,7 +153,7 @@ async fn provider_admin_model_listing_covers_openrouter_validation_and_local_syn#[tokio::test]async fn factory_covers_legacy_api_key_scoping_and_abstract_model_errors() {- let _env = env_lock();+ let _env = env_lock_async().await;let (base, state) = serve_mock().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);@@ -242,7 +247,7 @@ async fn factory_covers_legacy_api_key_scoping_and_abstract_model_errors() {#[tokio::test]async fn local_admin_covers_diagnostics_errors_and_probe_with_fake_bins() {- let _env = env_lock();+ let _env = env_lock_async().await;let (base, _state) = serve_mock().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);diff --git a/tests/raw_coverage/inference_provider_auth_e2e.rs b/tests/raw_coverage/inference_provider_auth_e2e.rsindex c7f243443a..fddd174302 100644--- a/tests/raw_coverage/inference_provider_auth_e2e.rs+++ b/tests/raw_coverage/inference_provider_auth_e2e.rs@@ -49,13 +49,18 @@ static AUTH_INIT: OnceLock<()> = OnceLock::new();/// Crate-wide, not file-local: all aggregated suites share one process, so a/// private mutex would not mutually exclude with anyone else's env mutation.-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .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}/// `core::auth::RPC_TOKEN`@@ -245,7 +250,7 @@ fn unsigned_jwt(claims: Value) -> String {#[tokio::test]async fn inference_resolve_model_maps_hints_and_tiers_to_the_routed_model() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup("").await;// ---- Phase A: nothing routed. Every hint resolves to its managed tier. --@@ -456,7 +461,7 @@ async fn inference_resolve_model_maps_hints_and_tiers_to_the_routed_model() {#[tokio::test]async fn inference_provider_auth_errors_surfaces_recorded_byo_key_rejections() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup("").await;// Start from a known state — another suite in this binary may have@@ -581,7 +586,7 @@ async fn inference_provider_auth_errors_surfaces_recorded_byo_key_rejections() {#[cfg(unix)]#[tokio::test]async fn inference_claude_code_status_classifies_ok_outdated_unusable_and_missing() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup("").await;let stub_dir = harness.home().join("stub-cli");@@ -703,7 +708,7 @@ async fn inference_claude_code_status_classifies_ok_outdated_unusable_and_missin#[cfg(unix)]#[tokio::test]async fn inference_claude_code_auth_status_prefers_the_env_key_then_reads_the_cli() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup("").await;let stub_dir = harness.home().join("stub-auth-cli");@@ -844,7 +849,7 @@ async fn inference_claude_code_auth_status_prefers_the_env_key_then_reads_the_cl#[tokio::test]async fn inference_claude_code_full_access_toggle_round_trips_through_the_workspace() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup("").await;// The safe posture is the default, and it must be the default on a fresh@@ -987,7 +992,7 @@ async fn inference_claude_code_full_access_toggle_round_trips_through_the_worksp#[tokio::test]async fn inference_openai_oauth_import_codex_cli_imports_a_real_auth_file() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup("").await;let codex_home = harness.home().join("codex-home");diff --git a/tests/raw_coverage/inference_provider_raw_coverage_e2e.rs b/tests/raw_coverage/inference_provider_raw_coverage_e2e.rsindex 6e0bce2931..38d5144a7f 100644--- a/tests/raw_coverage/inference_provider_raw_coverage_e2e.rs+++ b/tests/raw_coverage/inference_provider_raw_coverage_e2e.rs@@ -38,16 +38,21 @@ struct MockState {// single crate-wide SHARED_ENV_LOCK (these tests use an `EnvVarGuard` struct// that does not itself hold a lock). Poison is recovered so a panic// elsewhere cannot wedge the suite.-fn __shared_env_lock() -> std::sync::MutexGuard<'static, ()> {+fn __shared_env_lock() -> tokio::sync::MutexGuard<'static, ()> {crate::SHARED_ENV_LOCK- .get_or_init(|| std::sync::Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .get_or_init(|| tokio::sync::Mutex::new(()))+ .blocking_lock()+}++async fn __shared_env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {+ crate::SHARED_ENV_LOCK+ .get_or_init(|| tokio::sync::Mutex::new(()))+ .lock().await}#[tokio::test]async fn provider_factory_and_model_listing_cover_cloud_local_and_invalid_shapes() {- let _env_lock = __shared_env_lock();+ let _env_lock = __shared_env_lock_async().await;let (base, _state) = serve_mock().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);@@ -207,7 +212,7 @@ async fn provider_factory_and_model_listing_cover_cloud_local_and_invalid_shapes#[tokio::test]async fn local_service_public_inference_and_diagnostics_use_loopback_ollama() {- let _env_lock = __shared_env_lock();+ let _env_lock = __shared_env_lock_async().await;let (base, _state) = serve_mock().await;let _ollama_env = EnvVarGuard::set("OPENHUMAN_OLLAMA_BASE_URL", &base);let tmp = tempdir().expect("tempdir");diff --git a/tests/raw_coverage/inference_voice_http_round23_raw_coverage_e2e.rs b/tests/raw_coverage/inference_voice_http_round23_raw_coverage_e2e.rsindex 54ea841e4e..0f356aa796 100644--- a/tests/raw_coverage/inference_voice_http_round23_raw_coverage_e2e.rs+++ b/tests/raw_coverage/inference_voice_http_round23_raw_coverage_e2e.rs@@ -43,18 +43,23 @@ struct MockState {/// by default. These tests mutate `OPENHUMAN_WORKSPACE`, `OPENHUMAN_OLLAMA_BASE_URL`,/// and binary path env vars, so every test takes this guard before reading or/// writing config that may be influenced by process env.-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|e| e.into_inner())+ .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}#[tokio::test]async fn http_models_and_chat_use_mocked_ollama_without_real_runtime() {- let _env = env_lock();+ let _env = env_lock_async().await;let (base, state) = serve_mock().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);@@ -166,7 +171,7 @@ async fn http_models_and_chat_use_mocked_ollama_without_real_runtime() {#[tokio::test]async fn dictation_ws_empty_stop_and_audio_cap_do_not_load_whisper() {- let _env = env_lock();+ let _env = env_lock_async().await;let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);config.dictation.streaming = false;@@ -205,7 +210,7 @@ async fn dictation_ws_empty_stop_and_audio_cap_do_not_load_whisper() {#[tokio::test]async fn local_service_reports_endpoint_state_from_mocked_ollama_without_spawning() {- let _env = env_lock();+ let _env = env_lock_async().await;let (base, _state) = serve_mock().await;let tmp = tempdir().expect("tempdir");// Runtime binaries on PATH leave a marker if run: OpenHuman probes thediff --git a/tests/raw_coverage/learning_facets_e2e.rs b/tests/raw_coverage/learning_facets_e2e.rsindex dd3d84e082..4df5a4ad6a 100644--- a/tests/raw_coverage/learning_facets_e2e.rs+++ b/tests/raw_coverage/learning_facets_e2e.rs@@ -60,13 +60,18 @@ static AUTH_INIT: OnceLock<()> = OnceLock::new();static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();/// The crate-wide env lock — see the module docs.-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .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}// ── Env isolation ─────────────────────────────────────────────────────────@@ -324,7 +329,7 @@ fn facets_of(payload: &Value, context: &str) -> Vec<Value> {/// on the previous one's leftovers — the state-leak the wave brief forbids.#[tokio::test]async fn learning_facet_lifecycle_from_rebuild_to_reset() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;// Drain anything a sibling suite left, so `rebuild` scores only these.@@ -639,7 +644,7 @@ async fn learning_facet_lifecycle_from_rebuild_to_reset() {/// handler's wording would pass only if that uniform gate were removed.#[tokio::test]async fn learning_facet_controllers_refuse_bad_input_and_absent_keys() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;// `get_facet` needs both halves of the key.@@ -754,7 +759,7 @@ async fn learning_facet_controllers_refuse_bad_input_and_absent_keys() {/// deliberately does not have.#[tokio::test]async fn learning_save_profile_writes_the_workspace_file() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;let body = "# E2E Profile\n\n- Prefers terse answers\n- Uses pnpm\n";@@ -831,7 +836,7 @@ async fn learning_save_profile_writes_the_workspace_file() {/// with an empty result.#[tokio::test]async fn learning_linkedin_enrichment_fails_loudly_without_a_backend() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;let response = rpc(diff --git a/tests/raw_coverage/memory_sync_round23_raw_coverage_e2e.rs b/tests/raw_coverage/memory_sync_round23_raw_coverage_e2e.rsindex 221ea5afa1..4d56d6834e 100644--- a/tests/raw_coverage/memory_sync_round23_raw_coverage_e2e.rs+++ b/tests/raw_coverage/memory_sync_round23_raw_coverage_e2e.rs@@ -62,7 +62,7 @@ use openhuman_core::security::credentials::{AuthService, APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFILE_NAME,};-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();fn ensure_memory_seams() {@@ -78,11 +78,16 @@ fn ensure_memory_seams() {});}-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|e| e.into_inner())+ .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}fn config_in(tmp: &TempDir) -> Config {@@ -126,7 +131,7 @@ fn store_session(config: &Config) {/// is not.#[tokio::test]async fn composio_get_user_profile_refuses_cleanly_without_a_loaded_module() {- let _guard = env_lock();+ let _guard = env_lock_async().await;let tmp = TempDir::new().expect("tempdir");let _workspace = EnvVarGuard::set_path("OPENHUMAN_WORKSPACE", tmp.path());let _home = EnvVarGuard::set_path("HOME", tmp.path());diff --git a/tests/raw_coverage/notification_platform_e2e.rs b/tests/raw_coverage/notification_platform_e2e.rsindex 5efadcc536..d70fe0e5fd 100644--- a/tests/raw_coverage/notification_platform_e2e.rs+++ b/tests/raw_coverage/notification_platform_e2e.rs@@ -40,13 +40,18 @@ use openhuman_rpc::server::build_core_http_router;// ── env serialisation ────────────────────────────────────────────────────────-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;-fn platform_e2e_env_lock() -> std::sync::MutexGuard<'static, ()> {+fn platform_e2e_env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .get_or_init(|| tokio::sync::Mutex::new(()))+ .blocking_lock()+}++async fn platform_e2e_env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {+ ENV_LOCK+ .get_or_init(|| tokio::sync::Mutex::new(()))+ .lock().await}const TEST_JWT: &str = "e2e-notification-platform-jwt";@@ -330,7 +335,7 @@ fn default_state() -> BackendState {/// `openhuman.notification_mark_acted`.#[tokio::test]async fn notification_centre_lifecycle_over_rpc() {- let _env_lock = platform_e2e_env_lock();+ let _env_lock = platform_e2e_env_lock_async().await;let h = Harness::start(default_state()).await;// Enable the provider so ingest stores rather than skipping.@@ -587,7 +592,7 @@ async fn notification_centre_lifecycle_over_rpc() {/// Covers: `openhuman.notification_core_list`, `openhuman.notification_core_mark_read`.#[tokio::test]async fn notification_core_sync_down_and_mark_read() {- let _env_lock = platform_e2e_env_lock();+ let _env_lock = platform_e2e_env_lock_async().await;let h = Harness::start(default_state()).await;// Empty workspace first: the contract is an empty page, not an error.@@ -800,7 +805,7 @@ async fn notification_core_sync_down_and_mark_read() {/// Covers: `openhuman.health_snapshot`, `openhuman.health_system_info`.#[tokio::test]async fn health_snapshot_and_system_info_report_this_process() {- let _env_lock = platform_e2e_env_lock();+ let _env_lock = platform_e2e_env_lock_async().await;let h = Harness::start(default_state()).await;mark_component_ok("e2e_platform_probe_ok");@@ -905,7 +910,7 @@ async fn health_snapshot_and_system_info_report_this_process() {/// Covers: `openhuman.doctor_report`, `openhuman.doctor_models`.#[tokio::test]async fn doctor_report_and_models_are_internally_consistent() {- let _env_lock = platform_e2e_env_lock();+ let _env_lock = platform_e2e_env_lock_async().await;let h = Harness::start(default_state()).await;let report = post_json_rpc(&h.rpc_base, 9301, "openhuman.doctor_report", json!({})).await;@@ -1062,7 +1067,7 @@ async fn doctor_report_and_models_are_internally_consistent() {/// Covers: `openhuman.service_daemon_host_get`, `openhuman.service_daemon_host_set`.#[tokio::test]async fn service_daemon_host_preferences_round_trip_to_disk() {- let _env_lock = platform_e2e_env_lock();+ let _env_lock = platform_e2e_env_lock_async().await;let h = Harness::start(default_state()).await;let initial = post_json_rpc(@@ -1175,7 +1180,7 @@ async fn service_daemon_host_preferences_round_trip_to_disk() {/// `openhuman.provider_surfaces_list_queue`.#[tokio::test]async fn provider_surfaces_respond_queue_upserts_by_event_identity() {- let _env_lock = platform_e2e_env_lock();+ let _env_lock = platform_e2e_env_lock_async().await;let h = Harness::start(default_state()).await;let event = json!({@@ -1335,7 +1340,7 @@ async fn provider_surfaces_respond_queue_upserts_by_event_identity() {/// Covers: `openhuman.slack_memory_sync_status`, `openhuman.slack_memory_sync_trigger`.#[tokio::test]async fn slack_memory_sync_status_filters_to_active_slack_connections() {- let _env_lock = platform_e2e_env_lock();+ let _env_lock = platform_e2e_env_lock_async().await;// Three rows that between them exercise every branch of the filter: an active slack one, an// active connection for a *different* toolkit, and a slack one that is not active.@@ -1428,7 +1433,7 @@ async fn slack_memory_sync_status_filters_to_active_slack_connections() {/// Both `slack_memory` controllers refuse before the network hop when the user is signed out.#[tokio::test]async fn slack_memory_controllers_require_a_backend_session() {- let _env_lock = platform_e2e_env_lock();+ let _env_lock = platform_e2e_env_lock_async().await;let h = Harness::start(default_state()).await;// Deliberately no sign_in().@@ -1459,7 +1464,7 @@ async fn slack_memory_controllers_require_a_backend_session() {/// Covers: `openhuman.announcements_get_latest`.#[tokio::test]async fn announcements_get_latest_passes_through_and_folds_404_to_null() {- let _env_lock = platform_e2e_env_lock();+ let _env_lock = platform_e2e_env_lock_async().await;// ── signed out: refused locally, before the backend is dialled.let h = Harness::start(default_state()).await;diff --git a/tests/raw_coverage/session_store_e2e.rs b/tests/raw_coverage/session_store_e2e.rsindex fdbecac848..a042ca72b3 100644--- a/tests/raw_coverage/session_store_e2e.rs+++ b/tests/raw_coverage/session_store_e2e.rs@@ -52,17 +52,22 @@ static AUTH_INIT: OnceLock<()> = OnceLock::new();/// nothing: every `tests/raw_coverage/` suite is a module in the one/// `raw_coverage_all` binary, so libtest runs them concurrently in one process/// and only the shared mutex actually excludes another suite's `set_var`.-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;// ── Env isolation ─────────────────────────────────────────────────────────/// `HOME` / `OPENHUMAN_WORKSPACE` are process-global, so every case in this/// binary is serialised behind one lock.-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .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}fn ensure_rpc_auth() {@@ -246,7 +251,7 @@ fn error_message(value: &Value, context: &str) -> String {/// idempotent because the item ledger says the work is done.#[tokio::test]async fn session_import_plans_imports_then_skips_on_rerun() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;let raw_dir = harness.workspace.join("session_raw");@@ -404,7 +409,7 @@ async fn session_import_plans_imports_then_skips_on_rerun() {/// scans a directory.#[tokio::test]async fn session_import_rejects_malformed_params() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;let bad = rpc(@@ -453,7 +458,7 @@ async fn session_import_rejects_malformed_params() {/// byte-for-byte, and a pass-through returns the input unchanged.#[tokio::test]async fn tokenjuice_compress_agrees_with_detect_and_never_loses_content() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;// A JSON array: the one kind the existing `json_rpc_e2e` coverage already@@ -599,7 +604,7 @@ async fn tokenjuice_compress_agrees_with_detect_and_never_loses_content() {/// never minted is a clean `found: false` rather than an error.#[tokio::test]async fn tokenjuice_refuses_empty_input_and_misses_cleanly() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;let no_content = rpc(@@ -692,7 +697,7 @@ fn seed_artifact(/// resolving an absolute path, and `delete` actually removing the row.#[tokio::test]async fn ai_artifacts_list_filter_get_and_delete() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;seed_artifact(@@ -861,7 +866,7 @@ async fn ai_artifacts_list_filter_get_and_delete() {#[cfg(not(feature = "e2e-test-support"))]#[tokio::test]async fn test_support_controllers_are_absent_without_their_feature() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;let catalog = schema_catalog(&harness.rpc_base).await;@@ -903,7 +908,7 @@ async fn test_support_controllers_are_absent_without_their_feature() {#[cfg(feature = "e2e-test-support")]#[tokio::test]async fn test_support_introspection_reads_the_live_workspace() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;std::fs::create_dir_all(harness.workspace.join("notes")).expect("create notes dir");diff --git a/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs b/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rsindex ef3a0d1185..3548e3384d 100644--- a/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs+++ b/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs@@ -35,7 +35,7 @@ use openhuman_rpc::server::build_core_http_router;const TEST_RPC_TOKEN: &str = "tool-registry-approval-raw-e2e-token";static AUTH_INIT: OnceLock<()> = OnceLock::new();-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;struct TestHarness {_tmp: TempDir,@@ -44,11 +44,16 @@ struct TestHarness {rpc_join: tokio::task::JoinHandle<Result<(), std::io::Error>>,}-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .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}fn ensure_rpc_auth() {@@ -219,7 +224,7 @@ fn install_test_mcp_server(config: &Config, server: &InstalledServer) {#[tokio::test(flavor = "multi_thread", worker_threads = 2)]async fn tool_registry_rpc_diagnostics_include_denials_and_provider_errors() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup(r#"[[capability_providers]]@@ -444,7 +449,7 @@ async fn tool_registry_entries_include_connected_mcp_client_tools() {#[tokio::test]async fn tool_registry_diagnostics_reports_config_and_audit_store_failures() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let tmp = tempdir().expect("tempdir");let workspace_file = tmp.path().join("workspace-file");std::fs::write(&workspace_file, "not a directory").expect("workspace sentinel");@@ -625,7 +630,7 @@ async fn approval_schema_handlers_validate_params_and_surface_empty_gate_state()#[tokio::test(flavor = "multi_thread", worker_threads = 2)]async fn approval_rpc_decision_paths_persist_always_allow_and_recent_audit() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup("").await;let config = Config::load_or_init().awaitdiff --git a/tests/raw_coverage/tools_composio_large_round25_raw_coverage_e2e.rs b/tests/raw_coverage/tools_composio_large_round25_raw_coverage_e2e.rsindex 9d5a732c6b..5c696cd877 100644--- a/tests/raw_coverage/tools_composio_large_round25_raw_coverage_e2e.rs+++ b/tests/raw_coverage/tools_composio_large_round25_raw_coverage_e2e.rs@@ -27,7 +27,7 @@ use openhuman_core::integrations::composio::{use openhuman_core::tools::ComposioListToolsTool;use tinytools::{Tool, ToolCallOptions};-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;#[derive(Clone, Debug)]struct RecordedRequest {@@ -49,11 +49,16 @@ struct Harness {_guards: Vec<EnvVarGuard>,}-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .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}async fn setup_direct_config(base: &str) -> Harness {@@ -108,7 +113,7 @@ async fn setup_direct_config(base: &str) -> Harness {#[tokio::test]async fn round25_direct_mode_ops_use_loopback_factory_for_tools_connections_and_execute() {- let _lock = env_lock();+ let _lock = env_lock_async().await;invalidate_connected_integrations_cache();let state = MockState::default();diff --git a/tests/raw_coverage/tools_composio_network_leftovers_raw_coverage_e2e.rs b/tests/raw_coverage/tools_composio_network_leftovers_raw_coverage_e2e.rsindex 1e72141afd..24c2b69663 100644--- a/tests/raw_coverage/tools_composio_network_leftovers_raw_coverage_e2e.rs+++ b/tests/raw_coverage/tools_composio_network_leftovers_raw_coverage_e2e.rs@@ -24,7 +24,7 @@ use openhuman_core::tools::{};use tinytools::{Tool, ToolCallOptions};-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;#[derive(Clone, Debug)]struct RecordedRequest {@@ -47,11 +47,16 @@ struct Harness {_guards: Vec<EnvVarGuard>,}-fn env_lock() -> std::sync::MutexGuard<'static, ()> {+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())+ .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}fn tempdir() -> TempDir {@@ -111,7 +116,7 @@ fn store_session_token(config: &Config) {#[tokio::test]async fn round20_backend_agent_tools_cover_markdown_filtering_and_errors() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let state = MockState::default();let base = start_loopback(Router::new()@@ -212,7 +217,7 @@ async fn round20_backend_agent_tools_cover_markdown_filtering_and_errors() {#[tokio::test]async fn round20_composio_ops_cover_authorize_scopes() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let state = MockState::default();let base = start_loopback(Router::new()diff --git a/tests/raw_coverage/w4_shared/mod.rs b/tests/raw_coverage/w4_shared/mod.rsindex 125765c0bf..148a16d926 100644--- a/tests/raw_coverage/w4_shared/mod.rs+++ b/tests/raw_coverage/w4_shared/mod.rs@@ -38,18 +38,28 @@ pub const SESSION_USER_ID: &str = "w4-user";static AUTH_INIT: OnceLock<String> = OnceLock::new();/// The crate-wide env mutex, not a private one — see the module note above.-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;static KEYRING_INIT: OnceLock<()> = OnceLock::new();/// Serializes every case that touches process-global env (`HOME`,/// `OPENHUMAN_WORKSPACE`, the backend-URL overrides) against every other/// aggregated suite. Poison is recovered so one panicking case cannot wedge the/// binary.-pub fn env_lock() -> std::sync::MutexGuard<'static, ()> {+pub fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {let guard = ENV_LOCK- .get_or_init(|| Mutex::new(()))- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner());+ .get_or_init(|| tokio::sync::Mutex::new(()))+ .blocking_lock();+ // Under the lock, so this `set_var` cannot race a concurrent env read.+ KEYRING_INIT.get_or_init(|| {+ std::env::set_var("OPENHUMAN_KEYRING_BACKEND", "file");+ });+ guard+}++pub async fn env_lock_async() -> tokio::sync::MutexGuard<'static, ()> {+ let guard = ENV_LOCK+ .get_or_init(|| tokio::sync::Mutex::new(()))+ .lock().await;// Under the lock, so this `set_var` cannot race a concurrent env read.KEYRING_INIT.get_or_init(|| {std::env::set_var("OPENHUMAN_KEYRING_BACKEND", "file");diff --git a/tests/raw_coverage/worker_b_raw_coverage_e2e.rs b/tests/raw_coverage/worker_b_raw_coverage_e2e.rsindex 0c0aacf372..f2b29dc999 100644--- a/tests/raw_coverage/worker_b_raw_coverage_e2e.rs+++ b/tests/raw_coverage/worker_b_raw_coverage_e2e.rs@@ -36,7 +36,7 @@ use openhuman_rpc::server::build_core_http_router;const TEST_RPC_TOKEN: &str = "worker-b-raw-coverage-e2e-token";static AUTH_INIT: OnceLock<()> = OnceLock::new();-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;+static ENV_LOCK: &OnceLock<tokio::sync:: tokio::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;#[derive(Clone, Default)]struct MockState {@@ -56,12 +56,14 @@ struct MockHarness {join: tokio::task::JoinHandle<Result<(), std::io::Error>>,}-fn env_lock() -> std::sync::MutexGuard<'static, ()> {- let mutex = ENV_LOCK.get_or_init(|| Mutex::new(()));- match mutex.lock() {- Ok(guard) => guard,- Err(poisoned) => poisoned.into_inner(),- }+fn env_lock() -> tokio::sync::MutexGuard<'static, ()> {+ let mutex = ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));+ mutex.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}fn ensure_rpc_auth() {@@ -361,7 +363,7 @@ async fn seed_session_token() {#[tokio::test]async fn inference_provider_success_paths_use_mock_models_and_chat() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let mock = serve_mock().await;let harness = setup().await;configure_mock_provider(&harness.rpc_base, &mock.base).await;@@ -439,7 +441,7 @@ async fn tools_web_answer_uses_managed_gemini_grounding_and_returns_citations());return;}- let _lock = env_lock();+ let _lock = env_lock_async().await;let mock = serve_mock().await;let harness = setup().await;configure_mock_provider(&harness.rpc_base, &mock.base).await;@@ -518,7 +520,7 @@ async fn tools_web_search_success_path_uses_backend_session_and_shapes_results());return;}- let _lock = env_lock();+ let _lock = env_lock_async().await;let mock = serve_mock().await;let harness = setup().await;configure_mock_provider(&harness.rpc_base, &mock.base).await;@@ -588,7 +590,7 @@ async fn tools_web_search_success_path_uses_backend_session_and_shapes_results()#[tokio::test]async fn approval_gate_rpc_decision_resumes_parked_tool_and_records_execution() {- let _lock = env_lock();+ let _lock = env_lock_async().await;let harness = setup().await;let config = Config::load_or_init().await