AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
kv-store lock tests stop racing each other and the worker thread (SC-AGENT-PREFLIGHT flake)
merged693adbb0c1cdcafd #683 · opened 2026-10-19 17:20 UTC · closed 2026-10-19 17:51 UTC · merged 2026-10-19 17:51 UTC
Imported from GitHub aien-dev/aien-sovereign-core-mv#683, by drakestapleton
Labels: ready-to-merge
Base e54700fb357f48344100ecaab047e8ffa4ce2610 · Head bd4bd2a50b867440fddf49c1240d58e56f97bf0a
Merged on GitHub as c17430dbb8358c8387384dd193479ef91c4fc3d6; reachable from main 007ac4ac5ee5edc6f79f411b1706752293604044 (observed 2026-11-18T16:35:47Z)
drakestapleton wrote on 2026-10-19 17:20 UTC
What this fixes
Two kv-store tests reopened a store while something still held its lock, so SC-AGENT-PREFLIGHT (which runs a file's tests side by side) failed at random with "in use" / an unexpected terminal. The lock code is right; the tests interfered.
host_fs_lock_tests.rs: the cross-process test spawns a second copy of the test binary; between spawn and exec the child holds duplicates of every open file, including the lock of a store a neighbouring test just closed. The spawning test now waits until no other lock test is mid-way, and the others wait while it spawns. No check removed or loosened.
worker_host_fs_tests.rs: the stalled-shutdown restart test reopened its store while the background worker thread still held two handles on it. It now waits for the worker to let go first (the sibling test got the same fix in 4d624f70).
Lock test file 500 runs each, interleaved under the same load: main failed 29 of 500, this branch 0 of 500. Controls on main: serial 0/300; side by side without the spawning test 0/300.
Restart race: a probe build counted 3 handles at reopen in 40 of 40 runs; the judge hit it on heads 12e71aad and 4291df40. It could not be made to fail on demand (0/80), the probe shows the window.
Whole kv-store crate: 256 tests pass, clippy and fmt clean. Full SC-AGENT-PREFLIGHT in the sandbox: PASS, 352 test groups ok.
Apply it
git checkout -b patch-693adbb0c1cdcafde54700fb357f48344100ecaab047e8ffa4ce2610
curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/693adbb0c1cdcafd.patch | git am
diff --git a/.crumb b/.crumb
index 6834e330..f1241b53 100644
--- a/.crumb
+++ b/.crumb
@@ -119,14 +119,14 @@
}
],
"children_root": "sha256:7233404baa7d5c3ce664e4abee8970212f5e6213399ba74d2ad7a65e3a5324d5",
- "compiled_at": "2026-10-19T15:26:54Z",
+ "compiled_at": "2026-10-19T17:20:35Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:b2c63b9d9b092fd1c9953a073578b2ce88d7fcf553789620bfeb93efd35ebae3",
+ "digest": "sha256:ed210d92a91b1b826018fffd07efb5c8da54cfa5bc70911ca6c4a9dc9f74aa03",
"evidence_files": 1578,
"evidence_root": "sha256:135e27a1a0704c4a8371cd2c1eb555f2b5beec61c212949b029a5457418a7160",
"files": 5891,
- "generated_at_commit": "78b49dee252cb90f04c4ad594535c5cba4c1c52f",
- "source_tree": "sha256:8075a28ecf5ae93677aa294ef29675ceef358c1df1a05bdf2b195c84369a6966"
+ "generated_at_commit": "40ed2a147cf53fa88af59fddb14a6007559d4bfd",
+ "source_tree": "sha256:228864541d5d655070f9ec7302cc5741bbd0198d569678411c0c009c92557898"
}
},
"history": [],
diff --git a/crates/aien-kv-store/tests/host_fs_lock_tests.rs b/crates/aien-kv-store/tests/host_fs_lock_tests.rs
index e9e10916..026e0144 100644
--- a/crates/aien-kv-store/tests/host_fs_lock_tests.rs
+++ b/crates/aien-kv-store/tests/host_fs_lock_tests.rs
@@ -12,16 +12,31 @@ mod rig;
use aien_kv_store::host_fs::{HostFsConfig, HostFsStore};
use aien_platform::PlatformError;
use rig::Fx;
+use std::sync::{RwLock, RwLockReadGuard};
/// The child process of the cross-process test reads its store root here.
const CHILD_ROOT_ENV: &str = "AIEN_KV_LOCK_TEST_CHILD_ROOT";
+/// Tests run on parallel threads of one process. While the cross-process test
+/// spawns its child, the child holds a copy of every descriptor open in this
+/// process until its exec closes them (they are close-on-exec), and `flock`
+/// belongs to the open file, not the descriptor: a store another test drops
+/// in that window stays locked, and that test's reopen is refused. The
+/// spawning test takes this for writing and every other test for reading, so
+/// no store opens or drops while a child is being spawned.
+static SPAWN: RwLock<()> = RwLock::new(());
+
+fn no_spawn() -> RwLockReadGuard<'static, ()> {
+ SPAWN.read().unwrap_or_else(|e| e.into_inner())
+}
+
fn in_use(r: Result<HostFsStore, PlatformError>) -> bool {
matches!(r, Err(PlatformError::TaskRejected(ref m)) if m.contains("in use"))
}
#[test]
fn a_second_open_of_a_held_store_directory_is_refused() {
+ let _g = no_spawn();
let fx = Fx::new();
let first = fx.open();
assert!(fx.root().join("LOCK").exists());
@@ -31,6 +46,7 @@ fn a_second_open_of_a_held_store_directory_is_refused() {
#[test]
fn a_refused_second_open_leaves_the_first_stores_temp_files_alone() {
+ let _g = no_spawn();
let fx = Fx::new();
let first = fx.open();
// Stands for a park the first store has in flight.
@@ -51,6 +67,7 @@ fn a_refused_second_open_leaves_the_first_stores_temp_files_alone() {
#[test]
fn the_lock_is_released_when_the_store_drops() {
+ let _g = no_spawn();
let fx = Fx::new();
for _ in 0..3 {
drop(fx.open());
@@ -59,6 +76,7 @@ fn the_lock_is_released_when_the_store_drops() {
#[test]
fn a_store_directory_held_by_another_process_is_refused() {
+ let _g = SPAWN.write().unwrap_or_else(|e| e.into_inner());
let fx = Fx::new();
let first = fx.open();
let out = std::process::Command::new(std::env::current_exe().unwrap())
diff --git a/crates/aien-kv-store/tests/worker_host_fs_tests.rs b/crates/aien-kv-store/tests/worker_host_fs_tests.rs
index 9922021b..c5d0daeb 100644
--- a/crates/aien-kv-store/tests/worker_host_fs_tests.rs
+++ b/crates/aien-kv-store/tests/worker_host_fs_tests.rs
@@ -310,6 +310,14 @@ fn worker_over_host_fs_shutdown_with_a_stalled_job_then_restart_recovers() {
// Restart: leave debris a crash would leave, reopen, recover, restore.
let Rigged { fx, store, worker } = r;
drop(worker);
+ // As in the test above: the worker thread still holds two clones of the
+ // store until its loop returns, and the LOCK (#521) lives as long as any
+ // clone, so reopen only once the thread let go.
+ let deadline = Instant::now() + Duration::from_secs(10);
+ while Arc::strong_count(&store) > 1 {
+ assert!(Instant::now() < deadline, "worker thread kept the store");
+ std::thread::sleep(Duration::from_millis(1));
+ }
drop(store);
std::fs::write(fx.root().join("tmp").join("leftover.1.2.3.part"), b"x").unwrap();
let (junk, _) = fx.chunk(42, 8);