From 6140034f72ec218de30d00fdd33d63f0d4d64b9d Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 15:16:43 +0530 Subject: [PATCH 1/2] test(policy): a scoped test thread's reload never writes the process policy --- .../src/security/live_policy.rs | 6 ++++ .../src/security/live_policy_tests.rs | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/crates/openhuman-core/src/security/live_policy.rs b/crates/openhuman-core/src/security/live_policy.rs index 3597a13c7f1..f9f7e75bd32 100644 --- a/crates/openhuman-core/src/security/live_policy.rs +++ b/crates/openhuman-core/src/security/live_policy.rs @@ -201,7 +201,13 @@ pub fn generation() -> u64 { /// Rebuild the policy from `autonomy_config` against the stored workspace dir /// and swap it in, bumping the generation counter. No-op if nothing has been /// installed yet (e.g. a CLI invocation that never started a session runtime). +/// A test thread holding an [`install_scoped`] policy owns its policy, so its +/// reloads never reach the process-global one that sibling tests read. pub fn reload_from(autonomy_config: &crate::config::AutonomyConfig) { + #[cfg(test)] + if TEST_POLICY_OVERRIDE.with(|current| current.borrow().is_some()) { + return; + } let Some(state) = STATE.get() else { return; }; diff --git a/crates/openhuman-core/src/security/live_policy_tests.rs b/crates/openhuman-core/src/security/live_policy_tests.rs index 830f3a65cb8..6e92ae54c94 100644 --- a/crates/openhuman-core/src/security/live_policy_tests.rs +++ b/crates/openhuman-core/src/security/live_policy_tests.rs @@ -39,6 +39,40 @@ fn scoped_policy_is_thread_local_and_restored() { ); } +#[test] +fn a_reload_on_a_scoped_thread_leaves_the_process_policy_alone() { + let _env = crate::config::TEST_ENV_LOCK.blocking_lock(); + let workspace = std::env::temp_dir().join("openhuman_scoped_reload_test"); + install( + Arc::new(SecurityPolicy::default()), + workspace.clone(), + workspace.clone(), + ); + let _guard = install_scoped( + Arc::new(SecurityPolicy::default()), + workspace.clone(), + workspace, + ); + + reload_from(&AutonomyConfig { + auto_approve: vec!["create_workflow".into()], + ..AutonomyConfig::default() + }); + + let sibling_list = std::thread::spawn(|| { + current() + .expect("global policy remains installed") + .auto_approve + .clone() + }) + .join() + .expect("sibling thread joined"); + assert!( + !sibling_list.iter().any(|tool| tool == "create_workflow"), + "a scoped test's reload must not reach the process-global policy" + ); +} + #[test] fn install_then_reload_swaps_policy_and_bumps_generation() { // Serialize against other tests that install/reload this process-global From 7c15ac1e1cc83947aa7c57e80c4d6841a8b14fab Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 19:29:43 +0530 Subject: [PATCH 2/2] docs(policy): plain-text the test-only link; trace the scoped reload skip --- crates/openhuman-core/src/security/live_policy.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/openhuman-core/src/security/live_policy.rs b/crates/openhuman-core/src/security/live_policy.rs index f9f7e75bd32..9018a7e55ff 100644 --- a/crates/openhuman-core/src/security/live_policy.rs +++ b/crates/openhuman-core/src/security/live_policy.rs @@ -201,11 +201,12 @@ pub fn generation() -> u64 { /// Rebuild the policy from `autonomy_config` against the stored workspace dir /// and swap it in, bumping the generation counter. No-op if nothing has been /// installed yet (e.g. a CLI invocation that never started a session runtime). -/// A test thread holding an [`install_scoped`] policy owns its policy, so its +/// A test thread holding an `install_scoped` policy owns its policy, so its /// reloads never reach the process-global one that sibling tests read. pub fn reload_from(autonomy_config: &crate::config::AutonomyConfig) { #[cfg(test)] if TEST_POLICY_OVERRIDE.with(|current| current.borrow().is_some()) { + tracing::trace!("[security:live_policy] reload skipped for scoped test policy"); return; } let Some(state) = STATE.get() else {