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
test(storage): key the probe-race signal to the test's own lease key
M3gA-Minddb04dae69257
diff --git a/crates/openhuman-core/src/storage/lease_local.rs b/crates/openhuman-core/src/storage/lease_local.rsindex 5c7ff95b2a..d4b67c17b8 100644--- a/crates/openhuman-core/src/storage/lease_local.rs+++ b/crates/openhuman-core/src/storage/lease_local.rs@@ -79,7 +79,10 @@ fn lock_past_probes(file: &File, key: &str, node: &str) -> io::Result<()> {match file.try_lock_exclusive() {Err(error) if is_contended(&error) && retries + 1 < PROBE_ATTEMPTS => {#[cfg(test)]- CONTENDED_ATTEMPTS.fetch_add(1, std::sync::atomic::Ordering::SeqCst);+ CONTENDED_KEYS+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner)+ .push(key.to_string());retries += 1;std::thread::sleep(PROBE_WAIT);}@@ -99,10 +102,10 @@ fn lock_past_probes(file: &File, key: &str, node: &str) -> io::Result<()> {result}-/// Contended attempts `lock_past_probes` has retried, so a test can release-/// its stand-in probe lock only once `acquire` has actually met it.+/// Keys whose contended lock `lock_past_probes` retried, so a test can+/// release its stand-in probe lock only once its own `acquire` has met it.#[cfg(test)]-static CONTENDED_ATTEMPTS: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);+static CONTENDED_KEYS: Mutex<Vec<String>> = Mutex::new(Vec::new());impl LocalLeases {/// Leases under `root` for `node`.diff --git a/crates/openhuman-core/src/storage/lease_local_tests.rs b/crates/openhuman-core/src/storage/lease_local_tests.rsindex 8c1ddc7c5b..e32d8cccf5 100644--- a/crates/openhuman-core/src/storage/lease_local_tests.rs+++ b/crates/openhuman-core/src/storage/lease_local_tests.rs@@ -164,8 +164,9 @@ async fn acquire_rides_out_a_transient_inspection_lock() {// The doctor's `holder_readonly` (often another process) checks liveness// by taking the lock for an instant; an `acquire` landing in that window// must not report the dead previous owner as the holder.+ const KEY: &str = "probe-race";let dir = tempfile::tempdir().unwrap();- let key_dir = local_dir(dir.path(), "k");+ let key_dir = local_dir(dir.path(), KEY);fs::create_dir_all(&key_dir).unwrap();fs::write(key_dir.join(RECORD_FILE),@@ -187,25 +188,21 @@ async fn acquire_rides_out_a_transient_inspection_lock() {.open(key_dir.join(LOCK_FILE)).unwrap();probe.try_lock_exclusive().unwrap();- // Release the stand-in probe only after `acquire` has met it contended,- // so the test always exercises the retry rather than racing a timer.- let seen = CONTENDED_ATTEMPTS.load(std::sync::atomic::Ordering::SeqCst);+ // Release the stand-in probe only after this test's own `acquire` has met+ // it contended (keyed, so other tests' retries can't trigger it), so the+ // test always exercises the retry rather than racing a timer.+ let met = || CONTENDED_KEYS.lock().unwrap().iter().any(|k| k == KEY);let release = std::thread::spawn(move || {let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);- while CONTENDED_ATTEMPTS.load(std::sync::atomic::Ordering::SeqCst) == seen- && std::time::Instant::now() < deadline- {+ while !met() && std::time::Instant::now() < deadline {std::thread::yield_now();}FileExt::unlock(&probe).unwrap();});- let grant = LocalLeases::new(dir.path(), "b").acquire("k", 0).await;+ let grant = LocalLeases::new(dir.path(), "b").acquire(KEY, 0).await;release.join().unwrap();let grant = grant.expect("a probe-length lock must not refuse the acquire");assert_eq!((grant.epoch, grant.previous_unclean), (2, true));- assert!(- CONTENDED_ATTEMPTS.load(std::sync::atomic::Ordering::SeqCst) > seen,- "the acquire never met the probe lock"- );+ assert!(met(), "the acquire never met the probe lock");}