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
About Files History Releases Proposed changes Issues For developers
aien-test: a gb10 gate checks free memory before it starts (short = NOT_RUN gpu_mem)
merged 148cbad35cdc012c #693 · opened 2026-10-20 03:08 UTC · closed 2026-10-30 03:33 UTC · merged 2026-10-30 03:33 UTC
Imported from GitHub aien-dev/aien-sovereign-core-mv#693, by drakestapleton
Base e728371bd83a6702c1122cacc0ab3e7ea0c10c3e · Head 1663d65cbc762ff612ff772a864ccf0ca268b222
Merged on GitHub as 8a49b64be9f3dd4c18e463e7fd5800de5bb99bca ; reachable from main 007ac4ac5ee5edc6f79f411b1706752293604044 (observed 2026-11-18T16:35:45Z)
drakestapleton wrote on 2026-10-20 03:08 UTC
What changes
A GB10 gate that holds the GPU locks now also needs MemAvailable >= DEFAULT_GPU_MEM_MB (6 GB). A short reading waits up to 15 min (the same polling style as the lock wait, #684). Still short: the locks are released and the gate is NOT_RUN gpu_mem (retryable, nothing judged), not FAIL.
Receipt: volatile.gpu_wait gains mem_need_mb and mem_free_mb. The refusal text carries the free and needed numbers.
A gate that starts and then fails stays FAIL (test gb10_gate_that_fails_after_it_starts_stays_fail).
Desk side (not in this repo): the operator retry in drive2/3/4 and hermes-retry re-runs a NOT_RUN gpu_mem as it does gpu_lock.
How the default was measured
Omega rx_r14_recovery_silicon built from omega origin/main, run under /tmp/aien-gb10.lock on the Spark, MemAvailable sampled every 0.5 s. Pre-run baseline 49.5-50.3 GB, in-run minimum 48.7 GB: a drop of 1.6 GB. The NO_MEMORY failures on omega#598 had 3-4 GB free, so the floor is about twice that failure point. The M19 silicon peak is not measured yet; the per-gate peaks come from the new receipt fields.
Verified
cargo test in tools/aien-test: 343 passed, 0 failed (Spark, CARGO_TARGET_DIR=targets/hermes-sc).
Red: bypassing the check makes six of the new tests fail; restored and green again.
cargo fmt -- --check clean.
Pipeline configuration
Touches tools/aien-test/ (rule A4): needs an operator run on the exact head. Redeploy of the live aien-test is a separate step (swap with aien-run-exec only while idle).
Fetch it
A git bundle of the pull request's head, 8883 bytes.
curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/148cbad35cdc012c .bundle -o 148cbad35cdc012c .bundle
git fetch 148cbad35cdc012c .bundle refs/pull/693/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
693
1663d65cbc762ff612ff772a864ccf0ca268b222
{"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":693,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/693","export_sha256":"d815604dc795b494a931d4c9d256159461266bed51d6da460421ed1d94dab90f ","imported_utc":"2026-11-18T16:35:45Z"}
Changes
diff --git a/.crumb b/.crumb
index e10d5e80 ..6b953d38 100644
--- a/.crumb
+++ b/.crumb
@@ -89,7 +89,7 @@
},
{
"digest": "3a331fee49e858953c344a75e26558ac2288bca4b335eed2f2702dfd77379e8e ",
- "last_commit": "75070c84 ",
+ "last_commit": "e728371b ",
"name": "crates/aien-heartbeat",
"purpose": "Expert Heartbeat H1 (aienix#4): fixed-slot versioned ring streaming MoE expert weights from NVMe"
},
@@ -125,14 +125,14 @@
}
],
"children_root": "sha256:ab951d662c7c12e63d462c163e2f5efff2d207bf22e5b6be32f5537a5735e522 ",
- "compiled_at": "2026-10-30T03:32:02Z",
+ "compiled_at": "2026-10-30T03:32:35Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:050655720fa36b9bed8c737bb4fa6c068bb03f581680dd5cbffd6603151d170f ",
+ "digest": "sha256:03a326818ddcc82e2ca2dc6ac78bddbc898bdd9b2d20fc386ae0e44bc7ec1332 ",
"evidence_files": 3586,
"evidence_root": "sha256:ee29710af304de14c30917f3cc8eb87c5b5e9a42b75dd9d009e842279d8075d0 ",
"files": 8073,
- "generated_at_commit": "5a901818ebea951800ab68cb43948561f7c8f5d8 ",
- "source_tree": "sha256:6509d6b7206cdf0401da4e509c23810389ea95f2a9e163c1c917c803fdb58598 "
+ "generated_at_commit": "89aa04809022b1e8d9985f770751fdaf64db01d4 ",
+ "source_tree": "sha256:1c34696de78494371336a056e9587f321a2b5f0d478d19750b99360eb3c988fe "
}
},
"history": [],
diff --git a/tools/aien-test/src/resources.rs b/tools/aien-test/src/resources.rs
index 6fd5581a ..8df5c02b 100644
--- a/tools/aien-test/src/resources.rs
+++ b/tools/aien-test/src/resources.rs
@@ -76,6 +76,26 @@ pub const DEFAULT_GPU_LOCK: &str = "/tmp/aien-gb10.lock";
/// requests on 2026-10-19 (serve.log), so the bound covers many turns.
pub const DEFAULT_GPU_WAIT: Duration = Duration::from_secs(30 * 60);
+/// MemAvailable (MB) a gb10 gate needs before it starts, checked with the GPU
+/// locks held. Measured on the Spark, 2026-10-20 (omega rx_r14_recovery_silicon
+/// under the GB10 lock, MemAvailable sampled every 0.5 s): baseline drift
+/// 0.8 GB, drop to 1.6 GB below the pre-run baseline during the run. The
+/// omega silicon gates that failed NO_MEMORY at channel create had 3-4 GB
+/// free, so the floor sits about twice that failure point. Replace it with
+/// per-gate peaks from the `volatile.gpu_wait` fields as they accrue.
+pub const DEFAULT_GPU_MEM_MB: u64 = 6 * 1024;
+
+/// How long a gb10 gate waits, holding the GPU locks, for `DEFAULT_GPU_MEM_MB`
+/// to show as free. Short on purpose: a 27B server holds its weights for hours,
+/// and a memory-short gate is NOT_RUN `gpu_mem` (retryable), not FAIL.
+pub const DEFAULT_GPU_MEM_WAIT: Duration = Duration::from_secs(15 * 60);
+
+/// Poll interval of the memory wait.
+const GPU_MEM_POLL: Duration = Duration::from_secs(5);
+
+/// The memory reading (procfs).
+pub const DEFAULT_MEMINFO: &str = "/proc/meminfo";
+
/// What a gb10 gate does when another holder has a GPU lock.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GpuWait {
@@ -355,6 +375,13 @@ pub struct GpuConfig {
pub proc_dir: PathBuf,
/// How long to wait for a held lock (`--gpu-wait`, `--wait-gpu`).
pub wait: GpuWait,
+ /// The memory reading (`/proc/meminfo`, MemAvailable); a file so a test
+ /// can fake it.
+ pub meminfo: PathBuf,
+ /// MB of MemAvailable a gate needs once it holds the locks; 0 = not checked.
+ pub mem_need_mb: u64,
+ /// How long to wait, holding the locks, for `mem_need_mb` to show as free.
+ pub mem_wait: Duration,
}
impl GpuConfig {
@@ -374,6 +401,9 @@ impl GpuConfig {
quiet_flag: home.map(|h| h.join("workspace/.spark-quiet")),
proc_dir: PathBuf::from("/proc"),
wait: GpuWait::Bounded(DEFAULT_GPU_WAIT),
+ meminfo: PathBuf::from(DEFAULT_MEMINFO),
+ mem_need_mb: DEFAULT_GPU_MEM_MB,
+ mem_wait: DEFAULT_GPU_MEM_WAIT,
}
}
@@ -386,6 +416,11 @@ impl GpuConfig {
quiet_flag: Some(dir.join("quiet-flag")),
proc_dir: dir.join("proc"),
wait: GpuWait::Refuse,
+ meminfo: dir.join("meminfo"),
+ // Not checked unless a test asks: the tests of the lock protocol
+ // do not depend on the machine's memory.
+ mem_need_mb: 0,
+ mem_wait: Duration::ZERO,
}
}
}
@@ -403,6 +438,9 @@ pub enum GpuRefusal {
LockHeld(PathBuf),
/// Another holder has aien-proof's `slots/gpu.lock` (`gpu_lock_proof`).
ProofLockHeld(PathBuf),
+ /// The locks were taken but MemAvailable stayed below what the gate needs
+ /// (`gpu_mem`, retryable: nothing ran). `None` = the reading was unreadable.
+ MemShort { free_mb: Option<u64>, need_mb: u64 },
}
impl GpuRefusal {
@@ -413,6 +451,7 @@ impl GpuRefusal {
GpuRefusal::LockOpen(_) => "gpu_open",
GpuRefusal::LockHeld(_) => "gpu_lock",
GpuRefusal::ProofLockHeld(_) => "gpu_lock_proof",
+ GpuRefusal::MemShort { .. } => "gpu_mem",
}
}
}
@@ -427,7 +466,45 @@ impl fmt::Display for GpuRefusal {
GpuRefusal::ProofLockHeld(p) => {
write!(f, "aien-proof GPU lock {} is held", p.display())
}
+ GpuRefusal::MemShort { free_mb, need_mb } => match free_mb {
+ Some(free) => write!(
+ f,
+ "free memory {free} MB, the gate needs {need_mb} MB (MemAvailable)"
+ ),
+ None => write!(
+ f,
+ "free memory unreadable, the gate needs {need_mb} MB (MemAvailable)"
+ ),
+ },
+ }
+ }
+}
+
+/// MemAvailable in MB from a meminfo file; None when it cannot be read.
+pub fn mem_available_mb(meminfo: &Path) -> Option<u64> {
+ let text = fs::read_to_string(meminfo).ok()?;
+ let line = text.lines().find(|l| l.starts_with("MemAvailable:"))?;
+ let kib: u64 = line.split_whitespace().nth(1)?.parse().ok()?;
+ Some(kib / 1024)
+}
+
+/// Wait until MemAvailable reaches `need_mb`, polling every `GPU_MEM_POLL`
+/// and giving up after `bound` (0 = one reading). Ok(free) when it did;
+/// Err(last reading) when it did not.
+pub fn wait_for_memory(meminfo: &Path, need_mb: u64, bound: Duration) -> Result<u64, Option<u64>> {
+ let t0 = Instant::now();
+ loop {
+ let free = mem_available_mb(meminfo);
+ if let Some(f) = free {
+ if f >= need_mb {
+ return Ok(f);
+ }
+ }
+ let left = bound.saturating_sub(t0.elapsed());
+ if left.is_zero() {
+ return Err(free);
}
+ std::thread::sleep(GPU_MEM_POLL.min(left));
}
}
@@ -733,6 +810,11 @@ fn take_lock(
pub struct GpuAttempt {
pub result: Result<GpuGuard, GpuRefusal>,
pub waited: Duration,
+ /// MemAvailable (MB) read after the locks were taken; None when the
+ /// memory check is off or the locks were refused first.
+ pub mem_free_mb: Option<u64>,
+ /// `GpuConfig::mem_need_mb` at the time of the attempt (0 = not checked).
+ pub mem_need_mb: u64,
}
/// The GPU job protocol up to the point of running: refusals first, then the
@@ -741,13 +823,34 @@ pub fn acquire_gpu(cfg: &GpuConfig) -> Result<GpuGuard, GpuRefusal> {
acquire_gpu_timed(cfg).result
}
-/// `acquire_gpu`, also reporting the wait. One bound covers both locks.
+/// `acquire_gpu`, also reporting the wait. One bound covers both locks. With
+/// a memory need set, the memory is checked once the locks are held; a short
+/// reading waits up to `mem_wait` for it, then refuses as `gpu_mem` and gives
+/// the locks back (the guard drops here, through the spawn gate).
pub fn acquire_gpu_timed(cfg: &GpuConfig) -> GpuAttempt {
let t0 = Instant::now();
- let result = acquire_locks(cfg, t0);
+ let (result, mem_free_mb) = match acquire_locks(cfg, t0) {
+ Err(r) => (Err(r), None),
+ Ok(guard) if cfg.mem_need_mb == 0 => (Ok(guard), None),
+ Ok(guard) => match wait_for_memory(&cfg.meminfo, cfg.mem_need_mb, cfg.mem_wait) {
+ Ok(free) => (Ok(guard), Some(free)),
+ Err(free) => {
+ drop(guard);
+ (
+ Err(GpuRefusal::MemShort {
+ free_mb: free,
+ need_mb: cfg.mem_need_mb,
+ }),
+ free,
+ )
+ }
+ },
+ };
GpuAttempt {
result,
waited: t0.elapsed(),
+ mem_free_mb,
+ mem_need_mb: cfg.mem_need_mb,
}
}
@@ -1114,6 +1217,101 @@ mod tests {
drop(held);
}
+ fn fake_meminfo(dir: &Path, mb: u64) {
+ write_file(
+ dir,
+ "meminfo",
+ &format!(
+ "MemTotal: 127598528 kB\nMemAvailable: {} kB\n",
+ mb * 1024
+ ),
+ false,
+ );
+ }
+
+ #[test]
+ fn short_memory_is_refused_as_gpu_mem_and_gives_the_locks_back() {
+ let d = TempDir::new("gpu");
+ let mut cfg = GpuConfig::rooted_at(d.path());
+ cfg.mem_need_mb = 100;
+ cfg.mem_wait = Duration::from_millis(300);
+ fake_meminfo(d.path(), 40);
+ let a = acquire_gpu_timed(&cfg);
+ assert!(
+ matches!(
+ a.result,
+ Err(GpuRefusal::MemShort {
+ free_mb: Some(40),
+ need_mb: 100
+ })
+ ),
+ "{:?}",
+ a.result.as_ref().err()
+ );
+ assert_eq!(a.result.as_ref().err().unwrap().reason(), "gpu_mem");
+ assert_eq!((a.mem_free_mb, a.mem_need_mb), (Some(40), 100));
+ assert!(a.waited >= Duration::from_millis(300), "{:?}", a.waited);
+ // The refused gate released the lock: the next job takes it.
+ cfg.mem_need_mb = 0;
+ assert!(acquire_gpu(&cfg).is_ok());
+ }
+
+ #[test]
+ fn enough_memory_runs_and_records_the_reading() {
+ let d = TempDir::new("gpu");
+ let mut cfg = GpuConfig::rooted_at(d.path());
+ cfg.mem_need_mb = 100;
+ cfg.mem_wait = Duration::from_millis(300);
+ fake_meminfo(d.path(), 200);
+ let a = acquire_gpu_timed(&cfg);
+ assert!(a.result.is_ok(), "{:?}", a.result.as_ref().err());
+ assert_eq!((a.mem_free_mb, a.mem_need_mb), (Some(200), 100));
+ }
+
+ #[test]
+ fn memory_that_comes_back_within_the_bound_runs() {
+ let d = TempDir::new("gpu");
+ let mut cfg = GpuConfig::rooted_at(d.path());
+ cfg.mem_need_mb = 100;
+ cfg.mem_wait = Duration::from_secs(20);
+ fake_meminfo(d.path(), 40);
+ let p = d.path().join("meminfo");
+ let freer = std::thread::spawn(move || {
+ std::thread::sleep(Duration::from_millis(700));
+ fs::write(p, "MemTotal: 127598528 kB\nMemAvailable: 204800 kB\n").unwrap();
+ });
+ let a = acquire_gpu_timed(&cfg);
+ freer.join().unwrap();
+ assert!(a.result.is_ok(), "{:?}", a.result.as_ref().err());
+ assert_eq!(a.mem_free_mb, Some(200));
+ assert!(a.waited < Duration::from_secs(20), "{:?}", a.waited);
+ }
+
+ #[test]
+ fn unreadable_memory_is_refused_not_run() {
+ let d = TempDir::new("gpu");
+ let mut cfg = GpuConfig::rooted_at(d.path());
+ cfg.mem_need_mb = 100;
+ // No meminfo file in the scratch dir.
+ let a = acquire_gpu_timed(&cfg);
+ assert!(matches!(
+ a.result,
+ Err(GpuRefusal::MemShort {
+ free_mb: None,
+ need_mb: 100
+ })
+ ));
+ assert_eq!(a.mem_free_mb, None);
+ }
+
+ #[test]
+ fn the_machine_default_checks_the_measured_floor() {
+ let cfg = GpuConfig::detect();
+ assert_eq!(cfg.mem_need_mb, DEFAULT_GPU_MEM_MB);
+ assert_eq!(cfg.meminfo, PathBuf::from(DEFAULT_MEMINFO));
+ assert_eq!(GpuConfig::rooted_at(Path::new("/x")).mem_need_mb, 0);
+ }
+
#[test]
fn open_handle_without_flock_does_not_block() {
// CR-052: only a flock holder blocks; a plain open handle does not.
diff --git a/tools/aien-test/src/runner.rs b/tools/aien-test/src/runner.rs
index fb5bfb42 ..d4931af0 100644
--- a/tools/aien-test/src/runner.rs
+++ b/tools/aien-test/src/runner.rs
@@ -1058,6 +1058,10 @@ fn execute_gate(job: &Job<'_>, permit: Option<Permit<'_>>) -> Result<Outcome, Ru
"bound_ms": opts.gpu.wait.bound_ms(),
"waited_ms": attempt.waited.as_millis() as u64,
"acquired": attempt.result.is_ok(),
+ // The memory check (gpu_mem): what the gate needed and what was free
+ // once it held the locks (null when not checked or refused first).
+ "mem_need_mb": attempt.mem_need_mb,
+ "mem_free_mb": attempt.mem_free_mb,
});
match attempt.result {
Ok(g) => Some(g),
@@ -2149,6 +2153,8 @@ mod tests {
opts.gpu.proof_lock_path = None;
opts.gpu.quiet_flag = scratch.quiet_flag;
opts.gpu.proc_dir = scratch.proc_dir;
+ // The memory check has its own tests below; this one is about the lock wait.
+ opts.gpu.mem_need_mb = 0;
let held = acquire_gpu(&GpuConfig::rooted_at(fx.scratch.path())).unwrap();
let holder = std::thread::spawn(move || {
std::thread::sleep(Duration::from_millis(1500));
@@ -2218,6 +2224,87 @@ mod tests {
assert_eq!(o.verdict, Verdict::Pass, "reason {}", o.reason);
}
+ /// A gb10 gate whose memory reading is short is NOT_RUN `gpu_mem` with the
+ /// numbers in the receipt, and its job never starts (retryable, nothing judged).
+ #[test]
+ fn gb10_gate_short_of_memory_is_not_run_gpu_mem_and_does_not_start() {
+ let fx = gb10_fixture(TOUCH_MARKER, "20s");
+ let mut opts = gb10_opts(&fx);
+ write_file(
+ fx.scratch.path(),
+ "meminfo",
+ "MemAvailable: 40960 kB\n",
+ false,
+ );
+ opts.gpu.meminfo = fx.scratch.path().join("meminfo");
+ opts.gpu.mem_need_mb = 100;
+ opts.gpu.mem_wait = Duration::from_millis(300);
+ let o = run(&fx, &opts);
+ assert_eq!(
+ (o.verdict, o.reason.as_str()),
+ (Verdict::NotRun, "gpu_mem"),
+ "{}",
+ o.reason
+ );
+ assert!(!fx.marker().exists(), "a memory-short job must not run");
+ let r = read_json(&o.receipt_path.unwrap());
+ assert_eq!(r["core"]["reason"], "gpu_mem");
+ let w = &r["volatile"]["gpu_wait"];
+ assert_eq!(w["acquired"], false);
+ assert_eq!(w["mem_free_mb"], 40);
+ assert_eq!(w["mem_need_mb"], 100);
+ // The locks went back: the same gate with enough memory runs.
+ write_file(
+ fx.scratch.path(),
+ "meminfo",
+ "MemAvailable: 204800 kB\n",
+ false,
+ );
+ let o = run(&fx, &opts);
+ assert_eq!(o.verdict, Verdict::Pass, "reason {}", o.reason);
+ assert!(fx.marker().exists());
+ }
+
+ #[test]
+ fn gb10_gate_with_enough_memory_runs_and_records_the_reading() {
+ let fx = gb10_fixture(TOUCH_MARKER, "20s");
+ let mut opts = gb10_opts(&fx);
+ write_file(
+ fx.scratch.path(),
+ "meminfo",
+ "MemAvailable: 204800 kB\n",
+ false,
+ );
+ opts.gpu.meminfo = fx.scratch.path().join("meminfo");
+ opts.gpu.mem_need_mb = 100;
+ let o = run(&fx, &opts);
+ assert_eq!(o.verdict, Verdict::Pass, "reason {}", o.reason);
+ assert!(fx.marker().exists());
+ let r = read_json(&o.receipt_path.unwrap());
+ let w = &r["volatile"]["gpu_wait"];
+ assert_eq!(w["acquired"], true);
+ assert_eq!(w["mem_free_mb"], 200);
+ }
+
+ /// A gate that starts with enough memory and then fails is a real FAIL,
+ /// never NOT_RUN: the memory check only decides whether the job starts.
+ #[test]
+ fn gb10_gate_that_fails_after_it_starts_stays_fail() {
+ let fx = gb10_fixture("#!/bin/sh\nexit 1\n", "20s");
+ let mut opts = gb10_opts(&fx);
+ write_file(
+ fx.scratch.path(),
+ "meminfo",
+ "MemAvailable: 204800 kB\n",
+ false,
+ );
+ opts.gpu.meminfo = fx.scratch.path().join("meminfo");
+ opts.gpu.mem_need_mb = 100;
+ let o = run(&fx, &opts);
+ assert_eq!(o.verdict, Verdict::Fail, "reason {}", o.reason);
+ assert_ne!(o.reason, "gpu_mem");
+ }
+
#[test]
fn host_gate_records_no_gpu_wait() {
let fx = fixture(TOUCH_MARKER, 0, &[], "20s", "");