interplane.Get Omega
Read in your language

aien-sovereign-core-mv

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.

Brought by drakestapleton

GitHub aien-dev/aien-sovereign-core-mv#607 (code only)

closed derived 5eb8a56a3aa50713 #607

Imported from GitHub aien-dev/aien-sovereign-core-mv#607 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 12e71aad80fda23a428317d11b0dac02d1c777f1 · Head ed717bcd10b6253138b8fca16634e4f4ae3b4859

Fetch it

A git bundle of the pull request's head, 6986 bytes.

curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/5eb8a56a3aa50713.bundle -o 5eb8a56a3aa50713.bundle
git fetch 5eb8a56a3aa50713.bundle refs/pull/607/head

Raw bundle · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/aien-sovereign-core-mv
607
ed717bcd10b6253138b8fca16634e4f4ae3b4859
{"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":607,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/607","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:37:39Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.crumb b/.crumb
index d38130fb..6e85fc82 100644
--- a/.crumb
+++ b/.crumb
@@ -63,45 +63,9 @@
   "extensions": {
     "generated": {
       "children": [
-        {
-          "digest": "4e7f370019e67f6c71565d1544530851eb1b3b1bed61c2712f4ac7d9614a89bf",
-          "last_commit": "6bbe2ec2",
-          "name": "crates/aien-allen",
-          "purpose": "ALLEN identity gate: resolve-only subject check, host pin record, deployment record (ADR 0035). "
-        },
-        {
-          "digest": "40a231c50dba92af7de2527ab33879c5d1eaaa6e7ea5d6a5ebaa9d60c7542075",
-          "last_commit": "b9b52f9c",
-          "name": "crates/aien-allen-memory",
-          "purpose": "ALLEN scoped memory store: scopes enforced at recall, inspect/correct/export, key-destroying for"
-        },
-        {
-          "digest": "44dc482b8c9db8919a68ec69b019cd77967232a6ec8b1910c0dfe3cd4d71f141",
-          "last_commit": "b9b52f9c",
-          "name": "crates/aien-allen-profile",
-          "purpose": "ALLEN persona profile v1: versioned, user-editable profile bound to the engaged ALLEN identity; "
-        },
-        {
-          "digest": "f5571bcc0bb95b44dd8bf8f0b47ded3bcb1e1ee76c81b4ff5edb87ac237d66d8",
-          "last_commit": "f8eea420",
-          "name": "crates/aien-cli",
-          "purpose": ""
-        },
-        {
-          "digest": "25fd9f8afbea19702750f8ddba2ef4aeafc5bc4515aa695340a5af6931989c03",
-          "last_commit": "8cca8020",
-          "name": "crates/aien-scheduler/src/bin",
-          "purpose": ""
-        },
-        {
-          "digest": "dd11ae9a698f7fcad7d1df386926426ea051d4131ee738da2ac81eb6a57b9473",
-          "last_commit": "afbbd804",
-          "name": "crates/spark-cockpit-rs",
-          "purpose": ""
-        },
         {
           "digest": "34b010337138a65931ca4d0177631d839f71af021c5092583f52afd69ddd1b72",
-          "last_commit": "fe3677c3",
+          "last_commit": "deff6f7a",
           "name": "scripts",
           "purpose": ""
         },
@@ -110,23 +74,17 @@
           "last_commit": "fa73e778",
           "name": "skills",
           "purpose": ""
-        },
-        {
-          "digest": "b787845b373f1f2ef48522c2575a6de8ad32e3584bef4b578ba61d2ab053187c",
-          "last_commit": "fe3677c3",
-          "name": "tools/aien-local-ci",
-          "purpose": "Local CI sandbox exec contract (C8), aien-run user/caches install, Forgejo trigger hook, health "
         }
       ],
-      "children_root": "sha256:111edf8bf001ed434f7dacbc6d8ab9d75f6bda2cd909d01264fb42bbe38b1d74",
-      "compiled_at": "2026-10-17T11:58:09Z",
+      "children_root": "sha256:bd742d6a3614d943dddc615cc1f2e6a2ff9b3b0274923cbb231b9a6660460503",
+      "compiled_at": "2026-10-18T12:33:45Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:90138b1fd1cf3ffa4f762b157930e959f2bea50c41351c40b41330ae9edff05b",
+      "digest": "sha256:8d1255e9ba25948febc8d3f5ca87d66a7105a993e8f5785562bc64cee59da4f5",
       "evidence_files": 1578,
       "evidence_root": "sha256:135e27a1a0704c4a8371cd2c1eb555f2b5beec61c212949b029a5457418a7160",
       "files": 5891,
-      "generated_at_commit": "6fb606867d2cd502b9475cd2ff0cc85ab40b16c9",
-      "source_tree": "sha256:7ac140a01c7f7ef0cc9f91a7cf9ea94fb063f8ca7f24365f185b9da5b2ed26b9"
+      "generated_at_commit": "2074065a284f91bbdb6d82714c5d5d8e0d770ddd",
+      "source_tree": "sha256:b7a6d7b5d44841ec7bda67f8178dcca2d95e07a1bff221b5e0cbb9a3ecc64e06"
     }
   },
   "history": [],
diff --git a/tools/aien-test/docs/LOCAL_VERIFICATION.md b/tools/aien-test/docs/LOCAL_VERIFICATION.md
index d8f9951c..3d6b9957 100644
--- a/tools/aien-test/docs/LOCAL_VERIFICATION.md
+++ b/tools/aien-test/docs/LOCAL_VERIFICATION.md
@@ -139,6 +139,23 @@ aien-proof `slots/gpu.lock`; the worker's target priming takes only the
 target-dir lock. Known limit: a gb10 gate is never killed on timeout, so a
 hung one holds the target dir until it exits on its own.
 
+The worker also holds the target dir for the whole head, from before the
+checkout to the verdict, on its own lock file
+`<state>/locks/target/<sanitised target dir>.head.lock` (`aien-test status`
+shows the phase `target-wait` while it waits; the bundle's notes record how
+long). Two heads of one trust class therefore never build in the dir with
+their gates interleaved. Without it a head failed to compile against its own
+crate (sc #597, `unresolved import aien_kv_cache::round_to_dtype_in_place` at
+a commit that has it): cargo keys a workspace crate by its path relative to
+the workspace root, so every checkout of the repository names the same rlib,
+and it decides freshness by comparing source mtimes with the artifact. Head B
+was checked out, head A then built the crate at a newer commit in the same
+dir, and B's sources were older than A's rlib, so cargo linked A's. With the
+head lock a checkout is always newer than every artifact in the dir, so a
+head rebuilds its own workspace crates and reuses only the registry
+dependencies, which cargo keys by version. Gate-level serialization of the
+dir already made this the throughput the judge had.
+
 Under `--sandbox user` every checkout is made with INFRA's worktree tool
 (`--wt-tool`, default `<clones>/aien-sovereign-core/tools/aien-local-ci/wt.sh`;
 without it the worker refuses to run). `wt.sh sync` refreshes the bare mirror
diff --git a/tools/aien-test/src/resources.rs b/tools/aien-test/src/resources.rs
index 407c6aad..fba4110a 100644
--- a/tools/aien-test/src/resources.rs
+++ b/tools/aien-test/src/resources.rs
@@ -8,13 +8,20 @@
 //!
 //! Deadlock rule: whenever more than one resource is taken, they are taken in
 //! one fixed order. Pools are ordered by `Pool`'s derived `Ord` (gb10, then
-//! qemu, then host). The full order for one gate is: (1) the in-process pool
-//! slot, (2) the target-dir lock (`lock_target_dir`, every gate that runs,
-//! on its `CARGO_TARGET_DIR` or else the worktree's `target/`), (3)
-//! `/tmp/aien-gb10.lock`, (4) aien-proof's `slots/gpu.lock` when the
-//! aien-proof board directory exists. A holder of (2) already has its slot
-//! and never waits for one, so a gate blocked on (2) with a slot in hand
-//! cannot close a cycle; the worker's target priming takes (2) alone and
+//! qemu, then host). Before any of them the worker holds (0) the head lock
+//! of its target dir (`head_lock_path`, `lock_target_dir`): taken before the
+//! head is checked out and held until its verdict, so two heads never build
+//! in one target dir with their gates interleaved (sc #597: cargo keys a
+//! workspace crate by its path relative to the workspace root, so head B's
+//! fresh checkout is older than the artifact head A built in between and
+//! cargo links A's stale rlib). The full order for one gate is then: (1) the
+//! in-process pool slot, (2) the target-dir lock (`lock_target_dir`, every
+//! gate that runs, on its `CARGO_TARGET_DIR` or else the worktree's
+//! `target/`), (3) `/tmp/aien-gb10.lock`, (4) aien-proof's `slots/gpu.lock`
+//! when the aien-proof board directory exists. A holder of (2) already has
+//! its slot and never waits for one, so a gate blocked on (2) with a slot in
+//! hand cannot close a cycle; a holder of (0) holds nothing else when it
+//! takes it; the worker's target priming takes (2) alone and
 //! never (3) or (4). Known limit: a gb10 gate is never killed on timeout,
 //! so a hung one holds (2) and (3) until it exits on its own; every other
 //! gate of that target dir waits behind it (the receipt says
@@ -424,7 +431,22 @@ pub const DEFAULT_TARGET_LOCK_DIR: &str = "/tmp/aien-test-target-locks";
 /// inside the target dir itself: under the user sandbox that belongs to
 /// `aien-run`, and the lock is the worker's.
 pub fn target_lock_path(lock_dir: &Path, target_dir: &Path) -> PathBuf {
-    let name: String = target_dir
+    lock_dir.join(format!("{}.lock", lock_name(target_dir)))
+}
+
+/// The head lock of one cargo target dir: `<lock_dir>/<sanitised>.head.lock`,
+/// beside the gate lock of the same dir and never the same file. The worker
+/// takes it before it checks a head out and holds it until the head's
+/// verdict, so the gates of two heads never interleave in one target dir
+/// (sc #597). Its own file, because the runner's per-gate `flock` on
+/// `target_lock_path` is taken in the same process: a second `flock` on one
+/// file would wait for the worker itself.
+pub fn head_lock_path(lock_dir: &Path, target_dir: &Path) -> PathBuf {
+    lock_dir.join(format!("{}.head.lock", lock_name(target_dir)))
+}
+
+fn lock_name(target_dir: &Path) -> String {
+    target_dir
         .display()
         .to_string()
         .chars()
@@ -435,8 +457,7 @@ pub fn target_lock_path(lock_dir: &Path, target_dir: &Path) -> PathBuf {
                 '_'
             }
         })
-        .collect();
-    lock_dir.join(format!("{name}.lock"))
+        .collect()
 }
 
 /// Exclusive hold of one cargo target dir (`flock(LOCK_EX)`, waited for).
@@ -475,6 +496,18 @@ pub fn lock_target_dir(path: &Path) -> io::Result<TargetLock> {
     })
 }
 
+/// `lock_target_dir` without the wait: `None` when another holder has it.
+pub fn try_lock_target_dir(path: &Path) -> io::Result<Option<TargetLock>> {
+    let file = open_lock(path)?;
+    if !flock_exclusive(&file, false)? {
+        return Ok(None);
+    }
+    Ok(Some(TargetLock {
+        file: Some(file),
+        path: path.to_path_buf(),
+    }))
+}
+
 fn open_lock(path: &Path) -> io::Result<File> {
     if let Some(parent) = path.parent() {
         if !parent.as_os_str().is_empty() {
@@ -626,6 +659,33 @@ mod tests {
         });
     }
 
+    /// The head lock of a target dir is its own file: holding it leaves the
+    /// gate lock of the same dir free (the runner takes that one in the same
+    /// process, for every gate of the head), and it is exclusive between
+    /// holders until dropped.
+    #[test]
+    fn head_lock_is_its_own_file_and_exclusive() {
+        let dir = TempDir::new("hlock");
+        let target = Path::new("/var/lib/aien-run/target/r/pr");
+        let head = head_lock_path(dir.path(), target);
+        let gate = target_lock_path(dir.path(), target);
+        assert_ne!(head, gate);
+        assert_eq!(head.parent(), gate.parent());
+        assert!(head.ends_with("_var_lib_aien-run_target_r_pr.head.lock"));
+        let held = lock_target_dir(&head).unwrap();
+        assert!(
+            try_lock_target_dir(&head).unwrap().is_none(),
+            "a second holder of the head lock is refused"
+        );
+        let gate_lock = try_lock_target_dir(&gate).unwrap();
+        assert!(
+            gate_lock.is_some(),
+            "the gate lock stays free under the head lock"
+        );
+        drop(held);
+        assert!(try_lock_target_dir(&head).unwrap().is_some());
+    }
+
     #[test]
     fn gb10_pool_is_serialized() {
         let p = Pools::new(PoolSizes { host: 4, qemu: 2 });
diff --git a/tools/aien-test/src/worker.rs b/tools/aien-test/src/worker.rs
index 6982dd4c..bd82e3c6 100644
--- a/tools/aien-test/src/worker.rs
+++ b/tools/aien-test/src/worker.rs
@@ -29,7 +29,7 @@ use crate::evidence::{canonical, canonical_digest, sha256_hex, utc_string};
 use crate::graph;
 use crate::plan::{self, Known, Section};
 use crate::process;
-use crate::resources::{Hardware, JobsSpec};
+use crate::resources::{self, Hardware, JobsSpec};
 use crate::runner::{self, CacheNote, Options};
 use crate::sandbox::Sandbox;
 use crate::verdict::Verdict;
@@ -40,7 +40,7 @@ use std::fs;
 use std::io::Write;
 use std::path::{Path, PathBuf};
 use std::process::Command;
-use std::time::{Duration, SystemTime, UNIX_EPOCH};
+use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
 
 pub const CONTEXT: &str = "AIEN Verification (Spark)";
 pub const EXECUTOR_CLASS: &str = "spark";
@@ -701,14 +701,14 @@ pub fn check_worktree_link(wt: &Path, mirror: &Path) -> Result<(), String> {
     Ok(())
 }
 
-/// Fetch the clone and add a detached worktree for `sha`. The clone's own
-/// checkout is never touched.
-fn checkout(
+/// Fetch the trusted clone of `repo` until it has `sha`. The clone's own
+/// checkout is never touched. Returns the clone.
+fn fetch_commit(
     cfg: &Config,
     repo: &str,
     sha: &str,
     notes: &mut Vec<String>,
-) -> Result<Checkout, String> {
+) -> Result<PathBuf, String> {
     let clone = cfg.clones.join(repo);
     if !clone.join(".git").exists() && !clone.join("HEAD").exists() {
         return Err(format!("no trusted clone at {}", clone.display()));
@@ -724,6 +724,48 @@ fn checkout(
     if !present(&clone) {
         return Err(format!("commit {sha} is not in {}", clone.display()));
     }
+    Ok(clone)
+}
+
+/// Hold the target dir the head's gates will build in, for the whole head
+/// (`resources::head_lock_path`, order (0) in `resources`). Taken before the
+/// head is checked out: a fresh checkout is then newer than every artifact
+/// in the dir, so cargo rebuilds this head's workspace crates instead of
+/// linking what another head left there (sc #597: two checkouts of one
+/// repository share cargo's metadata hash for their path crates, and with
+/// heads interleaved head B's checkout was older than the rlib head A had
+/// just built, so cargo took A's). Gates of different target dirs still run
+/// at the same time. `None` when the gates build in the worktree's own
+/// `target/`, which no other head shares.
+fn hold_target_dir(
+    cfg: &Config,
+    repo: &str,
+    sha: &str,
+    on_main: bool,
+    notes: &mut Vec<String>,
+) -> Result<Option<resources::TargetLock>, String> {
+    let Some(dir) = target_dir_for(cfg, repo, on_main) else {
+        return Ok(None);
+    };
+    let path = resources::head_lock_path(&cfg.state.target_lock_dir(), &dir);
+    cfg.state.beat(repo, sha, "target-wait");
+    let t = Instant::now();
+    let lock = resources::lock_target_dir(&path).map_err(|e| {
+        format!(
+            "cannot hold target dir {} for the head: {e}",
+            path.display()
+        )
+    })?;
+    notes.push(format!(
+        "target dir {} held for the whole head (waited {:.1} s)",
+        dir.display(),
+        t.elapsed().as_secs_f64()
+    ));
+    Ok(Some(lock))
+}
+
+/// Add a detached worktree for `sha` from the fetched trusted `clone`.
+fn checkout(cfg: &Config, repo: &str, sha: &str, clone: PathBuf) -> Result<Checkout, String> {
     if cfg.sandbox == Sandbox::User {
         let (wt, run_dir, nested) = checkout_for_sandbox(cfg, repo, sha, &clone)?;
         return Ok(Checkout {
@@ -832,8 +874,15 @@ pub fn run_once(cfg: &Config, repo: &str, sha: &str) -> Result<Summary, String>
     let sibs = siblings_for(cfg, repo)?;
     let pins = pins_for(cfg, repo)?;
     let mut notes: Vec<String> = Vec::new();
+    cfg.state.beat(repo, sha, "fetch");
+    let clone = fetch_commit(cfg, repo, sha, &mut notes)?;
+    // The trust class is decided from the trusted clone (the rule
+    // `run_in_worktree` applies again against the worktree) so the head's
+    // target dir is held before the checkout exists.
+    let (_, on_main) = plan::base_for(&clone, &cfg.base_ref, sha)?;
+    let _held = hold_target_dir(cfg, repo, sha, on_main, &mut notes)?;
     cfg.state.beat(repo, sha, "checkout");
-    let co = checkout(cfg, repo, sha, &mut notes)?;
+    let co = checkout(cfg, repo, sha, clone)?;
     ensure_pins(&cfg.clones, &pins, &sibs, &mut notes);
     let (made, pin_values) = provision_siblings(cfg, repo, sha, &co, &sibs, &pins, &mut notes);
     let (clone, wt) = (co.clone.clone(), co.wt.clone());
@@ -1156,7 +1205,8 @@ fn run_in_worktree(
 /// otherwise. The exec helper accepts only exactly those two paths under
 /// `/var/lib/aien-run/target` and creates the class dir on demand. Never the
 /// worker's own target dir, which `aien-run` cannot write. Without the
-/// sandbox, the worker's own `CARGO_TARGET_DIR`.
+/// sandbox, the worker's own `CARGO_TARGET_DIR`. Shared by every head of the
+/// class, so `hold_target_dir` keeps one head in it at a time.
 fn target_dir_for(cfg: &Config, repo: &str, on_main: bool) -> Option<PathBuf> {
     match cfg.sandbox {
         Sandbox::None => std::env::var_os("CARGO_TARGET_DIR").map(PathBuf::from),