From afb7b7c5a9097fcc52527eede0685b9d56a892dc Mon Sep 17 00:00:00 2001 From: aien Date: Sun, 11 Oct 2026 09:26:54 -0500 Subject: [PATCH 1/3] runtime: an explicitly CPU-only run uses the CPU backend or refuses to start (sc#384 preflight) AIEN_FORCE_CPU_STUB is build-time only. AIEN_BACKEND=cpu now makes the daemon refuse (CPU_ONLY_BUT_GPU_BUILD) before any model load if the binary has the GB10 engine linked. Co-Authored-By: Claude Fable 5.1 --- crates/aien-cli/src/commands.rs | 48 ++++++++++++ crates/aien-cli/tests/cpu_only_switch_test.rs | 78 +++++++++++++++++++ crates/aien-omega-compose/README.md | 2 +- crates/aien-omega-gpu/build.rs | 4 +- 4 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 crates/aien-cli/tests/cpu_only_switch_test.rs diff --git a/crates/aien-cli/src/commands.rs b/crates/aien-cli/src/commands.rs index 1bcd62da..e4de7047 100644 --- a/crates/aien-cli/src/commands.rs +++ b/crates/aien-cli/src/commands.rs @@ -1527,6 +1527,31 @@ type DaemonBackendParts = ( Option, ); +/// Runtime switch for an explicitly CPU-only run (sc#384 preflight). `AIEN_FORCE_CPU_STUB=1` +/// is a BUILD-time flag (crates/aien-omega-gpu/build.rs): it only stubs the GPU library when +/// compiling, and a binary built earlier with the GPU library ignores it at run time. +pub const CPU_ONLY_ENV: &str = "AIEN_BACKEND"; + +/// Stable name of the refusal, so scripts and tests can match it. +pub const CPU_ONLY_REFUSAL: &str = "CPU_ONLY_BUT_GPU_BUILD"; + +/// True when `AIEN_BACKEND=cpu` (case-insensitive) is set. +fn cpu_only_requested(value: Option<&str>) -> bool { + value.is_some_and(|v| v.trim().eq_ignore_ascii_case("cpu")) +} + +/// Preflight: an explicitly CPU-only run either uses the CPU backend or refuses to start. +/// Decided before any model load or GPU session is opened. `native_linked` is whether this +/// binary carries the real GPU library. +fn cpu_only_preflight(value: Option<&str>, native_linked: bool) -> Result<(), String> { + if cpu_only_requested(value) && native_linked { + return Err(format!( + "{CPU_ONLY_REFUSAL}: {CPU_ONLY_ENV}=cpu asks for a CPU-only run, but this binary has the GB10 GPU engine linked and would select it. Refusing to start. Use a CPU-stub build (AIEN_FORCE_CPU_STUB=1 at build time) or unset {CPU_ONLY_ENV}. Note AIEN_FORCE_CPU_STUB does nothing at run time." + )); + } + Ok(()) +} + fn build_native_daemon_backend() -> Result { let policy = CheckpointPolicy::from_env(); let manifest = resolve_daemon_manifest_with(&policy); @@ -1732,6 +1757,14 @@ pub async fn run_daemon_server() { "{}", "⚡ Starting AIEN Sovereign Runtime Daemon...".cyan().bold() ); + // sc#384 preflight: an explicitly CPU-only run never reaches a GPU build. + if let Err(fatal) = cpu_only_preflight( + std::env::var(CPU_ONLY_ENV).ok().as_deref(), + aien_omega_gpu::is_native(), + ) { + eprintln!("Fatal: {}", fatal.red().bold()); + std::process::exit(1); + } // NEXT-PHASE-2 (ACCEPTANCE-v2 2.8): damaged idempotency state refuses the // start; it is never reset silently. if let Err(fatal) = aien_runtime::control::RuntimeController::load() { @@ -2237,6 +2270,21 @@ pub async fn handle_aegis_command() { mod tests { use super::*; + #[test] + fn cpu_only_switch_never_selects_gpu() { + // GPU-capable build: refuses with the named error. + let e = cpu_only_preflight(Some("cpu"), true).unwrap_err(); + assert!(e.starts_with(CPU_ONLY_REFUSAL), "{e}"); + assert!(cpu_only_preflight(Some(" CPU "), true).is_err()); + // Stub build: allowed, the CPU reference backend is then the only one possible. + assert!(cpu_only_preflight(Some("cpu"), false).is_ok()); + // Not requested: unchanged behaviour. + assert!(cpu_only_preflight(None, true).is_ok()); + assert!(cpu_only_preflight(Some("gpu"), true).is_ok()); + // AIEN_FORCE_CPU_STUB alone is not the switch. + assert!(!cpu_only_requested(Some("1"))); + } + #[test] fn start_refusal_names_the_exact_command() { let t = start_refusal_text("no key at /x"); diff --git a/crates/aien-cli/tests/cpu_only_switch_test.rs b/crates/aien-cli/tests/cpu_only_switch_test.rs new file mode 100644 index 00000000..971aa69e --- /dev/null +++ b/crates/aien-cli/tests/cpu_only_switch_test.rs @@ -0,0 +1,78 @@ +//! sc#384 preflight: `AIEN_BACKEND=cpu` on a real `aien daemon` process. +//! Whatever the build, the daemon never reports the GB10 backend: +//! - GPU-capable build: refuses to start with the named error `CPU_ONLY_BUT_GPU_BUILD` +//! (before any model load or GPU session); +//! - CPU-stub build: the switch is accepted (the CPU backend is the only one possible); +//! here the start is stopped one step later by the approval-desk requirement, with no +//! desk key, so no model is needed and the test never touches the chip. +use std::process::{Command, Stdio}; + +fn run(extra: &[(&str, &str)]) -> (bool, String) { + let tmp = tempfile::Builder::new() + .prefix("co-") + .tempdir_in("/tmp") + .unwrap(); + let root = std::fs::canonicalize(tmp.path()).unwrap(); + for d in ["state", "home", "prov"] { + std::fs::create_dir_all(root.join(d)).unwrap(); + } + let mut c = Command::new(env!("CARGO_BIN_EXE_aien-cli")); + c.current_dir(&root) + .env("HOME", root.join("home")) + .env("NO_COLOR", "1") + .env("AIEN_RUNTIME_SOCK", root.join("s")) + .env("AIEN_RUNTIME_STATE_DIR", root.join("state")) + .env("AIEN_COMPOSE_DIR", root.join("compose")) + .env("AIEN_PROVENANCE_DIR", root.join("prov")) + .env("AIEN_REQUIRE_CHECKPOINT", "0"); + for k in [ + "AIEN_BACKEND", + "AIEN_REQUIRE_BLACKWELL", + "AIEN_GPU_BACKEND", + "AIEN_MODEL_PATH", + "AIEN_TOKENIZER_PATH", + "AIEN_MODEL_DIR", + "AIEN_DEV_FALLBACK", + "AIEN_COMPOSE_AUTHORIZE_REQUIRES_DESK", + ] { + c.env_remove(k); + } + for (k, v) in extra { + c.env(k, v); + } + let out = c + .arg("daemon") + .stdin(Stdio::null()) + .output() + .expect("run daemon"); + let text = format!( + "{}{}", + String::from_utf8_lossy(&out.stdout), + String::from_utf8_lossy(&out.stderr) + ); + (out.status.success(), text) +} + +#[test] +fn cpu_only_daemon_never_reports_gb10() { + let (ok, text) = run(&[("AIEN_BACKEND", "cpu")]); + assert!( + !ok, + "the start must be refused (named error or desk): {text}" + ); + assert!( + !text.contains("OmegaGb10Backend") && !text.contains("sm_121"), + "a CPU-only run reported the GB10 backend: {text}" + ); + if aien_omega_gpu::is_native() { + assert!(text.contains("CPU_ONLY_BUT_GPU_BUILD"), "{text}"); + } else { + assert!(!text.contains("CPU_ONLY_BUT_GPU_BUILD"), "{text}"); + } +} + +#[test] +fn force_cpu_stub_alone_is_not_the_runtime_switch() { + let (_ok, text) = run(&[("AIEN_FORCE_CPU_STUB", "1")]); + assert!(!text.contains("CPU_ONLY_BUT_GPU_BUILD"), "{text}"); +} diff --git a/crates/aien-omega-compose/README.md b/crates/aien-omega-compose/README.md index 705da448..cbd7a8fb 100644 --- a/crates/aien-omega-compose/README.md +++ b/crates/aien-omega-compose/README.md @@ -25,7 +25,7 @@ cargo test -p aien-omega-compose | `AIEN_PHYSICS_DIR` | physics checkout at omega's `physics.lock` (default `/../physics`) | | `AIEN_AIENOS_LOCK_REPO` | aienos clone holding omega's `aienos.lock` commit (passed as `AIENOS_LOCK_REPO`) | | `AIEN_OMEGA_COMPOSE_LIB` | link a prebuilt `librx_compose.a` instead (not sha-checked) | -| `AIEN_FORCE_CPU_STUB=1` | stub: every call returns `ComposeError::Unavailable` | +| `AIEN_FORCE_CPU_STUB=1` | stub: every call returns `ComposeError::Unavailable` (build time only; for a CPU-only run use `AIEN_BACKEND=cpu`, which makes the daemon refuse a GPU build) | With no checkout and no library set the crate builds the stub and prints a warning. Use `AIEN_OMEGA_COMPOSE_DIR` together with `AIEN_OMEGA_COMPOSE_SHA`, so an override diff --git a/crates/aien-omega-gpu/build.rs b/crates/aien-omega-gpu/build.rs index 325f8590..1ba14d68 100644 --- a/crates/aien-omega-gpu/build.rs +++ b/crates/aien-omega-gpu/build.rs @@ -1,7 +1,9 @@ //! Links `libomega_gpu.a` from the omega commit pinned in `omega.lock`. //! //! Offline by design: nothing is downloaded and no CUDA/nvcc is used. Order: -//! 1. `AIEN_FORCE_CPU_STUB=1` -> stub (CI without the chip). +//! 1. `AIEN_FORCE_CPU_STUB=1` -> stub (CI without the chip). BUILD-TIME ONLY: a binary already +//! built with the GPU library ignores it at run time. For a CPU-only RUN set `AIEN_BACKEND=cpu`: +//! the daemon refuses to start (`CPU_ONLY_BUT_GPU_BUILD`) if the binary would select the GB10 backend. //! 2. `AIEN_OMEGA_GPU_LIB=` -> link that prebuilt archive (not sha-checked). //! 3. `AIEN_OMEGA_DIR=` -> its HEAD must equal omega.lock; built with //! `make libomega_gpu` into OUT_DIR. `AIEN_PHYSICS_DIR` (default `/../physics`) From 1d222e14f5d423bec85fd5c68bc68e31d5b66f75 Mon Sep 17 00:00:00 2001 From: aien Date: Sun, 11 Oct 2026 09:27:00 -0500 Subject: [PATCH 2/3] crumb compile Co-Authored-By: Claude Fable 5.1 --- crates/aien-cli/.crumb | 16 ++++++++-------- crates/aien-cli/src/.crumb | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/aien-cli/.crumb b/crates/aien-cli/.crumb index 9c5a49c9..b58d3c05 100644 --- a/crates/aien-cli/.crumb +++ b/crates/aien-cli/.crumb @@ -34,21 +34,21 @@ "generated": { "children": [ { - "digest": "0d7cbe9cf349fd494cea36df598cbf5a4c97aa969524333c1b67ddb271be85fb", - "last_commit": "ecb7b00", + "digest": "85c08d443d770fb3efc1d973558dfcbe90d2a918d180722169e5620b7792fa0e", + "last_commit": "5fb8c6a", "name": "src", "purpose": "" } ], - "children_root": "sha256:6ecbe9238675fedfa699fe63d3a9b36e95a93cf0c380aa0e2c9dd456ee49c7e1", - "compiled_at": "2026-10-11T04:00:54Z", + "children_root": "sha256:d13f33e33c2bbbfb13571751edee311327b23f4975b9a5465760a22b629b386e", + "compiled_at": "2026-10-11T14:26:54Z", "compiler": "crumb-compile/1", - "digest": "sha256:e3127bf29b97d40da109561ad86d1d74e0989f379eeed51741517257bc15d3b1", + "digest": "sha256:7319d18a72b10027385d3aff513059c0f2f8dfe60b0bc9a491e0a36862c0b5e0", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 40, - "generated_at_commit": "ecb7b00f13c83a6900f18afb2c3a7d32660a83e9", - "source_tree": "sha256:957017e7747b9408a181e7db9bfa836e3aa560c512da1ec298eed1975b4b3cc8" + "files": 41, + "generated_at_commit": "5fb8c6aba59a1d3ec2ab162ccf0f5e7d8dfe072a", + "source_tree": "sha256:a6962b14c07eb4eb7bd2f626f485f20f086481db9dd9ad1bd29c495917961be4" } }, "history": [ diff --git a/crates/aien-cli/src/.crumb b/crates/aien-cli/src/.crumb index 42d20135..b0b1407a 100644 --- a/crates/aien-cli/src/.crumb +++ b/crates/aien-cli/src/.crumb @@ -64,14 +64,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-11T04:00:54Z", + "compiled_at": "2026-10-11T14:26:54Z", "compiler": "crumb-compile/1", - "digest": "sha256:0d7cbe9cf349fd494cea36df598cbf5a4c97aa969524333c1b67ddb271be85fb", + "digest": "sha256:85c08d443d770fb3efc1d973558dfcbe90d2a918d180722169e5620b7792fa0e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 29, - "generated_at_commit": "ecb7b00f13c83a6900f18afb2c3a7d32660a83e9", - "source_tree": "sha256:a19a681396d82957b581d2e05d8858e8363dfadeafa13e0de5add9ea0a5e1ad2" + "generated_at_commit": "5fb8c6aba59a1d3ec2ab162ccf0f5e7d8dfe072a", + "source_tree": "sha256:fad3d38a33c8e8475b2f03bbbb214b3cc602790dc19c60625f18bb2a77de9754" } }, "history": [ From 32f5b067fa2331bbef05bd80a9b48254ef9baabd Mon Sep 17 00:00:00 2001 From: aien Date: Sun, 11 Oct 2026 09:52:46 -0500 Subject: [PATCH 3/3] crumb compile (after rebase onto main) Co-authored-by: Drake Stapleton Co-Authored-By: Claude Fable 5.1 --- .crumb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.crumb b/.crumb index 0e7e272d..6cc3cb07 100644 --- a/.crumb +++ b/.crumb @@ -77,14 +77,14 @@ } ], "children_root": "sha256:9b69c98f2b943ef9c4a3768e892e02b1856c6bd53647de0688f375e86e964ee1", - "compiled_at": "2026-10-11T14:41:07Z", + "compiled_at": "2026-10-11T14:52:45Z", "compiler": "crumb-compile/1", - "digest": "sha256:cc09b847d831c7066cdd2884c047a2e26392a86d712eacccfb6753040c971dad", + "digest": "sha256:499b335b430cb6b0eba2b67e02b546f09639e1c8441bfa1e4e5d41f5063367d5", "evidence_files": 187, "evidence_root": "sha256:27ee0353cb4d4aae2b7dbce2bfe0d9f4ef2a94cd7a4555b84684d59372503280", - "files": 3555, - "generated_at_commit": "d242721708755066905617ac3e0fa06cd8d9634e", - "source_tree": "sha256:e75e3891e40d4c91ca772bcdcce8cf5fc995364ee0a176c52d19aae8d6d49f64" + "files": 3556, + "generated_at_commit": "1d222e14f5d423bec85fd5c68bc68e31d5b66f75", + "source_tree": "sha256:f839a1896f0c478e14324248127c5afd8970e669c2f0aa99e28fd0e1600a5ce2" } }, "history": [],