From b76d65a11df1d5330e9d1527be26f8c6dbb56ecf Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 22 Oct 2026 10:44:04 -0500 Subject: [PATCH 1/9] Pin canonical CUDApp motor through the qualified Omega archive --- native-artifacts.lock | 1 + omega.lock | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/native-artifacts.lock b/native-artifacts.lock index 7a39b1e7..b2d9515b 100644 --- a/native-artifacts.lock +++ b/native-artifacts.lock @@ -30,3 +30,4 @@ librx_compose.a 62833658f5c291f0d229b45d2c18500145cbab66 aarch64-unknown-linux-g libomega_gpu.a 62833658f5c291f0d229b45d2c18500145cbab66 aarch64-unknown-linux-gnu 6a6cb4df479ddbcc5cd4ef0fda1aea968832b2b70be2ff3312051c3e9921aad5 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 librx_compose.a 4799f9eba563e9c69579b47c477e7d9c2b0f15cb aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a 4799f9eba563e9c69579b47c477e7d9c2b0f15cb aarch64-unknown-linux-gnu 0629ad9cec0addd4ccc461f0523c2c3964964f0bafc0b98b678e5080b0373ae5 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +libomega_gpu.a d14b568f88f5ab2637382f6ce32761fbdad7aeee aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 diff --git a/omega.lock b/omega.lock index ffbd8369..20996a1b 100644 --- a/omega.lock +++ b/omega.lock @@ -1 +1 @@ -7c2ae49e22b5d4d771e6ae8757a03975a73c5abd +d14b568f88f5ab2637382f6ce32761fbdad7aeee From 0839fe01d362c3ed293b10765043d5501c3a62df Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 22 Oct 2026 10:47:20 -0500 Subject: [PATCH 2/9] Bind Rust ABI and tests to canonical motor capacity --- crates/aien-omega-gpu/abi/omega_gpu.manifest | 2 +- crates/aien-omega-gpu/src/ffi.rs | 2 +- crates/aien-omega-gpu/src/lib.rs | 6 +++--- native-artifacts.lock | 1 + omega.lock | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/aien-omega-gpu/abi/omega_gpu.manifest b/crates/aien-omega-gpu/abi/omega_gpu.manifest index aecb3199..06a41cb3 100644 --- a/crates/aien-omega-gpu/abi/omega_gpu.manifest +++ b/crates/aien-omega-gpu/abi/omega_gpu.manifest @@ -105,7 +105,7 @@ const OMEGA_GPU_MATMUL_PARITY_FAIL -5 const OMEGA_GPU_MATMUL_TILE_M 16 const OMEGA_GPU_MATMUL_TILE_N 8 const OMEGA_GPU_MATMUL_TILE_K 16 -const OMEGA_GPU_MATMUL_MAX_CTAS 64 +const OMEGA_GPU_MATMUL_MAX_CTAS 1024 const OMEGA_GPU_EW_OK 0 const OMEGA_GPU_EW_BAD_ARGS -1 const OMEGA_GPU_EW_TOO_LARGE -2 diff --git a/crates/aien-omega-gpu/src/ffi.rs b/crates/aien-omega-gpu/src/ffi.rs index e8b5ccd0..18375c77 100644 --- a/crates/aien-omega-gpu/src/ffi.rs +++ b/crates/aien-omega-gpu/src/ffi.rs @@ -24,7 +24,7 @@ pub const OMEGA_GPU_MATMUL_PARITY_FAIL: c_int = -5; pub const OMEGA_GPU_MATMUL_TILE_M: u32 = 16; pub const OMEGA_GPU_MATMUL_TILE_N: u32 = 8; pub const OMEGA_GPU_MATMUL_TILE_K: u32 = 16; -pub const OMEGA_GPU_MATMUL_MAX_CTAS: u32 = 64; +pub const OMEGA_GPU_MATMUL_MAX_CTAS: u32 = 1024; } abi_struct! { diff --git a/crates/aien-omega-gpu/src/lib.rs b/crates/aien-omega-gpu/src/lib.rs index 58ddfc5f..da9550df 100644 --- a/crates/aien-omega-gpu/src/lib.rs +++ b/crates/aien-omega-gpu/src/lib.rs @@ -407,7 +407,7 @@ pub fn is_blocked() -> bool { /// Daemon setting that picks the matmul CTA budget per launch. Unset or empty /// means the AIEN daemon default ([`DAEMON_DEFAULT_CTA_BUDGET`], 1024); omega's -/// own library default ([`ffi::OMEGA_GPU_MATMUL_MAX_CTAS`], 64) is not changed. +/// own library default ([`ffi::OMEGA_GPU_MATMUL_MAX_CTAS`], 1024) is not changed. pub const CTA_BUDGET_ENV: &str = "AIEN_OMEGA_CTA_BUDGET"; /// Largest budget [`parse_cta_budget`] accepts. Budgets chip-tested on the GB10: @@ -1304,7 +1304,7 @@ mod cta_budget_tests { #[test] fn default_budget_is_omega_max_ctas() { - assert_eq!(ffi::OMEGA_GPU_MATMUL_MAX_CTAS, 64); + assert_eq!(ffi::OMEGA_GPU_MATMUL_MAX_CTAS, 1024); // Reading the budget never opens the device (omega_gpu_matmul_api.c:121). if is_native() { assert_eq!(cta_budget(), Some(ffi::OMEGA_GPU_MATMUL_MAX_CTAS)); @@ -1325,7 +1325,7 @@ mod cta_budget_tests { Ok(Some(DAEMON_DEFAULT_CTA_BUDGET)) ); // Omega's own library default is untouched by the AIEN default. - assert_eq!(ffi::OMEGA_GPU_MATMUL_MAX_CTAS, 64); + assert_eq!(ffi::OMEGA_GPU_MATMUL_MAX_CTAS, 1024); assert!(DAEMON_DEFAULT_CTA_BUDGET_EVIDENCE.starts_with("docs/inference/evidence/")); let doc = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) .join("../..") diff --git a/native-artifacts.lock b/native-artifacts.lock index b2d9515b..6536feca 100644 --- a/native-artifacts.lock +++ b/native-artifacts.lock @@ -31,3 +31,4 @@ libomega_gpu.a 62833658f5c291f0d229b45d2c18500145cbab66 aarch64-unknown-linux-gn librx_compose.a 4799f9eba563e9c69579b47c477e7d9c2b0f15cb aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a 4799f9eba563e9c69579b47c477e7d9c2b0f15cb aarch64-unknown-linux-gnu 0629ad9cec0addd4ccc461f0523c2c3964964f0bafc0b98b678e5080b0373ae5 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a d14b568f88f5ab2637382f6ce32761fbdad7aeee aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +libomega_gpu.a d822df84a16c13f6aec647a18d2dca61a2280915 aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 diff --git a/omega.lock b/omega.lock index 20996a1b..f1147bd8 100644 --- a/omega.lock +++ b/omega.lock @@ -1 +1 @@ -d14b568f88f5ab2637382f6ce32761fbdad7aeee +d822df84a16c13f6aec647a18d2dca61a2280915 From a69c22e3a4e39bbe4fbdc16e6d71c97539209172 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 22 Oct 2026 10:48:49 -0500 Subject: [PATCH 3/9] Record actual pinned compose archive for required-native serving --- native-artifacts.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/native-artifacts.lock b/native-artifacts.lock index 6536feca..291f4d69 100644 --- a/native-artifacts.lock +++ b/native-artifacts.lock @@ -32,3 +32,4 @@ librx_compose.a 4799f9eba563e9c69579b47c477e7d9c2b0f15cb aarch64-unknown-linux-g libomega_gpu.a 4799f9eba563e9c69579b47c477e7d9c2b0f15cb aarch64-unknown-linux-gnu 0629ad9cec0addd4ccc461f0523c2c3964964f0bafc0b98b678e5080b0373ae5 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a d14b568f88f5ab2637382f6ce32761fbdad7aeee aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a d822df84a16c13f6aec647a18d2dca61a2280915 aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +librx_compose.a d822df84a16c13f6aec647a18d2dca61a2280915 aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 From 72ee866baf3216272741a5c576fa9706707a3182 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 22 Oct 2026 10:56:18 -0500 Subject: [PATCH 4/9] Pin motor candidate with complete maximum-capacity host fixtures --- native-artifacts.lock | 2 ++ omega.lock | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/native-artifacts.lock b/native-artifacts.lock index 291f4d69..96ee3df5 100644 --- a/native-artifacts.lock +++ b/native-artifacts.lock @@ -33,3 +33,5 @@ libomega_gpu.a 4799f9eba563e9c69579b47c477e7d9c2b0f15cb aarch64-unknown-linux-gn libomega_gpu.a d14b568f88f5ab2637382f6ce32761fbdad7aeee aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a d822df84a16c13f6aec647a18d2dca61a2280915 aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 librx_compose.a d822df84a16c13f6aec647a18d2dca61a2280915 aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +libomega_gpu.a 097dcb7e8850ecf628c185fb1e94418fbb5a6216 aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +librx_compose.a 097dcb7e8850ecf628c185fb1e94418fbb5a6216 aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 diff --git a/omega.lock b/omega.lock index f1147bd8..91cbe651 100644 --- a/omega.lock +++ b/omega.lock @@ -1 +1 @@ -d822df84a16c13f6aec647a18d2dca61a2280915 +097dcb7e8850ecf628c185fb1e94418fbb5a6216 From 38cf70c85a13bf51916f890fc89dec84a4c8c8e5 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 22 Oct 2026 11:03:57 -0500 Subject: [PATCH 5/9] Pin producer-proof source binding with ignored-overlay refusals --- native-artifacts.lock | 2 ++ omega.lock | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/native-artifacts.lock b/native-artifacts.lock index 96ee3df5..9f673215 100644 --- a/native-artifacts.lock +++ b/native-artifacts.lock @@ -35,3 +35,5 @@ libomega_gpu.a d822df84a16c13f6aec647a18d2dca61a2280915 aarch64-unknown-linux-gn librx_compose.a d822df84a16c13f6aec647a18d2dca61a2280915 aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a 097dcb7e8850ecf628c185fb1e94418fbb5a6216 aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 librx_compose.a 097dcb7e8850ecf628c185fb1e94418fbb5a6216 aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +libomega_gpu.a 7052d780ad9de52285e1c620e3eefd00ec5dc8db aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +librx_compose.a 7052d780ad9de52285e1c620e3eefd00ec5dc8db aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 diff --git a/omega.lock b/omega.lock index 91cbe651..5e4c37f6 100644 --- a/omega.lock +++ b/omega.lock @@ -1 +1 @@ -097dcb7e8850ecf628c185fb1e94418fbb5a6216 +7052d780ad9de52285e1c620e3eefd00ec5dc8db From aaab111c93168702da7db22e98555bb656c9bb28 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 22 Oct 2026 11:25:03 -0500 Subject: [PATCH 6/9] Record canonical motor archives for platform ABI 1.3 --- native-artifacts.lock | 2 ++ omega.lock | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/native-artifacts.lock b/native-artifacts.lock index 9f673215..0afe3927 100644 --- a/native-artifacts.lock +++ b/native-artifacts.lock @@ -37,3 +37,5 @@ libomega_gpu.a 097dcb7e8850ecf628c185fb1e94418fbb5a6216 aarch64-unknown-linux-gn librx_compose.a 097dcb7e8850ecf628c185fb1e94418fbb5a6216 aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a 7052d780ad9de52285e1c620e3eefd00ec5dc8db aarch64-unknown-linux-gnu 4ea52209c29034ddd6be3b220a3a648eea65b73519565eaac846308331f37187 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 librx_compose.a 7052d780ad9de52285e1c620e3eefd00ec5dc8db aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +libomega_gpu.a 1ad2dc1af70f01680fd93cb41a7a94fd0951723f aarch64-unknown-linux-gnu 63c500cec9784cf9ed6d751062f0dfcd27313e80e29b316e16f6bfc6ffc11c01 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +librx_compose.a 1ad2dc1af70f01680fd93cb41a7a94fd0951723f aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 diff --git a/omega.lock b/omega.lock index 5e4c37f6..bae373cf 100644 --- a/omega.lock +++ b/omega.lock @@ -1 +1 @@ -7052d780ad9de52285e1c620e3eefd00ec5dc8db +1ad2dc1af70f01680fd93cb41a7a94fd0951723f From fc184dacb02a92b38b5a9e2502bfbff61634a1e4 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 28 Oct 2026 14:54:11 -0500 Subject: [PATCH 7/9] fix(native): admit canonical CUDApp and independent CPU companion Recover the existing 35B caller without production activation. Authenticate source-checker bytes before execution, bind independent archive identities, derive optional APIs from the admitted canonical archive, and version bounded persistent-cache identities. Host qualification and refusal controls only. The combined reliability candidate remains pending CUDApp #174; no GPU, full-model or driver-replacement qualification is claimed. Refs #797. --- .crumb | 18 +- Cargo.lock | 8 + crates/aien-abi-conformance/src/build.rs | 80 ++++- crates/aien-abi-conformance/src/features.rs | 120 +++++++ crates/aien-abi-conformance/src/identity.rs | 44 ++- crates/aien-abi-conformance/src/lib.rs | 5 +- crates/aien-abi-conformance/src/native.rs | 4 +- crates/aien-abi-conformance/src/source.rs | 144 ++++++++ .../aien-inference-abi/src/omega_backend.rs | 2 +- .../aien-inference-abi/src/qwen3_moe_omega.rs | 4 +- .../tests/omega_backend_parity.rs | 25 ++ crates/aien-omega-bf16/Cargo.toml | 3 + crates/aien-omega-bf16/build.rs | 57 +--- crates/aien-omega-dattn/Cargo.toml | 3 + crates/aien-omega-dattn/build.rs | 57 +--- crates/aien-omega-dgraph/Cargo.toml | 3 + crates/aien-omega-dgraph/build.rs | 57 +--- crates/aien-omega-fp8/Cargo.toml | 3 + crates/aien-omega-fp8/build.rs | 86 ++--- crates/aien-omega-gpu/Cargo.toml | 3 +- crates/aien-omega-gpu/abi/omega_gpu.manifest | 8 +- crates/aien-omega-gpu/build.rs | 261 ++++++++------- crates/aien-omega-gpu/src/lib.rs | 103 +++++- crates/aien-omega-gpu/tests/abi_manifest.rs | 26 +- crates/aien-omega-moe/Cargo.toml | 3 + crates/aien-omega-moe/build.rs | 57 +--- crates/aien-omega-pf/Cargo.toml | 3 + crates/aien-omega-pf/build.rs | 119 ++----- crates/aien-omega-q38/Cargo.toml | 3 + crates/aien-omega-q38/build.rs | 85 ++--- crates/aien-omega-router/Cargo.toml | 3 + crates/aien-omega-router/build.rs | 57 +--- crates/aien-serve-http/build.rs | 32 -- crates/aien-serve-http/src/kv_persist.rs | 268 ++++++++++++--- crates/aien-serve-http/tests/kv_persist.rs | 77 ++++- docs/abi-qualification/INVENTORY.md | 42 ++- docs/release/BUILD_RECIPE.md | 71 +++- native-artifacts.lock | 13 +- omega.lock | 2 +- scripts/.crumb | 8 +- scripts/abi-qualify.sh | 51 ++- scripts/pins.sh | 54 ++- scripts/test-native-identity.sh | 310 +++++++++++++++++- scripts/test-pins.sh | 28 +- 44 files changed, 1655 insertions(+), 755 deletions(-) create mode 100644 crates/aien-abi-conformance/src/features.rs create mode 100644 crates/aien-abi-conformance/src/source.rs diff --git a/.crumb b/.crumb index 06e2456a..40708fe7 100644 --- a/.crumb +++ b/.crumb @@ -100,7 +100,7 @@ "purpose": "" }, { - "digest": "34b010337138a65931ca4d0177631d839f71af021c5092583f52afd69ddd1b72", + "digest": "b811ed841b3b36b0be3661290b8adfc1f5ea65710d6dd19d5ce2d0885af9cfcc", "last_commit": "fe3677c3", "name": "scripts", "purpose": "" @@ -118,15 +118,15 @@ "purpose": "Local CI sandbox exec contract (C8), aien-run user/caches install, Forgejo trigger hook, health " } ], - "children_root": "sha256:111edf8bf001ed434f7dacbc6d8ab9d75f6bda2cd909d01264fb42bbe38b1d74", - "compiled_at": "2026-10-18T11:53:56Z", + "children_root": "sha256:1531c58a660546b73170011d2c04ac2ec5cc48fdea193b4441d0a7c57aaf9753", + "compiled_at": "2026-10-28T19:53:33Z", "compiler": "crumb-compile/1", - "digest": "sha256:f2c43526655461c518b369419e899475bd348b12947b7dffcfb935c7276f4f9e", - "evidence_files": 1591, - "evidence_root": "sha256:15d7ced7ccf38ebdb4644dd791cc78ab7fac998827057ea56abbc7abfe6b2df0", - "files": 5906, - "generated_at_commit": "42e0bb7046790d01d37f78889d3d507c20c77011", - "source_tree": "sha256:24d5905c5f217ccdaab1830fdaeb27388d7445361b26fee6ecb7e83cd7b83593" + "digest": "sha256:1d5bef350231604182802ab54850f0f2d4853802513d53f165ac6380e23b76df", + "evidence_files": 3409, + "evidence_root": "sha256:09391c156f119df3838e28645c7303b5e7f3dc09d528b9866426aa5c9fc77b93", + "files": 7761, + "generated_at_commit": "aaab111c93168702da7db22e98555bb656c9bb28", + "source_tree": "sha256:4021b67e745f3ac020c6b2aa61bc7fdb7c42d9263f53bd29b3d0645e77422abf" } }, "history": [], diff --git a/Cargo.lock b/Cargo.lock index 83da9125..3bf958f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -294,6 +294,7 @@ dependencies = [ name = "aien-omega-bf16" version = "0.1.0" dependencies = [ + "aien-abi-conformance", "aien-omega-gpu", ] @@ -310,6 +311,7 @@ dependencies = [ name = "aien-omega-dattn" version = "0.1.0" dependencies = [ + "aien-abi-conformance", "aien-omega-gpu", ] @@ -317,6 +319,7 @@ dependencies = [ name = "aien-omega-dgraph" version = "0.1.0" dependencies = [ + "aien-abi-conformance", "aien-omega-gpu", ] @@ -324,6 +327,7 @@ dependencies = [ name = "aien-omega-fp8" version = "0.1.0" dependencies = [ + "aien-abi-conformance", "aien-omega-gpu", ] @@ -338,6 +342,7 @@ dependencies = [ name = "aien-omega-moe" version = "0.1.0" dependencies = [ + "aien-abi-conformance", "aien-omega-gpu", ] @@ -345,6 +350,7 @@ dependencies = [ name = "aien-omega-pf" version = "0.1.0" dependencies = [ + "aien-abi-conformance", "aien-omega-dattn", "aien-omega-gpu", ] @@ -353,6 +359,7 @@ dependencies = [ name = "aien-omega-q38" version = "0.1.0" dependencies = [ + "aien-abi-conformance", "aien-omega-gpu", ] @@ -360,6 +367,7 @@ dependencies = [ name = "aien-omega-router" version = "0.1.0" dependencies = [ + "aien-abi-conformance", "aien-omega-gpu", ] diff --git a/crates/aien-abi-conformance/src/build.rs b/crates/aien-abi-conformance/src/build.rs index cd2ecb24..cc8f1f1e 100644 --- a/crates/aien-abi-conformance/src/build.rs +++ b/crates/aien-abi-conformance/src/build.rs @@ -40,7 +40,7 @@ pub struct Identity { /// "locked" | "unrecorded" | "prebuilt-match" | "none" pub digest: &'static str, pub archive_sha256: String, - pub omega_sha: String, + pub source_sha: String, pub aienos_lock: String, pub physics_lock: String, pub target: String, @@ -54,7 +54,7 @@ impl Identity { abi: "none", digest: "none", archive_sha256: String::new(), - omega_sha: omega_sha.into(), + source_sha: omega_sha.into(), aienos_lock: String::new(), physics_lock: String::new(), target: env_or("TARGET", ""), @@ -69,7 +69,7 @@ impl Identity { ("ABI", self.abi.to_string()), ("DIGEST", self.digest.to_string()), ("ARCHIVE_SHA256", self.archive_sha256.clone()), - ("SOURCE_SHA", self.omega_sha.clone()), + ("SOURCE_SHA", self.source_sha.clone()), ("AIENOS_LOCK", self.aienos_lock.clone()), ("PHYSICS_LOCK", self.physics_lock.clone()), ("TARGET", self.target.clone()), @@ -159,25 +159,38 @@ pub fn qualify_built( archive: &Path, omega_sha: &str, pinned: bool, +) -> Identity { + qualify_built_with_includes( + krate, manifest, lock, omega, archive, omega_sha, pinned, + vec![omega.join("src"), omega.join("src/runtime"), physics.join("m16"), physics.join("nvrm")], + ) +} + +/// Checks one authenticated source root and the one archive that supplies its ABI. +/// Include paths must belong to that source, never an independently selected header tree. +#[allow(clippy::too_many_arguments)] +pub fn qualify_built_with_includes( + krate: &str, + manifest: &Path, + lock: &Path, + source: &Path, + archive: &Path, + source_sha: &str, + pinned: bool, + includes: Vec, ) -> Identity { let m = load_manifest(manifest); for h in &m.headers { - println!("cargo:rerun-if-changed={}", omega.join(h).display()); + println!("cargo:rerun-if-changed={}", source.join(h).display()); } let cc = env_or("CC", "cc"); let target = env_or("TARGET", ""); let host = env_or("HOST", ""); let abi = if target == host { let work = PathBuf::from(env_or("OUT_DIR", ".")).join("abi-probe"); - let includes = vec![ - omega.join("src"), - omega.join("src/runtime"), - physics.join("m16"), - physics.join("nvrm"), - ]; match check_c(&CCheck { manifest: &m, - root: omega, + root: source, includes, archive: Some(archive), work: &work, @@ -188,7 +201,7 @@ pub fn qualify_built( "pass" } Err(errs) => panic!( - "{krate}: omega {omega_sha} does not match {} ({} problem(s)); nothing was linked:\n - {}", + "{krate}: source {source_sha} does not match {} ({} problem(s)); nothing was linked:\n - {}", manifest.display(), errs.len(), errs.join("\n - ") @@ -200,6 +213,37 @@ pub fn qualify_built( println!("cargo:warning={krate}: cross build ({host} -> {target}): C ABI layout probe skipped (not qualifiable)"); "unchecked" }; + archive_identity(krate, lock, source, archive, source_sha, pinned, abi) +} + +/// The companion has no Rust-facing GPU ABI. It must not shadow a canonical function. +pub fn qualify_companion( + krate: &str, + manifest: &Path, + lock: &Path, + source: &Path, + archive: &Path, + source_sha: &str, +) -> Identity { + let m = load_manifest(manifest); + let symbols = defined_symbols(archive).unwrap_or_else(|e| panic!("{krate}: {e}")); + let shadows: Vec<_> = m.fns.iter().filter_map(|(name, _)| symbols.contains(name).then_some(name)).collect(); + assert!(shadows.is_empty(), "{krate}: companion shadows canonical GPU ABI functions: {shadows:?}"); + archive_identity(krate, lock, source, archive, source_sha, true, "none") +} + +fn archive_identity( + krate: &str, + lock: &Path, + source: &Path, + archive: &Path, + source_sha: &str, + pinned: bool, + abi: &'static str, +) -> Identity { + println!("cargo:rerun-if-changed={}", archive.display()); + let cc = env_or("CC", "cc"); + let target = env_or("TARGET", ""); let sha = identity::sha256_file(archive).unwrap_or_else(|e| panic!("{krate}: {e}")); let ccv = identity::cc_version(&cc); let name = archive @@ -209,7 +253,7 @@ pub fn qualify_built( let digest = match identity::check_built( &load_lock(lock), &name, - omega_sha, + source_sha, &target, &ccv, &sha, @@ -217,7 +261,7 @@ pub fn qualify_built( Ok(Digest::Locked) => "locked", Ok(Digest::Unrecorded) => { println!( - "cargo:warning={krate}: {name} sha256 {sha} (omega {omega_sha}, {target}, `{ccv}`) is not recorded in native-artifacts.lock: builds, but does not qualify" + "cargo:warning={krate}: {name} sha256 {sha} (source {source_sha}, {target}, `{ccv}`) is not recorded in native-artifacts.lock: builds, but does not qualify" ); "unrecorded" } @@ -232,9 +276,9 @@ pub fn qualify_built( abi, digest, archive_sha256: sha, - omega_sha: omega_sha.into(), - aienos_lock: read_trim(&omega.join("aienos.lock")), - physics_lock: read_trim(&omega.join("physics.lock")), + source_sha: source_sha.into(), + aienos_lock: read_trim(&source.join("aienos.lock")), + physics_lock: read_trim(&source.join("physics.lock")), target, cc: ccv, } @@ -276,7 +320,7 @@ pub fn qualify_prebuilt( abi: "symbols-only", digest: "prebuilt-match", archive_sha256: sha, - omega_sha: omega_sha.into(), + source_sha: omega_sha.into(), aienos_lock: String::new(), physics_lock: String::new(), target: env_or("TARGET", ""), diff --git a/crates/aien-abi-conformance/src/features.rs b/crates/aien-abi-conformance/src/features.rs new file mode 100644 index 00000000..02338ed7 --- /dev/null +++ b/crates/aien-abi-conformance/src/features.rs @@ -0,0 +1,120 @@ +//! Shared build-time helpers for optional omega crates to discover admitted canonical capabilities. +//! +//! All optional crates derive their native symbols and configuration flags from the admitted +//! canonical archive exported by `aien-omega-gpu` via Cargo DEP metadata. +//! No obsolete raw headers or prebuilt library paths (`AIEN_OMEGA_GPU_LIB`) are used. + +use std::collections::BTreeSet; +use std::path::{Path, PathBuf}; + +use crate::build; +use crate::identity; +use crate::probe; + +/// Admitted canonical archive metadata and defined global symbols. +#[derive(Debug, Clone)] +pub struct CanonicalFeatures { + archive: PathBuf, + sha256: String, + symbols: BTreeSet, +} + +impl CanonicalFeatures { + /// Inspect the admitted canonical archive exported by `aien-omega-gpu` via Cargo DEP metadata. + /// + /// Fails closed (panics) on malformed metadata, hash mismatch, or inspection failure. + /// Returns `None` only when `aien-omega-gpu` built as a stub and native is not required. + pub fn from_dep(krate: &str) -> Option { + println!("cargo:rerun-if-env-changed=AIEN_FORCE_CPU_STUB"); + println!("cargo:rerun-if-env-changed=AIEN_REQUIRE_NATIVE_LIBS"); + println!("cargo:rerun-if-env-changed=AIEN_OMEGA_GPU_LIB"); + println!("cargo:rerun-if-env-changed=DEP_AIEN_OMEGA_GPU_CANONICAL_ARCHIVE"); + println!("cargo:rerun-if-env-changed=DEP_AIEN_OMEGA_GPU_CANONICAL_SHA256"); + + assert!( + std::env::var_os("AIEN_OMEGA_GPU_LIB").is_none(), + "{krate}: AIEN_OMEGA_GPU_LIB is obsolete; canonical capability decisions derive only from admitted dependency metadata" + ); + + if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { + build::refuse_stub_if_required(krate); + return None; + } + + let archive_str = match std::env::var("DEP_AIEN_OMEGA_GPU_CANONICAL_ARCHIVE") { + Ok(s) if !s.trim().is_empty() => s, + _ => { + if build::require_native() { + panic!( + "{krate}: AIEN_REQUIRE_NATIVE_LIBS=1 refuses the stub build (canonical archive metadata not provided by aien-omega-gpu)" + ); + } + return None; + } + }; + + let sha256_expected = match std::env::var("DEP_AIEN_OMEGA_GPU_CANONICAL_SHA256") { + Ok(s) if identity::is_sha256(&s) => s, + _ => { + panic!( + "{krate}: malformed or missing DEP_AIEN_OMEGA_GPU_CANONICAL_SHA256 metadata for canonical archive {archive_str}" + ); + } + }; + + let archive = PathBuf::from(archive_str); + if !archive.is_file() { + panic!( + "{krate}: canonical archive metadata points to non-existent file: {}", + archive.display() + ); + } + + println!("cargo:rerun-if-changed={}", archive.display()); + + let actual_hash = identity::sha256_file(&archive).unwrap_or_else(|e| { + panic!( + "{krate}: cannot hash canonical archive {}: {e}", + archive.display() + ); + }); + + if actual_hash != sha256_expected { + panic!( + "{krate}: canonical archive digest mismatch for {}: metadata expected {sha256_expected}, got {actual_hash}", + archive.display() + ); + } + + let sym_vec = probe::defined_symbols(&archive).unwrap_or_else(|e| { + panic!( + "{krate}: cannot inspect defined symbols in canonical archive {}: {e}", + archive.display() + ); + }); + + let symbols = sym_vec.into_iter().collect(); + + Some(Self { + archive, + sha256: actual_hash, + symbols, + }) + } + + pub fn archive(&self) -> &Path { + &self.archive + } + + pub fn sha256(&self) -> &str { + &self.sha256 + } + + pub fn has_symbol(&self, name: &str) -> bool { + self.symbols.contains(name) + } + + pub fn has_all_symbols(&self, names: &[&str]) -> bool { + names.iter().all(|name| self.has_symbol(name)) + } +} diff --git a/crates/aien-abi-conformance/src/identity.rs b/crates/aien-abi-conformance/src/identity.rs index 7216c8d6..ad6dd858 100644 --- a/crates/aien-abi-conformance/src/identity.rs +++ b/crates/aien-abi-conformance/src/identity.rs @@ -1,10 +1,10 @@ //! Native archive identity (used from `build.rs`). //! //! `native-artifacts.lock` (repository root) records the expected sha256 of each archive built -//! from the pinned omega source, per target triple and C compiler, one line each: +//! from its pinned component source, per target triple and C compiler, one line each: //! //! ```text -//! +//! //! ``` //! //! omega's archives are byte-reproducible for a given source, compiler and target (the build @@ -59,7 +59,7 @@ pub fn cc_version(cc: &str) -> String { #[derive(Debug, Clone, PartialEq, Eq)] pub struct LockEntry { pub archive: String, - pub omega: String, + pub source_sha: String, pub target: String, pub sha256: String, pub cc: String, @@ -75,13 +75,13 @@ pub fn parse_lock(text: &str) -> Result, String> { let w: Vec<&str> = line.splitn(5, ' ').collect(); if w.len() != 5 || !is_sha256(w[3]) || w[1].len() != 40 { return Err(format!( - "native-artifacts.lock line {}: want ` `: {raw}", + "native-artifacts.lock line {}: want ` `: {raw}", i + 1 )); } v.push(LockEntry { archive: w[0].into(), - omega: w[1].into(), + source_sha: w[1].into(), target: w[2].into(), sha256: w[3].into(), cc: w[4].trim().into(), @@ -90,16 +90,16 @@ pub fn parse_lock(text: &str) -> Result, String> { Ok(v) } -/// The recorded digest for this archive, omega commit, target and compiler, if any. +/// The recorded digest for this archive, source commit, target and compiler, if any. pub fn expected<'a>( lock: &'a [LockEntry], archive: &str, - omega: &str, + source_sha: &str, target: &str, cc: &str, ) -> Option<&'a LockEntry> { lock.iter() - .find(|e| e.archive == archive && e.omega == omega && e.target == target && e.cc == cc) + .find(|e| e.archive == archive && e.source_sha == source_sha && e.target == target && e.cc == cc) } /// Outcome of the digest check for an archive built from source. @@ -107,7 +107,7 @@ pub fn expected<'a>( pub enum Digest { /// matches its `native-artifacts.lock` entry Locked, - /// no entry for this (archive, omega, target, compiler) + /// no entry for this (archive, source commit, target, compiler) Unrecorded, } @@ -115,15 +115,15 @@ pub enum Digest { pub fn check_built( lock: &[LockEntry], archive: &str, - omega: &str, + source_sha: &str, target: &str, cc: &str, actual: &str, ) -> Result { - match expected(lock, archive, omega, target, cc) { + match expected(lock, archive, source_sha, target, cc) { Some(e) if e.sha256 == actual => Ok(Digest::Locked), Some(e) => Err(format!( - "{archive} built from omega {omega} for {target} with `{cc}` has sha256 {actual}, native-artifacts.lock expects {}", + "{archive} built from source {source_sha} for {target} with `{cc}` has sha256 {actual}, native-artifacts.lock expects {}", e.sha256 )), None => Ok(Digest::Unrecorded), @@ -178,6 +178,26 @@ mod tests { assert!(parse_lock("libx.a short aarch64 abc cc\n").is_err()); } + #[test] + fn canonical_and_companion_records_are_independent_source_keys() { + let cudapp = "1111111111111111111111111111111111111111"; + let omega = "2222222222222222222222222222222222222222"; + let companion_digest = A.replace('a', "b"); + let target = "aarch64-unknown-linux-gnu"; + let cc = "cc fixture"; + let lock = parse_lock(&format!( + "libcudapp.a {cudapp} {target} {A} {cc}\nlibomega_gpu.a {omega} {target} {companion_digest} {cc}\n" + )).unwrap(); + assert_eq!(check_built(&lock, "libcudapp.a", cudapp, target, cc, A), Ok(Digest::Locked)); + assert_eq!(check_built(&lock, "libomega_gpu.a", omega, target, cc, &companion_digest), Ok(Digest::Locked)); + assert_eq!(check_built(&lock, "libcudapp.a", omega, target, cc, A), Ok(Digest::Unrecorded)); + assert_eq!(check_built(&lock, "libomega_gpu.a", cudapp, target, cc, &companion_digest), Ok(Digest::Unrecorded)); + assert_eq!(check_built(&lock, "libcudapp.a", cudapp, "other-target", cc, A), Ok(Digest::Unrecorded)); + assert_eq!(check_built(&lock, "libcudapp.a", cudapp, target, "other compiler", A), Ok(Digest::Unrecorded)); + assert!(check_built(&lock, "libcudapp.a", cudapp, target, cc, &companion_digest).is_err()); + assert!(check_built(&lock, "libomega_gpu.a", omega, target, cc, A).is_err()); + } + #[test] fn prebuilt_needs_and_checks_a_digest() { let dir = std::env::temp_dir().join(format!("abi-id-{}", std::process::id())); diff --git a/crates/aien-abi-conformance/src/lib.rs b/crates/aien-abi-conformance/src/lib.rs index 5baa969f..a65eb387 100644 --- a/crates/aien-abi-conformance/src/lib.rs +++ b/crates/aien-abi-conformance/src/lib.rs @@ -21,14 +21,17 @@ //! No dependencies; the C side needs `cc` and `nm` (both already required by the native build). pub mod build; +pub mod features; pub mod header; pub mod identity; pub mod manifest; mod native; pub mod probe; mod rust; +pub mod source; pub use manifest::{canon_sig, canon_type, Manifest}; +pub use features::CanonicalFeatures; pub use native::NativeIdentity; -pub use probe::{check_c, CCheck}; +pub use probe::{check_c, defined_symbols, CCheck}; pub use rust::{assert_manifest, rust_manifest, AbiStruct, CKind, Field, FnSig, RustAbi}; diff --git a/crates/aien-abi-conformance/src/native.rs b/crates/aien-abi-conformance/src/native.rs index 06322426..532b2a35 100644 --- a/crates/aien-abi-conformance/src/native.rs +++ b/crates/aien-abi-conformance/src/native.rs @@ -19,7 +19,7 @@ pub struct NativeIdentity { } impl NativeIdentity { - /// Release-grade: built from the pinned omega source, C ABI checked, digest recorded + /// Release-grade: built from its pinned source, C ABI checked, digest recorded /// and matched. A stub, a developer override or a prebuilt archive never qualifies. pub fn qualifies(&self) -> bool { self.link == "pinned-source" && self.abi == "pass" && self.digest == "locked" @@ -29,7 +29,7 @@ impl NativeIdentity { pub fn gaps(&self) -> Vec<&'static str> { let mut v = Vec::new(); if self.link != "pinned-source" { - v.push("not built from the pinned omega source"); + v.push("not built from the pinned component source"); } if self.abi != "pass" { v.push("C ABI not checked against the manifest"); diff --git a/crates/aien-abi-conformance/src/source.rs b/crates/aien-abi-conformance/src/source.rs new file mode 100644 index 00000000..dcd6ab1d --- /dev/null +++ b/crates/aien-abi-conformance/src/source.rs @@ -0,0 +1,144 @@ +//! Authenticate the bootstrap script before allowing it to check the rest of a source tree. +//! Git is a read-only hashing oracle here: object contents are not trusted merely because +//! cat-file found them under a requested object name. Never execute a working-tree checker. +use std::io::Write; +use std::path::Path; +use std::process::{Command, Stdio}; + +fn git(repo: &Path) -> Command { + let mut command = Command::new("git"); + command.arg("-C").arg(repo) + .env("GIT_NO_REPLACE_OBJECTS", "1") + .env("GIT_GRAFT_FILE", "/nonexistent/core-native-grafts"); + command +} + +fn object(repo: &Path, kind: &str, expected: &str) -> Vec { + let result = git(repo).args(["cat-file", kind, expected]).output() + .expect("read bootstrap Git object"); + assert!(result.status.success(), "bootstrap object authentication: cannot read {kind} {expected}"); + let mut hash = git(repo).args(["hash-object", "-t", kind, "--stdin"]) + .stdin(Stdio::piped()).stdout(Stdio::piped()).spawn() + .expect("start read-only Git object hash"); + hash.stdin.take().unwrap().write_all(&result.stdout).expect("hash bootstrap object bytes"); + let actual = hash.wait_with_output().expect("finish bootstrap Git object hash"); + assert!(actual.status.success(), "bootstrap object authentication: cannot hash {kind} {expected}"); + assert_eq!(String::from_utf8(actual.stdout).expect("ASCII Git object ID").trim(), expected, + "bootstrap object authentication failed for {kind} {expected}"); + result.stdout +} + +fn entry(tree: &[u8], name: &[u8], modes: &[&[u8]]) -> String { + let mut rest = tree; + while !rest.is_empty() { + let nul = rest.iter().position(|&b| b == 0).expect("bootstrap tree has no entry terminator"); + let header = &rest[..nul]; + let space = header.iter().position(|&b| b == b' ').expect("bootstrap tree has no entry mode"); + let id_end = nul.checked_add(21).expect("bootstrap tree entry overflow"); + assert!(rest.len() >= id_end, "bootstrap tree has a truncated object ID"); + if &header[space + 1..] == name { + assert!(modes.contains(&&header[..space]), "bootstrap object authentication: unexpected entry mode"); + let mut id = String::with_capacity(40); + use std::fmt::Write as _; + for byte in &rest[nul + 1..id_end] { + write!(&mut id, "{byte:02x}").expect("write Git object ID"); + } + return id; + } + rest = &rest[id_end..]; + } + panic!("bootstrap object authentication: required checker path is absent"); +} + +/// Return only checker bytes authenticated through commit -> root -> tools -> regular blob. +/// The caller executes a private snapshot and clears BASH_ENV before invoking Bash. +pub fn authenticated_source_checker(repo: &Path, pinned: &str) -> Vec { + let commit = object(repo, "commit", pinned); + let first = commit.split(|&b| b == b'\n').next().expect("bootstrap commit is empty"); + let root_id = std::str::from_utf8(first.strip_prefix(b"tree ").expect("bootstrap commit has no root tree")) + .expect("ASCII bootstrap root tree ID"); + let root = object(repo, "tree", root_id); + let tools_id = entry(&root, b"tools", &[b"40000"]); + let tools = object(repo, "tree", &tools_id); + let checker_id = entry(&tools, b"aienos_lock_source.sh", &[b"100644", b"100755"]); + object(repo, "blob", &checker_id) +} + +#[cfg(test)] +mod tests { + use super::*; + use std::sync::atomic::{AtomicUsize, Ordering}; + static NEXT: AtomicUsize = AtomicUsize::new(0); + + struct Fixture(std::path::PathBuf); + impl Drop for Fixture { + fn drop(&mut self) { let _ = std::fs::remove_dir_all(&self.0); } + } + impl Fixture { + fn new() -> Self { + let dir = std::env::temp_dir().join(format!("core-bootstrap-{}-{}", std::process::id(), NEXT.fetch_add(1, Ordering::Relaxed))); + std::fs::create_dir_all(dir.join("tools")).unwrap(); + let fixture = Self(dir); + fixture.run(&["init", "-q"]); + fixture.run(&["config", "user.name", "Bootstrap fixture"]); + fixture.run(&["config", "user.email", "fixture@example.invalid"]); + fixture.run(&["config", "commit.gpgsign", "false"]); + fixture.run(&["config", "core.hooksPath", "/dev/null"]); + std::fs::write(fixture.0.join("tools/aienos_lock_source.sh"), b"printf pristine > \"$1\"\n").unwrap(); + fixture.run(&["add", "tools/aienos_lock_source.sh"]); + fixture.run(&["commit", "-qm", "bootstrap fixture"]); + fixture + } + fn run(&self, args: &[&str]) -> String { + let output = git(&self.0).args(args).output().unwrap(); + assert!(output.status.success(), "fixture Git failed: {args:?}"); + String::from_utf8(output.stdout).unwrap().trim().to_owned() + } + fn poison_object(&self, kind: &str, expected: &str) { + let mut child = git(&self.0).args(["hash-object", "--literally", "-w", "-t", kind, "--stdin"]) + .stdin(Stdio::piped()).stdout(Stdio::piped()).spawn().unwrap(); + child.stdin.take().unwrap().write_all(b"printf poisoned > \"$1\"\n").unwrap(); + let result = child.wait_with_output().unwrap(); + assert!(result.status.success()); + let rogue = String::from_utf8(result.stdout).unwrap(); + let rogue = rogue.trim(); + let objects = self.0.join(".git/objects"); + let destination = objects.join(&expected[..2]).join(&expected[2..]); + std::fs::remove_file(&destination).unwrap(); + std::fs::copy(objects.join(&rogue[..2]).join(&rogue[2..]), destination).unwrap(); + std::fs::write(self.0.join("tools/aienos_lock_source.sh"), b"printf poisoned > \"$1\"\n").unwrap(); + } + fn execute_snapshot(&self, bytes: &[u8]) { + let snapshot = self.0.join("verified-checker.sh"); + std::fs::write(&snapshot, bytes).unwrap(); + assert!(Command::new("bash").arg(snapshot).arg(self.0.join("marker")) + .env_remove("BASH_ENV").status().unwrap().success()); + } + } + + #[test] + fn pristine_chain_uses_verified_snapshot_not_dirty_working_checker() { + let fixture = Fixture::new(); + let pin = fixture.run(&["rev-parse", "HEAD"]); + std::fs::write(fixture.0.join("tools/aienos_lock_source.sh"), b"printf poisoned > \"$1\"\n").unwrap(); + fixture.execute_snapshot(&authenticated_source_checker(&fixture.0, &pin)); + assert_eq!(std::fs::read(fixture.0.join("marker")).unwrap(), b"pristine"); + } + + #[test] + fn every_poisoned_bootstrap_object_refuses_before_checker_execution() { + for (kind, expression) in [("commit", "HEAD"), ("tree", "HEAD^{tree}"), + ("tree", "HEAD:tools"), ("blob", "HEAD:tools/aienos_lock_source.sh")] { + let fixture = Fixture::new(); + let pin = fixture.run(&["rev-parse", "HEAD"]); + let expected = fixture.run(&["rev-parse", expression]); + fixture.poison_object(kind, &expected); + let refusal = std::panic::catch_unwind(|| { + let checker = authenticated_source_checker(&fixture.0, &pin); + fixture.execute_snapshot(&checker); + }); + assert!(refusal.is_err(), "poisoned {kind} {expression} was accepted"); + assert!(!fixture.0.join("marker").exists(), "poisoned checker executed before refusal"); + } + } +} diff --git a/crates/aien-inference-abi/src/omega_backend.rs b/crates/aien-inference-abi/src/omega_backend.rs index f6a86801..a8255304 100644 --- a/crates/aien-inference-abi/src/omega_backend.rs +++ b/crates/aien-inference-abi/src/omega_backend.rs @@ -1,5 +1,5 @@ //! `OmegaGb10Backend` (FB-1 cuts 3b, 3c, 3d): all ten `TensorBackend` ops run on our own -//! native GPU engine (`libomega_gpu.a`, no CUDA) through the `aien-omega-gpu` crate. +//! native GPU engine (canonical CUDApp, no CUDA) through the `aien-omega-gpu` crate. //! //! Native mask: `matmul_vec`, `matmul_batch`, `compute_logits`, `rmsnorm`, `rmsnorm_heads`, //! `apply_rope`, `swiglu`, `gqa_attention`, `paged_attention`, `paged_attention_batch`. diff --git a/crates/aien-inference-abi/src/qwen3_moe_omega.rs b/crates/aien-inference-abi/src/qwen3_moe_omega.rs index 8ffa23ac..a589cb67 100644 --- a/crates/aien-inference-abi/src/qwen3_moe_omega.rs +++ b/crates/aien-inference-abi/src/qwen3_moe_omega.rs @@ -844,7 +844,7 @@ impl ModelUploader for OmegaModelUploader { scales: &[u16], ) -> Result, String> { if !Self::uses_fp8_api() { - return Err("this binary carries no FP8 GEMV (omega before OWN-30B cut 5, or AIEN_OMEGA_GPU_LIB without it)".into()); + return Err("this binary carries no FP8 GEMV (omega before OWN-30B cut 5, or admitted archive without it)".into()); } let t = aien_omega_fp8::Fp8Tensor::upload(experts, n, k, w, scales) .map_err(|e| e.to_string())?; @@ -3842,7 +3842,7 @@ impl Qwen3MoeOmegaEngine { progress: &mut dyn FnMut(&str), ) -> Result<(Self, LoadReport), String> { if !aien_omega_gpu::is_native() { - return Err("this binary carries the CPU stub of the Omega engine (build with AIEN_OMEGA_DIR or AIEN_OMEGA_GPU_LIB)".into()); + return Err("this binary carries the CPU stub of the Omega engine (build with AIEN_OMEGA_DIR and AIEN_CUDAPP_DIR)".into()); } let (weights, report) = load_qwen3_moe_omega_paths(dir, &OmegaModelUploader, format, paths, progress)?; diff --git a/crates/aien-inference-abi/tests/omega_backend_parity.rs b/crates/aien-inference-abi/tests/omega_backend_parity.rs index 295313ec..297cc799 100644 --- a/crates/aien-inference-abi/tests/omega_backend_parity.rs +++ b/crates/aien-inference-abi/tests/omega_backend_parity.rs @@ -48,6 +48,31 @@ fn stub_backend_reports_unavailable() { assert_eq!(b.native_ops().native_ops().len(), 10); } +/// This only inspects admitted-archive capabilities. It never opens a device. +#[test] +fn canonical_35b_callers_are_not_silently_stubbed() { + let native = aien_omega_gpu::is_native(); + for (name, available) in [ + ("bf16", aien_omega_bf16::is_native()), + ("decode-attention", aien_omega_dattn::is_native()), + ("decode-graph", aien_omega_dgraph::is_native()), + ("fp8", aien_omega_fp8::is_native()), + ("fp8-device-tables", aien_omega_fp8::has_device_tables()), + ("fp8-grouped-gemm", aien_omega_fp8::has_gemm()), + ("moe", aien_omega_moe::is_native()), + ("prefill", aien_omega_pf::is_native()), + ("prefill-attention", aien_omega_pf::has_attention()), + ("prefill-device-attention", aien_omega_pf::has_attention_dev()), + ("prefill-host", aien_omega_pf::has_pfhost()), + ("q38", aien_omega_q38::is_native()), + ("q38-prefill", aien_omega_q38::has_prefill()), + ("q36-35b-graph", aien_omega_q38::q36::is_native()), + ("router", aien_omega_router::is_native()), + ] { + assert_eq!(available, native, "{name} differs from the canonical link"); + } +} + #[test] #[ignore = "chip test: needs a native build and the GB10; run through the heavy queue"] fn chip_parity_on_tinyllama_shapes() { diff --git a/crates/aien-omega-bf16/Cargo.toml b/crates/aien-omega-bf16/Cargo.toml index 83bf4777..4142a9dd 100644 --- a/crates/aien-omega-bf16/Cargo.toml +++ b/crates/aien-omega-bf16/Cargo.toml @@ -9,3 +9,6 @@ build = "build.rs" [dependencies] aien-omega-gpu = { path = "../aien-omega-gpu" } + +[build-dependencies] +aien-abi-conformance = { path = "../aien-abi-conformance" } diff --git a/crates/aien-omega-bf16/build.rs b/crates/aien-omega-bf16/build.rs index eeedc9aa..1f349bd1 100644 --- a/crates/aien-omega-bf16/build.rs +++ b/crates/aien-omega-bf16/build.rs @@ -1,58 +1,25 @@ //! Decides whether omega's bf16 streaming GEMV (`src/omega_gpu_bf16_gemv_api.h`, //! OWN-30B cut 8 on the omega side) is linked. //! -//! The archive itself is linked by `aien-omega-gpu`'s build script (this crate only declares -//! the extra symbols), so the decision mirrors its inputs: -//! * `AIEN_FORCE_CPU_STUB=1`: stub. -//! * `AIEN_OMEGA_GPU_LIB=`: native when `nm` finds `omega_gpu_bf16_gemv_f32` defined -//! in that archive. -//! * `AIEN_OMEGA_DIR=`: native when the checkout has `src/omega_gpu_bf16_gemv_api.h`. -//! * otherwise: stub (every call returns `Unavailable`). +//! Canonical capabilities are inspected from the admitted canonical archive exported by +//! `aien-omega-gpu` via Cargo DEP metadata. //! //! `cfg(has_omega_bf16)` is set only when native. A stub never fails the build: the engine //! keeps the dense lm_head matmul, and `is_native()` says which //! one a binary carries. -use std::path::Path; -use std::process::Command; +use aien_abi_conformance::CanonicalFeatures; fn main() { println!("cargo:rustc-check-cfg=cfg(has_omega_bf16)"); - for v in [ - "AIEN_FORCE_CPU_STUB", - "AIEN_OMEGA_GPU_LIB", - "AIEN_OMEGA_DIR", - ] { - println!("cargo:rerun-if-env-changed={v}"); - } - if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { - return; - } - if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { - println!("cargo:rerun-if-changed={lib}"); - if archive_defines(Path::new(&lib), "omega_gpu_bf16_gemv_f32") { - println!("cargo:rustc-cfg=has_omega_bf16"); - } else { - println!("cargo:warning=aien-omega-bf16: {lib} does not define the bf16 GEMV API; the bf16 lm_head GEMV is stubbed"); - } + let Some(cf) = CanonicalFeatures::from_dep("aien-omega-bf16") else { return; - } - if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { - let header = Path::new(&dir).join("src/omega_gpu_bf16_gemv_api.h"); - println!("cargo:rerun-if-changed={}", header.display()); - if header.is_file() { - println!("cargo:rustc-cfg=has_omega_bf16"); - } else { - println!("cargo:warning=aien-omega-bf16: {dir} has no src/omega_gpu_bf16_gemv_api.h (omega before OWN-30B cut 8); the bf16 lm_head GEMV is stubbed"); - } - } -} - -fn archive_defines(lib: &Path, symbol: &str) -> bool { - let Ok(out) = Command::new("nm").arg(lib).output() else { - println!("cargo:warning=aien-omega-bf16: nm not available, assuming the archive lacks the bf16 GEMV API"); - return false; }; - String::from_utf8_lossy(&out.stdout) - .lines() - .any(|l| l.ends_with(&format!(" T {symbol}"))) + if cf.has_symbol("omega_gpu_bf16_gemv_f32") { + println!("cargo:rustc-cfg=has_omega_bf16"); + } else { + println!( + "cargo:warning=aien-omega-bf16: {} does not define the bf16 GEMV API; the bf16 lm_head GEMV is stubbed", + cf.archive().display() + ); + } } diff --git a/crates/aien-omega-dattn/Cargo.toml b/crates/aien-omega-dattn/Cargo.toml index 46269f1b..aa79d5c3 100644 --- a/crates/aien-omega-dattn/Cargo.toml +++ b/crates/aien-omega-dattn/Cargo.toml @@ -9,3 +9,6 @@ build = "build.rs" [dependencies] aien-omega-gpu = { path = "../aien-omega-gpu" } + +[build-dependencies] +aien-abi-conformance = { path = "../aien-abi-conformance" } diff --git a/crates/aien-omega-dattn/build.rs b/crates/aien-omega-dattn/build.rs index c5b99c22..9e81045f 100644 --- a/crates/aien-omega-dattn/build.rs +++ b/crates/aien-omega-dattn/build.rs @@ -1,58 +1,25 @@ //! Decides whether omega's one-launch decode attention (`src/omega_gpu_decode_attn_api.h`, //! OWN-30B cut 8 on the omega side) is linked. //! -//! The archive itself is linked by `aien-omega-gpu`'s build script (this crate only declares -//! the extra symbols), so the decision mirrors its inputs: -//! * `AIEN_FORCE_CPU_STUB=1`: stub. -//! * `AIEN_OMEGA_GPU_LIB=`: native when `nm` finds `omega_gpu_decode_attn` defined -//! in that archive. -//! * `AIEN_OMEGA_DIR=`: native when the checkout has `src/omega_gpu_decode_attn_api.h`. -//! * otherwise: stub (every call returns `Unavailable`). +//! Canonical capabilities are inspected from the admitted canonical archive exported by +//! `aien-omega-gpu` via Cargo DEP metadata. //! //! `cfg(has_omega_dattn)` is set only when native. A stub never fails the build: the engine //! keeps its split attention path (host norm/rope, paged KV), and `is_native()` says which //! one a binary carries. -use std::path::Path; -use std::process::Command; +use aien_abi_conformance::CanonicalFeatures; fn main() { println!("cargo:rustc-check-cfg=cfg(has_omega_dattn)"); - for v in [ - "AIEN_FORCE_CPU_STUB", - "AIEN_OMEGA_GPU_LIB", - "AIEN_OMEGA_DIR", - ] { - println!("cargo:rerun-if-env-changed={v}"); - } - if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { - return; - } - if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { - println!("cargo:rerun-if-changed={lib}"); - if archive_defines(Path::new(&lib), "omega_gpu_decode_attn") { - println!("cargo:rustc-cfg=has_omega_dattn"); - } else { - println!("cargo:warning=aien-omega-dattn: {lib} does not define the decode attention API; fused attention is stubbed"); - } + let Some(cf) = CanonicalFeatures::from_dep("aien-omega-dattn") else { return; - } - if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { - let header = Path::new(&dir).join("src/omega_gpu_decode_attn_api.h"); - println!("cargo:rerun-if-changed={}", header.display()); - if header.is_file() { - println!("cargo:rustc-cfg=has_omega_dattn"); - } else { - println!("cargo:warning=aien-omega-dattn: {dir} has no src/omega_gpu_decode_attn_api.h (omega before OWN-30B cut 8); fused attention is stubbed"); - } - } -} - -fn archive_defines(lib: &Path, symbol: &str) -> bool { - let Ok(out) = Command::new("nm").arg(lib).output() else { - println!("cargo:warning=aien-omega-dattn: nm not available, assuming the archive lacks the decode attention API"); - return false; }; - String::from_utf8_lossy(&out.stdout) - .lines() - .any(|l| l.ends_with(&format!(" T {symbol}"))) + if cf.has_symbol("omega_gpu_decode_attn") { + println!("cargo:rustc-cfg=has_omega_dattn"); + } else { + println!( + "cargo:warning=aien-omega-dattn: {} does not define the decode attention API; fused attention is stubbed", + cf.archive().display() + ); + } } diff --git a/crates/aien-omega-dgraph/Cargo.toml b/crates/aien-omega-dgraph/Cargo.toml index f968976e..f0523dcf 100644 --- a/crates/aien-omega-dgraph/Cargo.toml +++ b/crates/aien-omega-dgraph/Cargo.toml @@ -9,3 +9,6 @@ build = "build.rs" [dependencies] aien-omega-gpu = { path = "../aien-omega-gpu" } + +[build-dependencies] +aien-abi-conformance = { path = "../aien-abi-conformance" } diff --git a/crates/aien-omega-dgraph/build.rs b/crates/aien-omega-dgraph/build.rs index af62e4ac..b6910039 100644 --- a/crates/aien-omega-dgraph/build.rs +++ b/crates/aien-omega-dgraph/build.rs @@ -1,57 +1,24 @@ //! Decides whether omega's one-list decode token (`src/omega_gpu_decode_graph.h`, OWN-30B L2 //! cut 2 on the omega side) is linked. //! -//! The archive itself is linked by `aien-omega-gpu`'s build script (this crate only declares -//! the extra symbols), so the decision mirrors its inputs: -//! * `AIEN_FORCE_CPU_STUB=1`: stub. -//! * `AIEN_OMEGA_GPU_LIB=`: native when `nm` finds `omega_gpu_decode_graph_create` -//! defined in that archive. -//! * `AIEN_OMEGA_DIR=`: native when the checkout has `src/omega_gpu_decode_graph.h`. -//! * otherwise: stub (every call returns `Unavailable`). +//! Canonical capabilities are inspected from the admitted canonical archive exported by +//! `aien-omega-gpu` via Cargo DEP metadata. //! //! `cfg(has_omega_dgraph)` is set only when native. A stub never fails the build: the engine //! keeps its launch-at-a-time decode, and `is_native()` says which one a binary carries. -use std::path::Path; -use std::process::Command; +use aien_abi_conformance::CanonicalFeatures; fn main() { println!("cargo:rustc-check-cfg=cfg(has_omega_dgraph)"); - for v in [ - "AIEN_FORCE_CPU_STUB", - "AIEN_OMEGA_GPU_LIB", - "AIEN_OMEGA_DIR", - ] { - println!("cargo:rerun-if-env-changed={v}"); - } - if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { - return; - } - if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { - println!("cargo:rerun-if-changed={lib}"); - if archive_defines(Path::new(&lib), "omega_gpu_decode_graph_create") { - println!("cargo:rustc-cfg=has_omega_dgraph"); - } else { - println!("cargo:warning=aien-omega-dgraph: {lib} does not define the decode graph API; the one-list decode is stubbed"); - } + let Some(cf) = CanonicalFeatures::from_dep("aien-omega-dgraph") else { return; - } - if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { - let header = Path::new(&dir).join("src/omega_gpu_decode_graph.h"); - println!("cargo:rerun-if-changed={}", header.display()); - if header.is_file() { - println!("cargo:rustc-cfg=has_omega_dgraph"); - } else { - println!("cargo:warning=aien-omega-dgraph: {dir} has no src/omega_gpu_decode_graph.h (omega before OWN-30B L2 cut 2); the one-list decode is stubbed"); - } - } -} - -fn archive_defines(lib: &Path, symbol: &str) -> bool { - let Ok(out) = Command::new("nm").arg(lib).output() else { - println!("cargo:warning=aien-omega-dgraph: nm not available, assuming the archive lacks the decode graph API"); - return false; }; - String::from_utf8_lossy(&out.stdout) - .lines() - .any(|l| l.ends_with(&format!(" T {symbol}"))) + if cf.has_symbol("omega_gpu_decode_graph_create") { + println!("cargo:rustc-cfg=has_omega_dgraph"); + } else { + println!( + "cargo:warning=aien-omega-dgraph: {} does not define the decode graph API; the one-list decode is stubbed", + cf.archive().display() + ); + } } diff --git a/crates/aien-omega-fp8/Cargo.toml b/crates/aien-omega-fp8/Cargo.toml index 1095431b..9a814f5b 100644 --- a/crates/aien-omega-fp8/Cargo.toml +++ b/crates/aien-omega-fp8/Cargo.toml @@ -9,3 +9,6 @@ build = "build.rs" [dependencies] aien-omega-gpu = { path = "../aien-omega-gpu" } + +[build-dependencies] +aien-abi-conformance = { path = "../aien-abi-conformance" } diff --git a/crates/aien-omega-fp8/build.rs b/crates/aien-omega-fp8/build.rs index 3fe1c955..591257a0 100644 --- a/crates/aien-omega-fp8/build.rs +++ b/crates/aien-omega-fp8/build.rs @@ -1,81 +1,35 @@ //! Decides whether omega's FP8 GEMV API (`src/omega_gpu_fp8_api.h`, OWN-30B cuts 5-6) is linked. //! -//! The archive itself is linked by `aien-omega-gpu`'s build script (this crate only declares -//! the extra symbols), so the decision mirrors its inputs: -//! * `AIEN_FORCE_CPU_STUB=1`: stub. -//! * `AIEN_OMEGA_GPU_LIB=`: native when `nm` finds -//! `omega_gpu_fp8_gemv_grouped_f32` defined in that archive. -//! * `AIEN_OMEGA_DIR=`: native when the checkout has `src/omega_gpu_fp8_api.h`. -//! -//! `cfg(has_omega_fp8gemm)` (the prefill grouped GEMM) is set when the archive defines -//! `omega_gpu_fp8gemm_f32` or the checkout has `src/omega_gpu_fp8gemm_api.h`. -//! * otherwise: stub (every call returns `Unavailable`). +//! Canonical capabilities are inspected from the admitted canonical archive exported by +//! `aien-omega-gpu` via Cargo DEP metadata. //! //! `cfg(has_omega_fp8)` is set only when native. A stub never fails the build: the bf16 //! path in the model code stays usable, and `is_native()` says which one a binary carries. -use std::path::Path; -use std::process::Command; +//! `cfg(has_omega_fp8_dev)` is set when the device-pointer entry is present. +//! `cfg(has_omega_fp8gemm)` (the prefill grouped GEMM) is set when the archive defines `omega_gpu_fp8gemm_f32`. +use aien_abi_conformance::CanonicalFeatures; fn main() { println!("cargo:rustc-check-cfg=cfg(has_omega_fp8)"); println!("cargo:rustc-check-cfg=cfg(has_omega_fp8_dev)"); println!("cargo:rustc-check-cfg=cfg(has_omega_fp8gemm)"); - for v in [ - "AIEN_FORCE_CPU_STUB", - "AIEN_OMEGA_GPU_LIB", - "AIEN_OMEGA_DIR", - ] { - println!("cargo:rerun-if-env-changed={v}"); - } - if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { + let Some(cf) = CanonicalFeatures::from_dep("aien-omega-fp8") else { return; - } - if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { - println!("cargo:rerun-if-changed={lib}"); - if archive_defines(Path::new(&lib), "omega_gpu_fp8_gemv_grouped_f32") { - println!("cargo:rustc-cfg=has_omega_fp8"); - if archive_defines(Path::new(&lib), "omega_gpu_fp8_gemv_grouped_dev") - && archive_defines(Path::new(&lib), "omega_gpu_fp8_tensor_entry") - { - println!("cargo:rustc-cfg=has_omega_fp8_dev"); - } - if archive_defines(Path::new(&lib), "omega_gpu_fp8gemm_f32") { - println!("cargo:rustc-cfg=has_omega_fp8gemm"); - } - } else { - println!("cargo:warning=aien-omega-fp8: {lib} does not define the FP8 GEMV API; FP8 calls are stubbed"); + }; + if cf.has_symbol("omega_gpu_fp8_gemv_grouped_f32") { + println!("cargo:rustc-cfg=has_omega_fp8"); + if cf.has_symbol("omega_gpu_fp8_gemv_grouped_dev") + && cf.has_symbol("omega_gpu_fp8_tensor_entry") + { + println!("cargo:rustc-cfg=has_omega_fp8_dev"); } - return; - } - if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { - let header = Path::new(&dir).join("src/omega_gpu_fp8_api.h"); - println!("cargo:rerun-if-changed={}", header.display()); - if header.is_file() { - println!("cargo:rustc-cfg=has_omega_fp8"); - if std::fs::read_to_string(&header).is_ok_and(|t| { - t.contains("omega_gpu_fp8_gemv_grouped_dev") - && t.contains("omega_gpu_fp8_tensor_entry") - }) { - println!("cargo:rustc-cfg=has_omega_fp8_dev"); - } - if Path::new(&dir) - .join("src/omega_gpu_fp8gemm_api.h") - .is_file() - { - println!("cargo:rustc-cfg=has_omega_fp8gemm"); - } - } else { - println!("cargo:warning=aien-omega-fp8: {dir} has no src/omega_gpu_fp8_api.h (omega before OWN-30B cut 5); FP8 calls are stubbed"); + if cf.has_symbol("omega_gpu_fp8gemm_f32") { + println!("cargo:rustc-cfg=has_omega_fp8gemm"); } + } else { + println!( + "cargo:warning=aien-omega-fp8: {} does not define the FP8 GEMV API; FP8 calls are stubbed", + cf.archive().display() + ); } } - -fn archive_defines(lib: &Path, symbol: &str) -> bool { - let Ok(out) = Command::new("nm").arg(lib).output() else { - println!("cargo:warning=aien-omega-fp8: nm not available, assuming the archive lacks the FP8 GEMV API"); - return false; - }; - String::from_utf8_lossy(&out.stdout) - .lines() - .any(|l| l.ends_with(&format!(" T {symbol}"))) -} diff --git a/crates/aien-omega-gpu/Cargo.toml b/crates/aien-omega-gpu/Cargo.toml index 3437059d..350be253 100644 --- a/crates/aien-omega-gpu/Cargo.toml +++ b/crates/aien-omega-gpu/Cargo.toml @@ -3,9 +3,10 @@ name = "aien-omega-gpu" version = "0.1.0" edition = "2021" authors = ["Drake Stapleton "] -description = "FFI to the native (no CUDA) Omega GPU matmul engine, pinned by omega.lock" +description = "Rust ABI to canonical CUDApp, authenticated through the pinned Omega consumer" license.workspace = true build = "build.rs" +links = "aien_omega_gpu" [dependencies] aien-abi-conformance = { path = "../aien-abi-conformance" } diff --git a/crates/aien-omega-gpu/abi/omega_gpu.manifest b/crates/aien-omega-gpu/abi/omega_gpu.manifest index 06a41cb3..1d1c3a96 100644 --- a/crates/aien-omega-gpu/abi/omega_gpu.manifest +++ b/crates/aien-omega-gpu/abi/omega_gpu.manifest @@ -1,9 +1,9 @@ -# The omega GPU engine C ABI (libomega_gpu.a) that aien-omega-gpu mirrors in src/ffi.rs. -# Checked from both sides: tests/abi_manifest.rs (Rust declarations, every build) and build.rs -# (pinned C headers, compiled layout probe, archive symbols). +# Canonical CUDApp GPU C ABI (libcudapp.a) mirrored by aien-omega-gpu src/ffi.rs. +# Checked from both sides: Rust declarations and authenticated canonical CUDApp headers, +# compiled layout/prototype/constant probes and this archive's symbols alone. # Format: aien-abi-conformance src/manifest.rs. Regenerate the fact lines from Rust with # AIEN_ABI_BLESS=1 cargo test -p aien-omega-gpu --test abi_manifest -# only together with the omega.lock change that makes the C side agree. +# only with the authenticated Omega cudapp.lock source change that makes the C side agree. abi omega_gpu 1 header src/omega_gpu_matmul_api.h header src/omega_gpu_session.h diff --git a/crates/aien-omega-gpu/build.rs b/crates/aien-omega-gpu/build.rs index 08eff4f8..bbfaf2c0 100644 --- a/crates/aien-omega-gpu/build.rs +++ b/crates/aien-omega-gpu/build.rs @@ -1,151 +1,168 @@ -//! 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). 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. -//! Refused when `AIEN_REQUIRE_NATIVE_LIBS=1` (a required-native build is never a stub). -//! 2. `AIEN_OMEGA_GPU_LIB=` -> link that prebuilt archive; `AIEN_OMEGA_GPU_LIB_SHA256` must -//! name its sha256 (checked) and it must define every function in the ABI manifest. A -//! development override: its identity says `prebuilt` and it never qualifies. -//! 3. `AIEN_OMEGA_DIR=` -> its HEAD must equal omega.lock; built with -//! `make libomega_gpu` into OUT_DIR. `AIEN_PHYSICS_DIR` (default `/../physics`) -//! is passed as PHYSICS_DIR; omega's own physics.lock check still runs. -//! 4. otherwise -> stub, with a build warning. -//! -//! `cfg(has_omega_gpu)` is set only when the real library is linked. -//! -//! Before linking a checkout build, `aien_abi_conformance::build::qualify_built` checks the -//! pinned headers, a compiled layout probe and the archive symbols against -//! `abi/omega_gpu.manifest`, and the archive sha256 against `native-artifacts.lock`; any mismatch -//! fails the build. The result is recorded for `native_identity()`. +//! Links the authenticated Omega CPU/evidence companion first and canonical CUDApp last. +//! The Rust GPU ABI is checked only against the pinned CUDApp source and archive. +//! Both digests remain independently subject to native-artifacts.lock; unrecorded +//! development builds do not qualify. No GPU or model is opened by this build script. use aien_abi_conformance::build; +use std::collections::BTreeSet; use std::path::{Path, PathBuf}; use std::process::Command; const PREFIX: &str = "AIEN_OMEGA_GPU"; +const COMPANION: &str = "AIEN_OMEGA_COMPANION"; fn main() { println!("cargo:rustc-check-cfg=cfg(has_omega_gpu)"); - for v in [ - "AIEN_FORCE_CPU_STUB", - "AIEN_OMEGA_GPU_LIB", - "AIEN_OMEGA_DIR", - "AIEN_PHYSICS_DIR", - "AIEN_REQUIRE_NATIVE_LIBS", - ] { + for v in ["AIEN_FORCE_CPU_STUB", "AIEN_OMEGA_GPU_LIB", "AIEN_OMEGA_GPU_LIB_SHA256", + "AIEN_OMEGA_DIR", "AIEN_CUDAPP_DIR", "AIEN_PHYSICS_DIR", "AIEN_REQUIRE_NATIVE_LIBS", + "OMEGA_OMC", "OMEGA_BRIDGE"] { println!("cargo:rerun-if-env-changed={v}"); } - let lock_path = Path::new(&env("CARGO_MANIFEST_DIR")).join("../../omega.lock"); + assert!(std::env::var_os("AIEN_OMEGA_GPU_LIB").is_none(), + "AIEN_OMEGA_GPU_LIB is obsolete: the canonical GPU boundary requires authenticated source and both archives"); + let root = PathBuf::from(env("CARGO_MANIFEST_DIR")); + let lock_path = root.join("../../omega.lock"); println!("cargo:rerun-if-changed={}", lock_path.display()); - let pinned = std::fs::read_to_string(&lock_path) - .unwrap_or_else(|e| panic!("cannot read {}: {e}", lock_path.display())) - .trim() - .to_string(); - assert!( - pinned.len() == 40 && pinned.bytes().all(|b| b.is_ascii_hexdigit()), - "omega.lock must hold one full 40-hex sha" - ); + let pinned = read_pin(&lock_path); println!("cargo:rustc-env=AIEN_OMEGA_PINNED_SHA={pinned}"); - - let root = PathBuf::from(env("CARGO_MANIFEST_DIR")); - let manifest = root.join("abi/omega_gpu.manifest"); - let artifacts_lock = root.join("../../native-artifacts.lock"); - println!("cargo:rerun-if-env-changed=AIEN_OMEGA_GPU_LIB_SHA256"); if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { build::refuse_stub_if_required("aien-omega-gpu"); - build::Identity::stub(&pinned).emit(PREFIX); - return; - } - if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { - let lib = PathBuf::from(lib); - assert!( - lib.is_file(), - "AIEN_OMEGA_GPU_LIB {} is not a file", - lib.display() - ); - build::qualify_prebuilt( - "aien-omega-gpu", - &manifest, - &lib, - "AIEN_OMEGA_GPU_LIB_SHA256", - "unverified", - ) - .emit(PREFIX); - link(&lib); + emit_stub(&pinned); return; } let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") else { - // AIEN_REQUIRE_NATIVE_LIBS=1 (set by scripts/pins.sh env.sh) turns the silent - // stub fallback into a build error: a release or receipt build must never - // discover at run time that it carries the CPU stub (sovereign-core #92). - assert!( - std::env::var("AIEN_REQUIRE_NATIVE_LIBS").as_deref() != Ok("1"), - "aien-omega-gpu: AIEN_REQUIRE_NATIVE_LIBS=1 but neither AIEN_OMEGA_DIR nor AIEN_OMEGA_GPU_LIB is set (run scripts/pins.sh --gpu and source target/pins/env.sh)" - ); - println!("cargo:warning=aien-omega-gpu: no AIEN_OMEGA_DIR or AIEN_OMEGA_GPU_LIB, building the CPU stub"); - build::Identity::stub(&pinned).emit(PREFIX); + assert!(!build::require_native(), + "aien-omega-gpu: AIEN_REQUIRE_NATIVE_LIBS=1 but AIEN_OMEGA_DIR is not set (run scripts/pins.sh --gpu)"); + println!("cargo:warning=aien-omega-gpu: no AIEN_OMEGA_DIR, building the CPU stub"); + emit_stub(&pinned); return; }; - let dir = PathBuf::from(dir); - let head = Command::new("git") - .arg("-C") - .arg(&dir) - .args(["rev-parse", "HEAD"]) - .output() - .ok() - .filter(|o| o.status.success()) - .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()) - .unwrap_or_default(); - assert!( - head == pinned, - "omega checkout {} is at '{head}', omega.lock pins {pinned}", - dir.display() - ); - let physics = std::env::var("AIEN_PHYSICS_DIR") - .map(PathBuf::from) - .unwrap_or_else(|_| dir.join("../physics")); + let dir = PathBuf::from(dir).canonicalize().expect("resolve Omega checkout"); + let head = git(&dir, &["rev-parse", "HEAD"]); + assert_eq!(head.trim(), pinned, "Omega checkout does not match omega.lock"); + let physics = std::env::var("AIEN_PHYSICS_DIR").map(PathBuf::from) + .unwrap_or_else(|_| dir.join("../physics")).canonicalize().expect("resolve physics checkout"); + let cudapp = PathBuf::from(env("AIEN_CUDAPP_DIR")).canonicalize().expect("resolve CUDApp checkout"); let out = PathBuf::from(env("OUT_DIR")).join("omega-build"); - if build::fresh_out_dir(&out, &pinned) { - println!("cargo:warning=aien-omega-gpu: build dir was for another omega commit, rebuilt from clean"); - } - let status = Command::new("make") - .current_dir(&dir) + build::fresh_out_dir(&out, &pinned); + // Build only authenticated commit bytes, not dirty or ignored worktree overlays. + let source = materialize_source(&dir, &pinned, &lock_path, &out); + let cudapp_lock = source.join("cudapp.lock"); + let canonical_pin = read_pin(&cudapp_lock); + println!("cargo:rustc-env=AIEN_OMEGA_CUDAPP_PINNED_SHA={canonical_pin}"); + let status = Command::new("make").current_dir(&source) + .env_remove("BASH_ENV") .arg(format!("OUT_DIR={}", out.display())) .arg(format!("PHYSICS_DIR={}", physics.display())) - .arg(out.join("libomega_gpu.a")) - .status() - .expect("run make"); - assert!( - status.success(), - "make libomega_gpu failed in {}", - dir.display() - ); - let archive = out.join("libomega_gpu.a"); - build::qualify_built( - "aien-omega-gpu", - &manifest, - &artifacts_lock, - &dir, - &physics, - &archive, - &pinned, - true, - ) - .emit(PREFIX); - link(&archive); -} - -fn link(lib: &Path) { - let dir = lib.parent().expect("lib has a parent dir"); - println!("cargo:rustc-link-search=native={}", dir.display()); + .arg(format!("CUDAPP_DIR={}", cudapp.display())) + .arg("libomega_gpu").status().expect("run canonical native build"); + assert!(status.success(), "canonical native archive build failed"); + // Resolve the publication symlink once, then authenticate and link that same stage. + let stage = out.join("cudapp").canonicalize().expect("resolve generated CUDApp stage"); + let status = Command::new("sh").arg(source.join("tools/cudapp-stage.sh")) + .env_remove("BASH_ENV") + .arg("--verify").arg(&cudapp_lock).arg(&stage).status().expect("authenticate CUDApp stage"); + assert!(status.success(), "canonical CUDApp stage authentication failed"); + for input in [cudapp_lock.clone(), stage.join("pin"), stage.join("observed"), + stage.join("archive.sha256"), stage.join("source.sha256"), stage.join("guard.sha256")] { + println!("cargo:rerun-if-changed={}", input.display()); + } + // Cargo recursively watches this pristine source; a modified header or an extra file + // invalidates the cached build and is refused by the next authentication. + println!("cargo:rerun-if-changed={}", stage.join("source").display()); + let canonical_source = stage.join("source"); + let canonical_archive = stage.join("build/libcudapp.a"); + let companion_archive = out.join("libomega_gpu.a"); + let manifest = root.join("abi/omega_gpu.manifest"); + let artifacts = root.join("../../native-artifacts.lock"); + let includes = ["src", "m16", "nvrm", + "third_party/nvidia-open-580.173.02/src/common/sdk/nvidia/inc", + "third_party/nvidia-open-580.173.02/kernel-open/common/inc", + "third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm", + "third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include"] + .iter().map(|p| canonical_source.join(p)).collect(); + let canonical = build::qualify_built_with_includes("aien-omega-gpu", &manifest, &artifacts, + &canonical_source, &canonical_archive, &canonical_pin, true, includes); + canonical.emit(PREFIX); + let companion = build::qualify_companion("aien-omega-gpu", &manifest, &artifacts, + &source, &companion_archive, &pinned); + companion.emit(COMPANION); + // CUDApp also has an archive named libomega_gpu.a. Only this private directory + // is searched for the companion, so the checked archive cannot be substituted. + let link_dir = out.join("admitted-link"); + std::fs::create_dir_all(&link_dir).expect("create admitted archive directory"); + copy_archive(&companion_archive, &link_dir.join("libomega_gpu.a"), &companion.archive_sha256); + copy_archive(&canonical_archive, &link_dir.join("libcudapp.a"), &canonical.archive_sha256); + println!("cargo:canonical_archive={}", link_dir.join("libcudapp.a").display()); + println!("cargo:canonical_sha256={}", canonical.archive_sha256); + println!("cargo:canonical_source={}", canonical_source.display()); + println!("cargo:rustc-link-search=native={}", link_dir.display()); println!("cargo:rustc-link-lib=static=omega_gpu"); + println!("cargo:rustc-link-lib=static=cudapp"); println!("cargo:rustc-link-lib=dylib=pthread"); println!("cargo:rustc-link-lib=dylib=m"); - println!("cargo:rerun-if-changed={}", lib.display()); println!("cargo:rustc-cfg=has_omega_gpu"); } -fn env(k: &str) -> String { - std::env::var(k).unwrap_or_else(|_| panic!("{k} not set")) +fn copy_archive(source: &Path, destination: &Path, admitted_sha: &str) { + if aien_abi_conformance::identity::sha256_file(destination).ok().as_deref() != Some(admitted_sha) { + std::fs::copy(source, destination).expect("snapshot admitted archive"); + } + assert_eq!(admitted_sha, + aien_abi_conformance::identity::sha256_file(destination).expect("hash admitted link input"), + "admitted archive changed before linking"); + println!("cargo:rerun-if-changed={}", destination.display()); +} + +fn emit_stub(pinned: &str) { + println!("cargo:rustc-env=AIEN_OMEGA_CUDAPP_PINNED_SHA="); + build::Identity::stub("").emit(PREFIX); + build::Identity::stub(pinned).emit(COMPANION); +} + +fn materialize_source(repo: &Path, pinned: &str, lock: &Path, out: &Path) -> PathBuf { + // The checker cannot establish its own trust after execution. Authenticate the + // bounded commit/tree/blob chain first, then execute only these private bytes. + let helper = out.join("authenticated-source-checker.sh"); + let checker = aien_abi_conformance::source::authenticated_source_checker(repo, pinned); + if std::fs::read(&helper).ok().as_deref() != Some(checker.as_slice()) { + std::fs::write(&helper, checker).expect("snapshot authenticated source checker"); + } + let roots = git(repo, &["ls-tree", "-z", "--name-only", pinned]); + let expected_roots: BTreeSet = roots.split('\0').filter(|s| !s.is_empty()).map(str::to_owned).collect(); + let source = out.join("source"); + let run = |mode: &str, names: &BTreeSet| { + let status = Command::new("bash").arg(&helper).arg(mode).arg(&source).args(names) + .env_remove("BASH_ENV") + .env("AIENOS_LOCK", "").env("AIENOS_LOCK_FILE", lock).env("AIENOS_LOCK_REPO", repo) + .status().expect("run raw-object source authentication"); + assert!(status.success(), "Omega source snapshot authentication failed"); + }; + run("materialize", &expected_roots); + let mut roots = expected_roots; + for entry in std::fs::read_dir(&source).expect("read source snapshot entries") { + roots.insert(entry.expect("read source entry").file_name().into_string().expect("UTF-8 source entry")); + } + run("verify-dir", &roots); + println!("cargo:rerun-if-changed={}", helper.display()); + source +} + +fn git(repo: &Path, args: &[&str]) -> String { + let result = Command::new("git").arg("-C").arg(repo) + .env("GIT_NO_REPLACE_OBJECTS", "1").env("GIT_GRAFT_FILE", "/nonexistent/core-native-grafts") + .args(args).output().expect("read native source identity"); + assert!(result.status.success(), "git source identity failed: {args:?}"); + String::from_utf8(result.stdout).expect("UTF-8 git identity") +} + +fn read_pin(path: &Path) -> String { + let pin = std::fs::read_to_string(path).unwrap_or_else(|e| panic!("{}: {e}", path.display())); + let pin = pin.trim(); + assert!(pin.len() == 40 && pin.bytes().all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)), + "{} must hold one lowercase full 40-hex source revision", path.display()); + pin.into() +} + +fn env(key: &str) -> String { + std::env::var(key).unwrap_or_else(|_| panic!("{key} not set")) } diff --git a/crates/aien-omega-gpu/src/lib.rs b/crates/aien-omega-gpu/src/lib.rs index da9550df..5019c9f7 100644 --- a/crates/aien-omega-gpu/src/lib.rs +++ b/crates/aien-omega-gpu/src/lib.rs @@ -1,9 +1,9 @@ -//! Safe Rust wrapper over omega's native GPU matmul (no CUDA). +//! Safe Rust wrapper over canonical CUDApp's native GPU ABI. //! -//! Built against the omega commit in `omega.lock`. With `cfg(has_omega_gpu)` the -//! real library is linked; otherwise (`AIEN_FORCE_CPU_STUB=1`, or no omega checkout -//! given) every chip call returns [`OmegaGpuError::Unavailable`], so CI passes -//! without the chip. Only the API on omega main at the pinned commit is wrapped. +//! Omega's authenticated dependency lock selects CUDApp. The CPU/evidence companion +//! and canonical archive are admitted separately; a host build does not qualify a +//! device path or remove the NVIDIA kernel-driver or firmware dependencies. +//! Without native sources every chip call returns [`OmegaGpuError::Unavailable`]. //! //! Conventions: row-major, `C[m x n] = A[m x k] * B[k x n]`, f32 output. //! Inputs are bf16 (`matmul_bf16`) or f32 rounded to bf16 on the host (`matmul_f32`). @@ -18,17 +18,23 @@ pub use ffi::OmegaGpuMatmulInfo; /// Omega commit this crate was built against (from `omega.lock`). pub const PINNED_OMEGA_SHA: &str = env!("AIEN_OMEGA_PINNED_SHA"); +/// Canonical CUDApp source selected by the authenticated Omega dependency lock. +pub const PINNED_CUDAPP_SHA: &str = env!("AIEN_OMEGA_CUDAPP_PINNED_SHA"); + +pub const fn cudapp_pinned_sha() -> &'static str { + PINNED_CUDAPP_SHA +} + /// True when the real native library is linked (not the stub). pub const fn is_native() -> bool { cfg!(has_omega_gpu) } -/// What this binary linked for the omega GPU engine (stub, pinned source, developer override or -/// prebuilt), the C ABI check result and the archive digest, as `build.rs` established them. -/// Only `qualifies()` identities count as release-grade native qualification. +/// Actual canonical GPU ABI archive, its checked C ABI and independently locked digest. +/// Pair qualification also requires the separately admitted Omega companion. pub fn native_identity() -> aien_abi_conformance::NativeIdentity { aien_abi_conformance::NativeIdentity { - component: "libomega_gpu.a", + component: "libcudapp.a", link: env!("AIEN_OMEGA_GPU_LINK"), abi: env!("AIEN_OMEGA_GPU_ABI"), digest: env!("AIEN_OMEGA_GPU_DIGEST"), @@ -41,6 +47,85 @@ pub fn native_identity() -> aien_abi_conformance::NativeIdentity { } } +/// Omega CPU/evidence companion. It has no Rust-facing GPU ABI and never claims one. +pub fn native_companion_identity() -> aien_abi_conformance::NativeIdentity { + aien_abi_conformance::NativeIdentity { + component: "libomega_gpu.a", + link: env!("AIEN_OMEGA_COMPANION_LINK"), + abi: env!("AIEN_OMEGA_COMPANION_ABI"), + digest: env!("AIEN_OMEGA_COMPANION_DIGEST"), + archive_sha256: env!("AIEN_OMEGA_COMPANION_ARCHIVE_SHA256"), + source_sha: env!("AIEN_OMEGA_COMPANION_SOURCE_SHA"), + aienos_lock: env!("AIEN_OMEGA_COMPANION_AIENOS_LOCK"), + physics_lock: env!("AIEN_OMEGA_COMPANION_PHYSICS_LOCK"), + target: env!("AIEN_OMEGA_COMPANION_TARGET"), + cc: env!("AIEN_OMEGA_COMPANION_CC"), + } +} + +/// Both real link inputs must be admitted. A standalone canonical identity is insufficient. +pub fn native_pair_qualifies() -> bool { + pair_qualifies(&native_identity(), &native_companion_identity(), PINNED_CUDAPP_SHA, PINNED_OMEGA_SHA) +} + +fn pair_qualifies( + canonical: &aien_abi_conformance::NativeIdentity, + companion: &aien_abi_conformance::NativeIdentity, + canonical_pin: &str, + omega_pin: &str, +) -> bool { + canonical.qualifies() + && canonical.component == "libcudapp.a" + && companion.component == "libomega_gpu.a" + && canonical.source_sha == canonical_pin + && companion.link == "pinned-source" + && companion.abi == "none" + && companion.digest == "locked" + && companion.source_sha == omega_pin +} + +#[cfg(test)] +mod native_pair_tests { + use super::*; + use aien_abi_conformance::NativeIdentity; + + #[test] + fn neither_archive_can_qualify_the_pair_alone() { + let canonical_pin = "1111111111111111111111111111111111111111"; + let omega_pin = "2222222222222222222222222222222222222222"; + let canonical = NativeIdentity { + component: "libcudapp.a", link: "pinned-source", abi: "pass", digest: "locked", + archive_sha256: "canonical-fixture", source_sha: canonical_pin, + aienos_lock: "", physics_lock: "", target: "host-fixture", cc: "fixture", + }; + let companion = NativeIdentity { + component: "libomega_gpu.a", abi: "none", archive_sha256: "companion-fixture", + source_sha: omega_pin, ..canonical + }; + assert!(canonical.qualifies()); + assert!(!companion.qualifies(), "no fictitious companion ABI pass"); + assert!(pair_qualifies(&canonical, &companion, canonical_pin, omega_pin)); + for bad in [ + NativeIdentity { digest: "unrecorded", ..canonical }, + NativeIdentity { component: "libomega_gpu.a", ..canonical }, + NativeIdentity { link: "prebuilt", ..canonical }, + NativeIdentity { abi: "unchecked", ..canonical }, + NativeIdentity { source_sha: omega_pin, ..canonical }, + ] { + assert!(!pair_qualifies(&bad, &companion, canonical_pin, omega_pin), "{bad:?}"); + } + for bad in [ + NativeIdentity { digest: "unrecorded", ..companion }, + NativeIdentity { component: "libcudapp.a", ..companion }, + NativeIdentity { link: "dev-override", ..companion }, + NativeIdentity { abi: "pass", ..companion }, + NativeIdentity { source_sha: canonical_pin, ..companion }, + ] { + assert!(!pair_qualifies(&canonical, &bad, canonical_pin, omega_pin), "{bad:?}"); + } + } +} + #[derive(Debug, Clone, PartialEq, Eq)] pub enum OmegaGpuError { /// Stub build: no native library linked. diff --git a/crates/aien-omega-gpu/tests/abi_manifest.rs b/crates/aien-omega-gpu/tests/abi_manifest.rs index 4382250f..755450cd 100644 --- a/crates/aien-omega-gpu/tests/abi_manifest.rs +++ b/crates/aien-omega-gpu/tests/abi_manifest.rs @@ -1,4 +1,4 @@ -//! The Rust mirror of the omega GPU ABI (src/ffi.rs) must equal abi/omega_gpu.manifest, +//! The Rust mirror of the canonical CUDApp GPU ABI must equal abi/omega_gpu.manifest, //! field by field (offset, size, kind, order), constant by constant and signature by //! signature. Runs in every build, the stub included. @@ -8,27 +8,35 @@ fn rust_ffi_matches_the_manifest() { aien_abi_conformance::assert_manifest(&aien_omega_gpu::ffi::rust_abi(), &path); } -/// What this test binary linked, as `build.rs` recorded it. Prints one -/// `AIEN_NATIVE_IDENTITY {json}` line (scripts/abi-qualify.sh collects it). A linked build -/// must never report the stub, a stub build must never qualify, and with -/// `AIEN_ABI_QUALIFY=1` (the qualification run) the identity must qualify. +/// Both actual link inputs, with the canonical ABI and companion admission kept separate. +/// The companion has no Rust-facing GPU ABI; it must not fabricate `abi=pass`. #[test] fn native_identity_matches_the_link() { let id = aien_omega_gpu::native_identity(); + let companion = aien_omega_gpu::native_companion_identity(); println!("AIEN_NATIVE_IDENTITY {}", id.to_json()); + println!("AIEN_NATIVE_IDENTITY {}", companion.to_json()); + println!("AIEN_NATIVE_PAIR_QUALIFIES {}", aien_omega_gpu::native_pair_qualifies()); + assert_eq!(id.component, "libcudapp.a"); + assert_eq!(companion.component, "libomega_gpu.a"); + assert_eq!(companion.abi, "none"); if cfg!(has_omega_gpu) { assert_ne!(id.link, "stub", "{id:?}"); assert!(id.digest != "none", "{id:?}"); + assert_eq!(id.source_sha, aien_omega_gpu::PINNED_CUDAPP_SHA); + assert_eq!(companion.source_sha, aien_omega_gpu::PINNED_OMEGA_SHA); + assert_eq!(companion.link, "pinned-source"); + assert_ne!(companion.digest, "none"); } else { assert_eq!(id.link, "stub", "{id:?}"); assert!(!id.qualifies()); + assert_eq!(companion.link, "stub"); + assert!(!aien_omega_gpu::native_pair_qualifies()); } if std::env::var("AIEN_ABI_QUALIFY").as_deref() == Ok("1") { assert!( - id.qualifies(), - "{} does not qualify: {:?}", - id.component, - id.gaps() + aien_omega_gpu::native_pair_qualifies(), + "canonical GPU/companion pair does not qualify: {id:?}, {companion:?}" ); } } diff --git a/crates/aien-omega-moe/Cargo.toml b/crates/aien-omega-moe/Cargo.toml index f187442f..d28a25e1 100644 --- a/crates/aien-omega-moe/Cargo.toml +++ b/crates/aien-omega-moe/Cargo.toml @@ -9,3 +9,6 @@ build = "build.rs" [dependencies] aien-omega-gpu = { path = "../aien-omega-gpu" } + +[build-dependencies] +aien-abi-conformance = { path = "../aien-abi-conformance" } diff --git a/crates/aien-omega-moe/build.rs b/crates/aien-omega-moe/build.rs index 9b6de88f..c6a1e0e4 100644 --- a/crates/aien-omega-moe/build.rs +++ b/crates/aien-omega-moe/build.rs @@ -1,56 +1,23 @@ //! Decides whether omega's MoE window API (`src/omega_gpu_moe_api.h`, OWN-30B cut 2) is linked. //! -//! The archive itself is linked by `aien-omega-gpu`'s build script (this crate only declares -//! the extra symbols), so the decision mirrors its inputs: -//! * `AIEN_FORCE_CPU_STUB=1`: stub. -//! * `AIEN_OMEGA_GPU_LIB=`: native when `nm` finds -//! `omega_gpu_matmul_resident_windows_f32` defined in that archive. -//! * `AIEN_OMEGA_DIR=`: native when the checkout has `src/omega_gpu_moe_api.h`. -//! * otherwise: stub (every call returns `Unavailable`). +//! Canonical capabilities are inspected from the admitted canonical archive exported by +//! `aien-omega-gpu` via Cargo DEP metadata. //! //! `cfg(has_omega_moe)` is set only when native. A stub never fails the build: the whole-tensor //! fallback in the model code stays usable, and `is_native()` says which one a binary carries. -use std::path::Path; -use std::process::Command; +use aien_abi_conformance::CanonicalFeatures; fn main() { println!("cargo:rustc-check-cfg=cfg(has_omega_moe)"); - for v in [ - "AIEN_FORCE_CPU_STUB", - "AIEN_OMEGA_GPU_LIB", - "AIEN_OMEGA_DIR", - ] { - println!("cargo:rerun-if-env-changed={v}"); - } - if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { - return; - } - if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { - println!("cargo:rerun-if-changed={lib}"); - if archive_defines(Path::new(&lib), "omega_gpu_matmul_resident_windows_f32") { - println!("cargo:rustc-cfg=has_omega_moe"); - } else { - println!("cargo:warning=aien-omega-moe: {lib} does not define the MoE window API; window calls are stubbed"); - } + let Some(cf) = CanonicalFeatures::from_dep("aien-omega-moe") else { return; - } - if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { - let header = Path::new(&dir).join("src/omega_gpu_moe_api.h"); - println!("cargo:rerun-if-changed={}", header.display()); - if header.is_file() { - println!("cargo:rustc-cfg=has_omega_moe"); - } else { - println!("cargo:warning=aien-omega-moe: {dir} has no src/omega_gpu_moe_api.h (omega before OWN-30B cut 2); window calls are stubbed"); - } - } -} - -fn archive_defines(lib: &Path, symbol: &str) -> bool { - let Ok(out) = Command::new("nm").arg(lib).output() else { - println!("cargo:warning=aien-omega-moe: nm not available, assuming the archive lacks the MoE window API"); - return false; }; - String::from_utf8_lossy(&out.stdout) - .lines() - .any(|l| l.ends_with(&format!(" T {symbol}"))) + if cf.has_symbol("omega_gpu_matmul_resident_windows_f32") { + println!("cargo:rustc-cfg=has_omega_moe"); + } else { + println!( + "cargo:warning=aien-omega-moe: {} does not define the MoE window API; window calls are stubbed", + cf.archive().display() + ); + } } diff --git a/crates/aien-omega-pf/Cargo.toml b/crates/aien-omega-pf/Cargo.toml index 815d79e4..7f9f5308 100644 --- a/crates/aien-omega-pf/Cargo.toml +++ b/crates/aien-omega-pf/Cargo.toml @@ -10,3 +10,6 @@ build = "build.rs" [dependencies] aien-omega-gpu = { path = "../aien-omega-gpu" } aien-omega-dattn = { path = "../aien-omega-dattn" } + +[build-dependencies] +aien-abi-conformance = { path = "../aien-abi-conformance" } diff --git a/crates/aien-omega-pf/build.rs b/crates/aien-omega-pf/build.rs index ed82d73e..11ccd855 100644 --- a/crates/aien-omega-pf/build.rs +++ b/crates/aien-omega-pf/build.rs @@ -1,98 +1,51 @@ -//! Decides which parts of omega's prefill API are linked (pattern of `aien-omega-fp8/build.rs`). +//! Decides which parts of omega's prefill API are linked. //! -//! The archive itself is linked by `aien-omega-gpu`'s build script; this crate only declares -//! the extra symbols, so the decision mirrors its inputs: -//! * `AIEN_FORCE_CPU_STUB=1`: stub. -//! * `AIEN_OMEGA_GPU_LIB=`: `nm` decides per symbol. -//! * `AIEN_OMEGA_DIR=`: the headers decide (`src/omega_gpu_prefill.h`, -//! `src/omega_gpu_prefill_attn_api.h`). +//! Canonical capabilities are inspected from the admitted canonical archive exported by +//! `aien-omega-gpu` via Cargo DEP metadata. //! -//! `cfg(has_omega_pf)`: `omega_gpu_pf_qgemm` defined (quantiser, QMMA grouped GEMM, pf buffers). +//! `cfg(has_omega_pf)`: `omega_gpu_pf_qgemm`, `omega_gpu_pf_quant`, `omega_gpu_pf_alloc_dev` defined (quantiser, QMMA grouped GEMM, pf buffers). //! `cfg(has_omega_pattn)`: `omega_gpu_prefill_attn` defined (host-pointer prefill attention). //! `cfg(has_omega_pattn_dev)`: `omega_gpu_prefill_attn_dev` defined (device-pointer entry). +//! `cfg(has_omega_pfhost)`: prefill router logits, MoE combine, router pack and rows. //! Otherwise every call returns `Unavailable`; a stub never fails the build. -use std::path::Path; -use std::process::Command; +use aien_abi_conformance::CanonicalFeatures; fn main() { - for c in ["has_omega_pf", "has_omega_pattn", "has_omega_pattn_dev"] { + for c in ["has_omega_pf", "has_omega_pattn", "has_omega_pattn_dev", "has_omega_pfhost"] { println!("cargo:rustc-check-cfg=cfg({c})"); } - println!("cargo:rustc-check-cfg=cfg(has_omega_pfhost)"); - for v in [ - "AIEN_FORCE_CPU_STUB", - "AIEN_OMEGA_GPU_LIB", - "AIEN_OMEGA_DIR", - ] { - println!("cargo:rerun-if-env-changed={v}"); - } - if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { + let Some(cf) = CanonicalFeatures::from_dep("aien-omega-pf") else { return; + }; + let has_pf = cf.has_symbol("omega_gpu_pf_qgemm") + && cf.has_symbol("omega_gpu_pf_quant") + && cf.has_symbol("omega_gpu_pf_alloc_dev"); + if has_pf { + println!("cargo:rustc-cfg=has_omega_pf"); + } else { + println!( + "cargo:warning=aien-omega-pf: {} does not define omega_gpu_pf_qgemm; prefill GEMM calls are stubbed", + cf.archive().display() + ); } - if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { - println!("cargo:rerun-if-changed={lib}"); - let syms = defined_symbols(Path::new(&lib)); - let has = |s: &str| syms.iter().any(|d| d == s); - if has("omega_gpu_pf_qgemm") && has("omega_gpu_pf_quant") && has("omega_gpu_pf_alloc_dev") { - println!("cargo:rustc-cfg=has_omega_pf"); - } else { - println!("cargo:warning=aien-omega-pf: {lib} does not define omega_gpu_pf_qgemm; prefill GEMM calls are stubbed"); - } - if has("omega_gpu_prefill_attn") { - println!("cargo:rustc-cfg=has_omega_pattn"); - if has("omega_gpu_prefill_attn_dev") { - println!("cargo:rustc-cfg=has_omega_pattn_dev"); - } - } else { - println!("cargo:warning=aien-omega-pf: {lib} does not define omega_gpu_prefill_attn; prefill attention is stubbed"); + if cf.has_symbol("omega_gpu_prefill_attn") { + println!("cargo:rustc-cfg=has_omega_pattn"); + if cf.has_symbol("omega_gpu_prefill_attn_dev") { + println!("cargo:rustc-cfg=has_omega_pattn_dev"); } - // W-L1G-D: router logits + MoE combine (omega_gpu_pfhost.h) - if has("omega_gpu_pf_qgemm") - && has("omega_gpu_pf_router_logits") - && has("omega_gpu_pf_moe_combine") - && has("omega_gpu_pf_router_pack") - && has("omega_gpu_pf_router_rows") - { - println!("cargo:rustc-cfg=has_omega_pfhost"); - } - return; + } else { + println!( + "cargo:warning=aien-omega-pf: {} does not define omega_gpu_prefill_attn; prefill attention is stubbed", + cf.archive().display() + ); } - if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { - let pf = Path::new(&dir).join("src/omega_gpu_prefill.h"); - let pa = Path::new(&dir).join("src/omega_gpu_prefill_attn_api.h"); - println!("cargo:rerun-if-changed={}", pf.display()); - println!("cargo:rerun-if-changed={}", pa.display()); - // W-L1G-D: router logits + MoE combine (omega_gpu_pfhost.h) - let ph = Path::new(&dir).join("src/omega_gpu_pfhost.h"); - println!("cargo:rerun-if-changed={}", ph.display()); - if std::fs::read_to_string(&ph).is_ok_and(|t| { - t.contains("omega_gpu_pf_router_logits(") && t.contains("omega_gpu_pf_moe_combine(") - }) { - println!("cargo:rustc-cfg=has_omega_pfhost"); - } - if std::fs::read_to_string(&pf) - .is_ok_and(|t| t.contains("omega_gpu_pf_qgemm(") && t.contains("omega_gpu_pf_quant(")) - { - println!("cargo:rustc-cfg=has_omega_pf"); - } - if let Ok(t) = std::fs::read_to_string(&pa) { - if t.contains("omega_gpu_prefill_attn(") { - println!("cargo:rustc-cfg=has_omega_pattn"); - if t.contains("omega_gpu_prefill_attn_dev(") { - println!("cargo:rustc-cfg=has_omega_pattn_dev"); - } - } - } + // W-L1G-D: router logits + MoE combine (omega_gpu_pfhost.h) + if has_pf + && cf.has_symbol("omega_gpu_pf_router_logits") + && cf.has_symbol("omega_gpu_pf_moe_combine") + && cf.has_symbol("omega_gpu_pf_router_pack") + && cf.has_symbol("omega_gpu_pf_router_rows") + { + println!("cargo:rustc-cfg=has_omega_pfhost"); } } - -fn defined_symbols(lib: &Path) -> Vec { - let Ok(out) = Command::new("nm").arg(lib).output() else { - println!("cargo:warning=aien-omega-pf: nm not available, assuming the archive lacks the prefill API"); - return Vec::new(); - }; - String::from_utf8_lossy(&out.stdout) - .lines() - .filter_map(|l| l.split_once(" T ").map(|(_, s)| s.to_string())) - .collect() -} diff --git a/crates/aien-omega-q38/Cargo.toml b/crates/aien-omega-q38/Cargo.toml index caeda539..91880a36 100644 --- a/crates/aien-omega-q38/Cargo.toml +++ b/crates/aien-omega-q38/Cargo.toml @@ -9,3 +9,6 @@ build = "build.rs" [dependencies] aien-omega-gpu = { path = "../aien-omega-gpu" } + +[build-dependencies] +aien-abi-conformance = { path = "../aien-abi-conformance" } diff --git a/crates/aien-omega-q38/build.rs b/crates/aien-omega-q38/build.rs index cc4ab924..e17ca9ad 100644 --- a/crates/aien-omega-q38/build.rs +++ b/crates/aien-omega-q38/build.rs @@ -1,80 +1,37 @@ //! Decides whether omega's Qwen3.8-27B decode pieces (`src/omega_gpu_q38_graph.h`, sc #642 //! on the omega side) are linked. //! -//! The archive itself is linked by `aien-omega-gpu`'s build script (this crate only declares -//! the extra symbols), so the decision mirrors its inputs: -//! * `AIEN_FORCE_CPU_STUB=1`: stub. -//! * `AIEN_OMEGA_GPU_LIB=`: native when `nm` finds `omega_gpu_q38_graph_create` -//! defined in that archive. -//! * `AIEN_OMEGA_DIR=`: native when the checkout has `src/omega_gpu_q38_graph.h`. -//! * otherwise: stub (every call returns `Unavailable`). -//! -//! `cfg(has_omega_q38_prefill)` is set when, in addition, the prefill entries are linked -//! (`omega_gpu_gdn_prefill` and `omega_gpu_prefill_attn256`, omega#543 / #545; with -//! `AIEN_OMEGA_DIR`, the header `src/omega_gpu_prefill_attn256_api.h`). +//! Canonical capabilities are inspected from the admitted canonical archive exported by +//! `aien-omega-gpu` via Cargo DEP metadata. //! //! `cfg(has_omega_q38)` is set only when native. A stub never fails the build: the Qwen3.8 //! engine reports itself unavailable, and `is_native()` says which one a binary carries. -use std::path::Path; -use std::process::Command; +//! `cfg(has_omega_q36)` is set when Qwen3.6-35B-A3B decode graph entries are defined. +//! `cfg(has_omega_q38_prefill)` is set when, in addition, the prefill entries are linked +//! (`omega_gpu_gdn_prefill` and `omega_gpu_prefill_attn256`). +use aien_abi_conformance::CanonicalFeatures; fn main() { println!("cargo:rustc-check-cfg=cfg(has_omega_q38)"); println!("cargo:rustc-check-cfg=cfg(has_omega_q38_prefill)"); println!("cargo:rustc-check-cfg=cfg(has_omega_q36)"); - for v in [ - "AIEN_FORCE_CPU_STUB", - "AIEN_OMEGA_GPU_LIB", - "AIEN_OMEGA_DIR", - ] { - println!("cargo:rerun-if-env-changed={v}"); - } - if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { + let Some(cf) = CanonicalFeatures::from_dep("aien-omega-q38") else { return; - } - if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { - println!("cargo:rerun-if-changed={lib}"); - if archive_defines(Path::new(&lib), "omega_gpu_q38_graph_create") { - println!("cargo:rustc-cfg=has_omega_q38"); - if archive_defines(Path::new(&lib), "omega_gpu_q36_graph_create") { - println!("cargo:rustc-cfg=has_omega_q36"); - } - if archive_defines(Path::new(&lib), "omega_gpu_gdn_prefill") - && archive_defines(Path::new(&lib), "omega_gpu_prefill_attn256") - { - println!("cargo:rustc-cfg=has_omega_q38_prefill"); - } - } else { - println!("cargo:warning=aien-omega-q38: {lib} does not define the q38 graph API; the Qwen3.8 decode is stubbed"); + }; + if cf.has_symbol("omega_gpu_q38_graph_create") { + println!("cargo:rustc-cfg=has_omega_q38"); + if cf.has_symbol("omega_gpu_q36_graph_create") { + println!("cargo:rustc-cfg=has_omega_q36"); } - return; - } - if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { - let header = Path::new(&dir).join("src/omega_gpu_q38_graph.h"); - println!("cargo:rerun-if-changed={}", header.display()); - if header.is_file() { - println!("cargo:rustc-cfg=has_omega_q38"); - if Path::new(&dir).join("src/omega_gpu_q36_graph.h").is_file() { - println!("cargo:rustc-cfg=has_omega_q36"); - } - if Path::new(&dir) - .join("src/omega_gpu_prefill_attn256_api.h") - .is_file() - { - println!("cargo:rustc-cfg=has_omega_q38_prefill"); - } - } else { - println!("cargo:warning=aien-omega-q38: {dir} has no src/omega_gpu_q38_graph.h (omega before sc #642); the Qwen3.8 decode is stubbed"); + if cf.has_symbol("omega_gpu_gdn_prefill") + && cf.has_symbol("omega_gpu_prefill_attn256") + { + println!("cargo:rustc-cfg=has_omega_q38_prefill"); } + } else { + println!( + "cargo:warning=aien-omega-q38: {} does not define the q38 graph API; the Qwen3.8 decode is stubbed", + cf.archive().display() + ); } } - -fn archive_defines(lib: &Path, symbol: &str) -> bool { - let Ok(out) = Command::new("nm").arg(lib).output() else { - println!("cargo:warning=aien-omega-q38: nm not available, assuming the archive lacks the q38 graph API"); - return false; - }; - String::from_utf8_lossy(&out.stdout) - .lines() - .any(|l| l.ends_with(&format!(" T {symbol}"))) -} diff --git a/crates/aien-omega-router/Cargo.toml b/crates/aien-omega-router/Cargo.toml index 5c61d602..bae843b3 100644 --- a/crates/aien-omega-router/Cargo.toml +++ b/crates/aien-omega-router/Cargo.toml @@ -9,3 +9,6 @@ build = "build.rs" [dependencies] aien-omega-gpu = { path = "../aien-omega-gpu" } + +[build-dependencies] +aien-abi-conformance = { path = "../aien-abi-conformance" } diff --git a/crates/aien-omega-router/build.rs b/crates/aien-omega-router/build.rs index 65ec13b4..2f3b909a 100644 --- a/crates/aien-omega-router/build.rs +++ b/crates/aien-omega-router/build.rs @@ -1,58 +1,25 @@ //! Decides whether omega's one-launch MoE router (`src/omega_gpu_router_api.h`, //! OWN-30B router cut on the omega side) is linked. //! -//! The archive itself is linked by `aien-omega-gpu`'s build script (this crate only declares -//! the extra symbols), so the decision mirrors its inputs: -//! * `AIEN_FORCE_CPU_STUB=1`: stub. -//! * `AIEN_OMEGA_GPU_LIB=`: native when `nm` finds `omega_gpu_router` defined -//! in that archive. -//! * `AIEN_OMEGA_DIR=`: native when the checkout has `src/omega_gpu_router_api.h`. -//! * otherwise: stub (every call returns `Unavailable`). +//! Canonical capabilities are inspected from the admitted canonical archive exported by +//! `aien-omega-gpu` via Cargo DEP metadata. //! //! `cfg(has_omega_router)` is set only when native. A stub never fails the build: the engine //! keeps its host routing, and `is_native()` says which //! one a binary carries. -use std::path::Path; -use std::process::Command; +use aien_abi_conformance::CanonicalFeatures; fn main() { println!("cargo:rustc-check-cfg=cfg(has_omega_router)"); - for v in [ - "AIEN_FORCE_CPU_STUB", - "AIEN_OMEGA_GPU_LIB", - "AIEN_OMEGA_DIR", - ] { - println!("cargo:rerun-if-env-changed={v}"); - } - if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { - return; - } - if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { - println!("cargo:rerun-if-changed={lib}"); - if archive_defines(Path::new(&lib), "omega_gpu_router") { - println!("cargo:rustc-cfg=has_omega_router"); - } else { - println!("cargo:warning=aien-omega-router: {lib} does not define the device router API; the device router is stubbed"); - } + let Some(cf) = CanonicalFeatures::from_dep("aien-omega-router") else { return; - } - if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { - let header = Path::new(&dir).join("src/omega_gpu_router_api.h"); - println!("cargo:rerun-if-changed={}", header.display()); - if header.is_file() { - println!("cargo:rustc-cfg=has_omega_router"); - } else { - println!("cargo:warning=aien-omega-router: {dir} has no src/omega_gpu_router_api.h (omega before OWN-30B cut 8); the device router is stubbed"); - } - } -} - -fn archive_defines(lib: &Path, symbol: &str) -> bool { - let Ok(out) = Command::new("nm").arg(lib).output() else { - println!("cargo:warning=aien-omega-router: nm not available, assuming the archive lacks the device router API"); - return false; }; - String::from_utf8_lossy(&out.stdout) - .lines() - .any(|l| l.ends_with(&format!(" T {symbol}"))) + if cf.has_symbol("omega_gpu_router") { + println!("cargo:rustc-cfg=has_omega_router"); + } else { + println!( + "cargo:warning=aien-omega-router: {} does not define the device router API; the device router is stubbed", + cf.archive().display() + ); + } } diff --git a/crates/aien-serve-http/build.rs b/crates/aien-serve-http/build.rs index 7c52ff82..44b9e802 100644 --- a/crates/aien-serve-http/build.rs +++ b/crates/aien-serve-http/build.rs @@ -6,9 +6,6 @@ //! - `AIEN_SERVE_HTTP_GIT_DIRTY`: `1` when `git status` showed modified tracked files at build //! time, `0` when clean (or `AIEN_BUILD_COMMIT` given), `unknown` without git. Re-checked //! when HEAD or the index moves, not on every unstaged edit. -//! - `AIEN_SERVE_HTTP_OMEGA_LOCK`: the omega commit `omega.lock` pins. -//! - `AIEN_SERVE_HTTP_GPU_RECORDED_SHA256`: the `libomega_gpu.a` sha256 `native-artifacts.lock` -//! records for that commit and this target, or `unrecorded`. use std::path::{Path, PathBuf}; use std::process::Command; @@ -28,7 +25,6 @@ fn git(root: &Path, args: &[&str]) -> Option { fn main() { let manifest = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); let root = manifest.join("../.."); - let target = std::env::var("TARGET").unwrap_or_default(); println!("cargo:rerun-if-env-changed=AIEN_BUILD_COMMIT"); let forced = std::env::var("AIEN_BUILD_COMMIT") @@ -72,32 +68,4 @@ fn main() { }; println!("cargo:rustc-env=AIEN_SERVE_HTTP_GIT_COMMIT={commit}"); println!("cargo:rustc-env=AIEN_SERVE_HTTP_GIT_DIRTY={dirty}"); - - let lock_path = root.join("omega.lock"); - println!("cargo:rerun-if-changed={}", lock_path.display()); - let omega = std::fs::read_to_string(&lock_path) - .map(|s| s.trim().to_string()) - .unwrap_or_default(); - let omega = if omega.is_empty() { - "unknown".to_string() - } else { - omega - }; - println!("cargo:rustc-env=AIEN_SERVE_HTTP_OMEGA_LOCK={omega}"); - - let artifacts = root.join("native-artifacts.lock"); - println!("cargo:rerun-if-changed={}", artifacts.display()); - let recorded = std::fs::read_to_string(&artifacts) - .ok() - .and_then(|text| { - text.lines() - .filter(|l| !l.trim_start().starts_with('#')) - .find_map(|l| { - let f: Vec<&str> = l.split_whitespace().collect(); - (f.len() >= 4 && f[0] == "libomega_gpu.a" && f[1] == omega && f[2] == target) - .then(|| f[3].to_string()) - }) - }) - .unwrap_or_else(|| "unrecorded".to_string()); - println!("cargo:rustc-env=AIEN_SERVE_HTTP_GPU_RECORDED_SHA256={recorded}"); } diff --git a/crates/aien-serve-http/src/kv_persist.rs b/crates/aien-serve-http/src/kv_persist.rs index 11129180..26e45e29 100644 --- a/crates/aien-serve-http/src/kv_persist.rs +++ b/crates/aien-serve-http/src/kv_persist.rs @@ -57,6 +57,8 @@ use sha2::{Digest, Sha256}; pub const ARITH_ID: &str = "omega-qwen3-moe"; /// Domain of the omega engine config digest. const OMEGA_ENG_DOMAIN: &[u8] = b"AIEN-PKV-OMEGA-ENG-V1\0"; +/// Domain of the omega two-archive engine build id (sc#505, ADR 0003 section 1.2.2). +const OMEGA_BUILD_DOMAIN_V2: &[u8] = b"AIEN-PKV-OMEGA-BUILD-V2\0"; /// How long a restore waits for its chunks before giving up (plain prefill). pub const LOAD_TIMEOUT: Duration = Duration::from_secs(10); /// How long a park waits for the storage worker's park budget to free (its earlier chunks @@ -84,6 +86,7 @@ pub const NEUTRAL_ENV: &[&str] = &[ "AIEN_OMEGA_GPU_LIB", "AIEN_OMEGA_GPU_LIB_SHA256", "AIEN_OMEGA_PINNED_SHA", + "AIEN_OMEGA_CUDAPP_PINNED_SHA", "AIEN_OMEGA_COMPOSE", "AIEN_OMEGA_COMPOSE_DIR", "AIEN_OMEGA_COMPOSE_LIB", @@ -99,16 +102,26 @@ pub const MUTANT_ENV: &[&str] = &["OWN30B_DECODE_GRAPH_MUTANT"]; /// The build of the engine that writes the K/V. #[derive(Debug, Clone, PartialEq, Eq)] pub struct OmegaBuild { - /// The omega commit `omega.lock` pins. - pub omega_commit: String, - /// How `libomega_gpu.a` was linked (`pinned-source`, `dev-override`, `prebuilt`, `stub`). + /// The canonical CUDApp commit pinned for this build. + pub cudapp_commit: String, + /// How canonical `libcudapp.a` was linked (`pinned-source`, `dev-override`, `prebuilt`, `stub`). pub gpu_link: String, - /// sha256 of the linked `libomega_gpu.a`. + /// sha256 of the linked canonical `libcudapp.a`. pub gpu_archive_sha256: String, - /// `locked` (the sha `native-artifacts.lock` records), `unrecorded` (no record for this - /// commit and target), `mismatch` or `none`. + /// `locked`, `unrecorded`, `mismatch` or `none` from canonical native identity. pub gpu_digest: String, pub gpu_target: String, + + /// The omega commit `omega.lock` pins. + pub omega_commit: String, + /// How companion `libomega_gpu.a` was linked (`pinned-source`, `dev-override`, `prebuilt`, `stub`). + pub companion_link: String, + /// sha256 of the linked companion `libomega_gpu.a`. + pub companion_archive_sha256: String, + /// `locked`, `unrecorded`, `mismatch` or `none` from companion native identity. + pub companion_digest: String, + pub companion_target: String, + /// This crate's commit (`build.rs`). pub sc_commit: String, /// Built from a checkout with modified tracked files (or unknown). @@ -118,53 +131,88 @@ pub struct OmegaBuild { impl OmegaBuild { /// What this binary was built from and linked. pub fn linked() -> Self { - let id = aien_omega_gpu::native_identity(); - let recorded = env!("AIEN_SERVE_HTTP_GPU_RECORDED_SHA256"); - let gpu_digest = if id.archive_sha256.is_empty() { - "none" - } else if recorded == "unrecorded" { - "unrecorded" - } else if recorded == id.archive_sha256 { - "locked" + let canonical = aien_omega_gpu::native_identity(); + let companion = aien_omega_gpu::native_companion_identity(); + let cudapp_pin = aien_omega_gpu::cudapp_pinned_sha(); + let omega_pin = aien_omega_gpu::PINNED_OMEGA_SHA; + + let gpu_link = if canonical.link == "pinned-source" && canonical.source_sha != cudapp_pin { + "pinned-source-other-commit".into() } else { - "mismatch" + canonical.link.to_string() }; - let pin = env!("AIEN_SERVE_HTTP_OMEGA_LOCK"); + + let companion_link = if companion.link == "pinned-source" && companion.source_sha != omega_pin { + "pinned-source-other-commit".into() + } else { + companion.link.to_string() + }; + Self { - omega_commit: pin.to_string(), - // A pinned-source archive built from another commit than the pin is not the pin. - gpu_link: if id.link == "pinned-source" && id.source_sha != pin { - "pinned-source-other-commit".into() - } else { - id.link.to_string() - }, - gpu_archive_sha256: id.archive_sha256.to_string(), - gpu_digest: gpu_digest.to_string(), - gpu_target: id.target.to_string(), + cudapp_commit: cudapp_pin.to_string(), + gpu_link, + gpu_archive_sha256: canonical.archive_sha256.to_string(), + gpu_digest: canonical.digest.to_string(), + gpu_target: canonical.target.to_string(), + + omega_commit: omega_pin.to_string(), + companion_link, + companion_archive_sha256: companion.archive_sha256.to_string(), + companion_digest: companion.digest.to_string(), + companion_target: companion.target.to_string(), + sc_commit: env!("AIEN_SERVE_HTTP_GIT_COMMIT").to_string(), sc_dirty: env!("AIEN_SERVE_HTTP_GIT_DIRTY") != "0", } } - /// `omega:+libomega_gpu:+sc:`. Refused when any part is unknown or + /// `v2:` computed via domain-separated SHA-256 (`AIEN-PKV-OMEGA-BUILD-V2`) + /// over length-framed field values: canonical CUDApp source commit, canonical `libcudapp.a` + /// archive sha256, canonical target, companion Omega source commit, companion `libomega_gpu.a` + /// archive sha256, companion target, and sovereign-core engine commit. + /// + /// Short and bounded (67 bytes) to satisfy the KV engine identity cap (`<= 255` bytes, + /// preventing `FieldTooLong("engine_build_id")`). Old single-archive cache entries + /// (`omega:+...`) miss. Refused when any part is unknown, dirty, unpinned, or /// cannot be trusted to name the bytes that run (fail closed). pub fn build_id(&self) -> Result { let hex = |s: &str, n: usize| s.len() == n && s.bytes().all(|b| b.is_ascii_hexdigit()); if self.gpu_link != "pinned-source" { return Err(format!( - "libomega_gpu.a is linked as {:?}, not built from the omega.lock pin", + "libcudapp.a is linked as {:?}, not built from the cudapp pin", self.gpu_link )); } if !hex(&self.gpu_archive_sha256, 64) { - return Err("the linked libomega_gpu.a has no sha256".into()); + return Err("the linked libcudapp.a has no sha256".into()); } if !matches!(self.gpu_digest.as_str(), "locked" | "unrecorded") { return Err(format!( - "libomega_gpu.a digest is {:?} against native-artifacts.lock", + "libcudapp.a digest is {:?} against native-artifacts.lock", self.gpu_digest )); } + if !hex(&self.cudapp_commit, 40) { + return Err(format!( + "cudapp pin commit {:?} is not a 40-hex commit", + self.cudapp_commit + )); + } + if self.companion_link != "pinned-source" { + return Err(format!( + "libomega_gpu.a is linked as {:?}, not built from the omega pin", + self.companion_link + )); + } + if !hex(&self.companion_archive_sha256, 64) { + return Err("the linked libomega_gpu.a has no sha256".into()); + } + if !matches!(self.companion_digest.as_str(), "locked" | "unrecorded") { + return Err(format!( + "libomega_gpu.a digest is {:?} against native-artifacts.lock", + self.companion_digest + )); + } if !hex(&self.omega_commit, 40) { return Err(format!( "omega.lock commit {:?} is not a 40-hex commit", @@ -184,13 +232,42 @@ impl OmegaBuild { return Err("the binary was built from a checkout with uncommitted changes".into()); } if self.gpu_target.is_empty() { + return Err("the linked libcudapp.a has no target".into()); + } + if self.companion_target.is_empty() { return Err("the linked libomega_gpu.a has no target".into()); } - Ok(format!( - "omega:{}+libomega_gpu:{}+sc:{}", - self.omega_commit, self.gpu_archive_sha256, self.sc_commit - )) + let mut h = Sha256::new(); + h.update(OMEGA_BUILD_DOMAIN_V2); + for field in [ + &self.cudapp_commit, + &self.gpu_archive_sha256, + &self.gpu_target, + &self.omega_commit, + &self.companion_archive_sha256, + &self.companion_target, + &self.sc_commit, + ] { + let len = u32::try_from(field.len()).map_err(|_| "field length overflow")?; + h.update(len.to_le_bytes()); + h.update(field.as_bytes()); + } + let digest = h.finalize(); + let mut hex_str = String::with_capacity(digest.len() * 2); + for b in digest { + use std::fmt::Write; + let _ = write!(&mut hex_str, "{b:02x}"); + } + let id = format!("v2:{hex_str}"); + if id.len() > 255 { + return Err(format!( + "engine_build_id length {} exceeds 255-byte limit", + id.len() + )); + } + Ok(id) } + } /// Everything the omega engine identity is built from. @@ -1366,11 +1443,16 @@ mod tests { fn build() -> OmegaBuild { OmegaBuild { - omega_commit: "d0889a944b02066f84fec71af7b9bbb92f5c986f".into(), + cudapp_commit: "1a".repeat(20), gpu_link: "pinned-source".into(), gpu_archive_sha256: "ab".repeat(32), gpu_digest: "unrecorded".into(), gpu_target: "aarch64-unknown-linux-gnu".into(), + omega_commit: "d0889a944b02066f84fec71af7b9bbb92f5c986f".into(), + companion_link: "pinned-source".into(), + companion_archive_sha256: "cd".repeat(32), + companion_digest: "unrecorded".into(), + companion_target: "aarch64-unknown-linux-gnu".into(), sc_commit: "cd".repeat(20), sc_dirty: false, } @@ -1494,13 +1576,20 @@ mod tests { ("decode graph", |i| i.switches.decode_graph ^= true), ("lm head gemv", |i| i.switches.lm_head_gemv ^= true), ("trace layers", |i| i.switches.trace_layers ^= true), - ("omega commit", |i| i.build.omega_commit = "e".repeat(40)), - ("archive digest", |i| { + ("cudapp commit", |i| i.build.cudapp_commit = "e".repeat(40)), + ("cudapp archive digest", |i| { i.build.gpu_archive_sha256 = "ef".repeat(32) }), - ("gpu target", |i| { + ("cudapp target", |i| { i.build.gpu_target = "x86_64-unknown-linux-gnu".into() }), + ("omega commit", |i| i.build.omega_commit = "e".repeat(40)), + ("companion archive digest", |i| { + i.build.companion_archive_sha256 = "fe".repeat(32) + }), + ("companion target", |i| { + i.build.companion_target = "x86_64-unknown-linux-gnu".into() + }), ("engine commit", |i| i.build.sc_commit = "ab".repeat(20)), ("env cta budget", |i| { i.env.push(("AIEN_OMEGA_CTA_BUDGET".into(), "4".into())) @@ -1547,15 +1636,33 @@ mod tests { fn untrusted_builds_and_negative_controls_refuse() { type Change = (&'static str, fn(&mut In)); let refusals: &[Change] = &[ - ("stub link", |i| i.build.gpu_link = "stub".into()), - ("dev override", |i| i.build.gpu_link = "dev-override".into()), - ("other commit", |i| { + ("cudapp stub link", |i| i.build.gpu_link = "stub".into()), + ("cudapp dev override", |i| i.build.gpu_link = "dev-override".into()), + ("cudapp other commit", |i| { i.build.gpu_link = "pinned-source-other-commit".into() }), - ("no archive sha", |i| i.build.gpu_archive_sha256.clear()), - ("digest mismatch", |i| { + ("cudapp no archive sha", |i| i.build.gpu_archive_sha256.clear()), + ("cudapp digest mismatch", |i| { i.build.gpu_digest = "mismatch".into() }), + ("cudapp digest none", |i| { + i.build.gpu_digest = "none".into() + }), + ("unknown cudapp commit", |i| { + i.build.cudapp_commit = "unknown".into() + }), + ("companion stub link", |i| i.build.companion_link = "stub".into()), + ("companion dev override", |i| i.build.companion_link = "dev-override".into()), + ("companion other commit", |i| { + i.build.companion_link = "pinned-source-other-commit".into() + }), + ("companion no archive sha", |i| i.build.companion_archive_sha256.clear()), + ("companion digest mismatch", |i| { + i.build.companion_digest = "mismatch".into() + }), + ("companion digest none", |i| { + i.build.companion_digest = "none".into() + }), ("unknown omega commit", |i| { i.build.omega_commit = "unknown".into() }), @@ -1606,4 +1713,79 @@ mod tests { ); assert!(HostFsConfig::from_fields(PathBuf::from("/nonexistent"), &f).is_ok()); } + + #[test] + fn old_cache_identity_and_independent_archive_or_source_changes() { + let b = build(); + let valid_id = b.build_id().unwrap(); + + // 1. Explicit bounded length regression: engine_build_id must fit within u8 len prefix (<= 255 bytes). + assert_eq!(valid_id.len(), 67); + assert!(valid_id.len() <= 255); + assert!(u8::try_from(valid_id.len()).is_ok()); + + // 2. Old single-archive cache identity must never silently match new two-archive pair. + let old_format = format!( + "omega:{}+libomega_gpu:{}+sc:{}", + b.omega_commit, b.companion_archive_sha256, b.sc_commit + ); + assert_ne!(valid_id, old_format); + assert!(!valid_id.starts_with("omega:")); + assert!(!valid_id.starts_with("cudapp:")); + assert!(valid_id.starts_with("v2:")); + + // 3. Changing canonical CUDApp source changes build_id. + let mut b_cudapp_src = b.clone(); + b_cudapp_src.cudapp_commit = "4f".repeat(20); + assert_ne!(valid_id, b_cudapp_src.build_id().unwrap()); + + // 4. Changing canonical CUDApp archive changes build_id. + let mut b_cudapp_arch = b.clone(); + b_cudapp_arch.gpu_archive_sha256 = "55".repeat(32); + assert_ne!(valid_id, b_cudapp_arch.build_id().unwrap()); + + // 5. Changing canonical CUDApp target changes build_id. + let mut b_cudapp_tgt = b.clone(); + b_cudapp_tgt.gpu_target = "x86_64-unknown-linux-gnu".into(); + assert_ne!(valid_id, b_cudapp_tgt.build_id().unwrap()); + + // 6. Changing Omega source changes build_id. + let mut b_omega_src = b.clone(); + b_omega_src.omega_commit = "6a".repeat(20); + assert_ne!(valid_id, b_omega_src.build_id().unwrap()); + + // 7. Changing companion Omega archive changes build_id. + let mut b_omega_arch = b.clone(); + b_omega_arch.companion_archive_sha256 = "77".repeat(32); + assert_ne!(valid_id, b_omega_arch.build_id().unwrap()); + + // 8. Changing companion Omega target changes build_id. + let mut b_omega_tgt = b.clone(); + b_omega_tgt.companion_target = "x86_64-unknown-linux-gnu".into(); + assert_ne!(valid_id, b_omega_tgt.build_id().unwrap()); + + // 9. Changing engine commit changes build_id. + let mut b_sc_commit = b.clone(); + b_sc_commit.sc_commit = "88".repeat(20); + assert_ne!(valid_id, b_sc_commit.build_id().unwrap()); + + // 10. Development unrecorded digests succeed, but mismatch or none refuse. + let mut b_dev = b.clone(); + b_dev.gpu_digest = "unrecorded".into(); + b_dev.companion_digest = "unrecorded".into(); + assert!(b_dev.build_id().is_ok()); + + let mut b_locked = b.clone(); + b_locked.gpu_digest = "locked".into(); + b_locked.companion_digest = "locked".into(); + assert!(b_locked.build_id().is_ok()); + + let mut b_bad_can = b.clone(); + b_bad_can.gpu_digest = "mismatch".into(); + assert!(b_bad_can.build_id().is_err()); + + let mut b_bad_comp = b.clone(); + b_bad_comp.companion_digest = "mismatch".into(); + assert!(b_bad_comp.build_id().is_err()); + } } diff --git a/crates/aien-serve-http/tests/kv_persist.rs b/crates/aien-serve-http/tests/kv_persist.rs index 45a10f9f..a884ade2 100644 --- a/crates/aien-serve-http/tests/kv_persist.rs +++ b/crates/aien-serve-http/tests/kv_persist.rs @@ -65,11 +65,16 @@ fn gen_key() -> String { fn test_build() -> OmegaBuild { OmegaBuild { - omega_commit: "d0889a944b02066f84fec71af7b9bbb92f5c986f".into(), + cudapp_commit: "3a".repeat(20), gpu_link: "pinned-source".into(), gpu_archive_sha256: "11".repeat(32), gpu_digest: "unrecorded".into(), gpu_target: "aarch64-unknown-linux-gnu".into(), + omega_commit: "d0889a944b02066f84fec71af7b9bbb92f5c986f".into(), + companion_link: "pinned-source".into(), + companion_archive_sha256: "55".repeat(32), + companion_digest: "unrecorded".into(), + companion_target: "aarch64-unknown-linux-gnu".into(), sc_commit: "22".repeat(20), sc_dirty: false, } @@ -306,11 +311,17 @@ fn each_identity_input_changed_alone_is_never_served() { v.weights = WeightFormat::Bf16; variants.push(("weights bf16", v)); let mut v = base.clone(); + v.build.cudapp_commit = "c".repeat(40); + variants.push(("cudapp commit", v)); + let mut v = base.clone(); + v.build.gpu_archive_sha256 = "33".repeat(32); + variants.push(("cudapp archive digest", v)); + let mut v = base.clone(); v.build.omega_commit = "e".repeat(40); variants.push(("omega commit", v)); let mut v = base.clone(); - v.build.gpu_archive_sha256 = "33".repeat(32); - variants.push(("gpu archive digest", v)); + v.build.companion_archive_sha256 = "77".repeat(32); + variants.push(("companion archive digest", v)); let mut v = base.clone(); v.build.sc_commit = "44".repeat(20); variants.push(("engine commit", v)); @@ -346,6 +357,66 @@ fn each_identity_input_changed_alone_is_never_served() { assert_eq!(counters(&b).restores, 1); } +#[test] +fn either_source_or_archive_change_invalidates_cache_and_old_cache_is_not_served() { + let scratch = Scratch::new("source-archive-invalidation"); + let key = gen_key(); + let base = Setup::new(&scratch.store(), &key); + let (_, h1) = park_turn1(&scratch, &base); + + let mut controls: Vec<(&str, Setup)> = Vec::new(); + + // 1. CUDApp source change + let mut v = base.clone(); + v.build.cudapp_commit = "f0".repeat(20); + controls.push(("cudapp source change", v)); + + // 2. Canonical libcudapp.a archive digest change + let mut v = base.clone(); + v.build.gpu_archive_sha256 = "88".repeat(32); + controls.push(("libcudapp archive digest change", v)); + + // 3. Omega source change + let mut v = base.clone(); + v.build.omega_commit = "e1".repeat(20); + controls.push(("omega source change", v)); + + // 4. Companion libomega_gpu.a archive digest change + let mut v = base.clone(); + v.build.companion_archive_sha256 = "99".repeat(32); + controls.push(("libomega_gpu companion archive digest change", v)); + + for (what, v) in controls { + let (b, line) = door(&scratch, &v); + assert!(line.contains("persistent KV: on"), "{what}: {line}"); + let _ = turn(&b, &prompt2(&h1)); + let c = counters(&b); + assert_eq!( + c.restores, 0, + "{what}: parked prefix was served despite invalidation: {c:?}" + ); + assert!( + c.restore_misses.get("not-found").copied().unwrap_or(0) >= 1, + "{what}: expected restore miss: {c:?}" + ); + } + + // Baseline still restores successfully + let (b, _) = door(&scratch, &base); + let _ = turn(&b, &prompt2(&h1)); + assert_eq!(counters(&b).restores, 1); +} + +#[test] +fn engine_build_id_is_bounded_and_short() { + let b = test_build(); + let id = b.build_id().unwrap(); + assert_eq!(id.len(), 67); + assert!(id.len() <= 255); + assert!(u8::try_from(id.len()).is_ok()); + assert!(id.starts_with("v2:")); +} + #[test] fn unknown_omega_switches_and_the_mutants_refuse_persistence() { let scratch = Scratch::new("mutant"); diff --git a/docs/abi-qualification/INVENTORY.md b/docs/abi-qualification/INVENTORY.md index 1697d20c..55ff7639 100644 --- a/docs/abi-qualification/INVENTORY.md +++ b/docs/abi-qualification/INVENTORY.md @@ -12,7 +12,7 @@ sovereign-core main `bd438bcc`. Tags: **implemented** (true before this work), * | Boundary | Producer | Consumer | Linked into production | |---|---|---|---| | rxc_host v2 (composition facade) | om `src/runtime/rxc_host_abi.h`, `.c`; archive `librx_compose.a` (`mk/rx_compose_lib.mk`) | sc `crates/aien-omega-compose` | yes (aien-runtime, aien-cli) | -| omega GPU engine | om `src/omega_gpu_{matmul_api,session,serving,elementwise_api,attention_api}.h`; `libomega_gpu.a` | sc `crates/aien-omega-gpu`, used by `aien-inference-abi` | yes on the GB10 build | +| canonical GPU engine (CUDApp) + CPU companion | CUDApp `libcudapp.a` (canonical GPU ABI) + om `libomega_gpu.a` (CPU companion) | sc `crates/aien-omega-gpu`, used by `aien-inference-abi` | yes on native build | | AIENOS capability authority (C, 64-bit generation) | ao `native/capability/aienos_capability.h` | om `src/runtime/aienos_cap.h` (hand copy), merged into `librx_compose.a` | yes, through librx_compose.a | | AIENOS capability (Rust, 32-bit generation) | ao `crates/aienos-capability-ffi` | nothing in sc, om or ao links it (grep, 2026-10-11) | no | @@ -87,8 +87,44 @@ Covered by tests: compatible pinned build, version mismatch, equal-size reorder, change, wrong prebuilt hash, wrong omega commit, missing symbol, truncated archive, callback failure and panic, invalid lengths and overflow, repeated init/destroy, concurrent callbacks, explicit stub, required-native with no library (`scripts/test-native-identity.sh`, -16 cases, in the required CI job), CPU vs GPU path identity (`native_identity()`), GPU -parity (existing chip suites, run by `scripts/abi-qualify.sh --chip`). +16 cases, in the required CI job), two-archive canonical identity and companion admission +(`native_identity()` for libcudapp.a, `native_companion_identity()` for libomega_gpu.a, and +`native_pair_qualifies()`). + +Host-only canonical amendment (2026-10-28; the dated inventory above is historical): + +- The exercised canonical source is CUDApp #169 + `7a354dbda9eddd405610fdcabf4fc4e24c1a0f47`; the Omega consumer source is + `cafb7be08e4a92d6dd7347b011a833f524140dee` (draft #924). + CUDApp #173 `ca441c5a92f5a951a67de00aeddae0e077f10216` has separate host repair + evidence, not a merged combined candidate. User-owned #174 remains pending; + the final combined 35B candidate is `NOT_FROZEN`. +- Canonical `libcudapp.a` owns the GPU ABI result. The independently locked Omega + CPU/evidence companion has ABI `none`; both pinned source identities and both recorded + archive digests are required for the pair. A companion defining a manifested GPU + symbol is refused. GPU prebuilt overrides are no longer accepted; the historical + prebuilt tests above describe composition-only development support. +- The source checker is authenticated before execution through the pinned commit, + root tree, tools tree and blob. Corrupt-object controls must refuse before a poisoned + checker marker can be written. Canonical-only C layout and symbol checks precede + private archive snapshotting; optional caller capabilities inspect the same admitted + archive instead of obsolete Omega-local headers. +- `native-artifacts.lock` now keys each archive by its own component source revision, + target and exact compiler version. The new host records came from the observed + unrecorded negative run, then the recorded pair passed host qualification. A stage's + mutable checksum files are consistency evidence, not an independent expected digest. +- Persistent KV identity is a versioned SHA-256 over length-framed canonical source, + canonical archive, canonical target, companion source, companion archive, companion + target and clean Core commit. This keeps the existing bounded format and makes old + single-archive caches miss. +- Host commands and tool prerequisites are in + [`BUILD_RECIPE.md`](../release/BUILD_RECIPE.md#canonical-native-admission-and-host-rehearsal). + The caller checks inspect native capabilities and exercise tiny real host inference, + loopback and persistent-cache refusal/recovery. They do not execute the physical 35B + workload. No GPU qualification was executed; production resolver NULL/count 0 and + the resident service remain unchanged. NVIDIA RM/UVM kernel-driver/device-interface + dependence persists; firmware is a separate dependency, not a driver-removal claim. + Entry point: `scripts/abi-qualify.sh [--chip]`, exit 0 PASS, 1 FAIL, 2 INCOMPLETE. Registered in the local verification gates (ADR 0033): `tests/gates/sc-native-identity.gate` (step `native-identity` in `tests/gates/run.sh`), and `native-artifacts.lock` is an input of diff --git a/docs/release/BUILD_RECIPE.md b/docs/release/BUILD_RECIPE.md index 918f4dd2..bdf63e78 100644 --- a/docs/release/BUILD_RECIPE.md +++ b/docs/release/BUILD_RECIPE.md @@ -5,17 +5,74 @@ checks all use the same commands. ## Build -One command materializes every pin a native build needs (sovereign-core #92, "clean checkout plus one command"): +Materialize every source pin a native build needs (sovereign-core #92, "clean checkout plus one command"): +```bash +scripts/pins.sh --gpu # omega, physics, aienos, canonical CUDApp and its unit bridge, under target/pins +. target/pins/env.sh ``` -scripts/pins.sh --gpu # omega at omega.lock, physics and aienos at omega's locks, under target/pins -. target/pins/env.sh # AIEN_OMEGA_DIR, AIEN_OMEGA_COMPOSE_DIR, AIEN_PHYSICS_DIR, AIEN_AIENOS_LOCK_REPO, AIEN_REQUIRE_NATIVE_LIBS=1 + +The seeded `OMEGA_OMC` executable must have SHA-256 +`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`. +Set `OMEGA_OMC` to that verified executable before `pins.sh`; otherwise source materialization +can finish but the script explicitly reports the missing compiler prerequisite. It does not +bootstrap an unchecked working-tree script or silently choose another host compiler. +The bridge comes from CUDApp's `om/omega-bridge.lock`, not Omega's separate CPU-unit bridge lock. +`env.sh` exports the component directories, available verified stage tools and +`AIEN_REQUIRE_NATIVE_LIBS=1`. + +Without `--gpu` only the composition library is linked (the CI gate shape). +`scripts/pins.sh --gpu --check` verifies the GPU source pins without touching the network; +omit `--gpu` for composition-only checks. Required-native builds fail instead of quietly +using a stub. `scripts/golden_path.sh` sources `target/pins/env.sh` when present. +`scripts/test-pins.sh` is the offline self-test (throwaway repositories, no network). + +### Canonical native admission and host rehearsal + +The actual GPU ABI, headers and symbols belong to pinned CUDApp `libcudapp.a`. +Omega `libomega_gpu.a` is a separately locked CPU/evidence companion, linked first; +the canonical archive is linked last. Its ABI result is `none`, not a fabricated GPU +layout pass. A companion exporting any manifested GPU entry is refused. Both source +identities and both archive digests must match their independent `native-artifacts.lock` +records before the pair qualifies. GPU prebuilt overrides are refused, including with +stub mode; composition-only prebuilt development support remains nonqualifying. + +The GPU builder authenticates the pinned commit, root tree, `tools` tree and source-checker +blob before executing a private snapshot of that checker. Corrupt object substitutions +are refused before the checker can run. The checker materializes the pinned Omega source, +the canonical CUDApp stage verifies its pinned source, and C layout/symbol checks use only +that canonical stage's headers. The admitted archives are copied into a private link +snapshot and rehashed against the admitted digests. Optional Q36, FP8, MoE, prefill and +other APIs derive their availability from symbols in that same admitted archive, not +retired Omega-local headers. Nothing here opens a GPU. + +After sourcing the pinned environment, the host-only acceptance commands are: + +```bash +bash scripts/abi-qualify.sh --out /absolute/path/to/new-host-evidence-directory +cargo test --locked --offline -p aien-inference-abi --test omega_backend_parity +cargo test --locked --offline -p aien-serve-http --lib --test loopback --test kv_persist -- --test-threads=1 ``` -Without `--gpu` only the composition library is linked (the CI gate shape). `scripts/pins.sh --check` verifies the -three checkouts are at their pins without touching the network. `AIEN_REQUIRE_NATIVE_LIBS=1` makes a build that -would silently fall back to a CPU stub fail instead; `scripts/golden_path.sh` sources `target/pins/env.sh` when -present. `scripts/test-pins.sh` is the offline self-test (throwaway repositories, no network). +Do not add `--chip`, `--ignored`, or a real model directory to this host rehearsal. +Loopback uses the existing tiny host test engine, real host numerical operations and an +ephemeral listener; it does not launch the resident 35B workload. Persistence binds both +sources, both archive digests, both targets and the clean engine commit in a length-framed, +domain-separated `v2:` SHA-256 identity. The bounded identifier preserves the existing KV +format limit; old single-archive identities cannot hit the new namespace. + +This rehearsal still uses the reviewed CUDApp #169 source. The separately verified #173 +repair is not a merged combined candidate, and user-owned #174 is pending. Keep the guide +and integration PRs draft and the final 35B candidate `NOT_FROZEN` until the accepted +combined source is supplied and the exact artifacts are rebuilt and independently locked. +No physical 35B correctness, memory, speed, reliability, recovery or neighbor-effect +qualification follows from these host tests. That path remains `NOT_RUN` without a current +operator-authorized GPU window; production resolver defaults remain NULL/count 0. + +The present native path still depends on NVIDIA kernel-driver RM/UVM device interfaces, +ioctls, mappings and channels, and the pinned NVIDIA 580.173.02 interface headers. +Firmware dependence is a separate migration obligation. This is neither a kernel-driver +replacement nor a blanket CUDA-free/drop-in compatibility claim. `scripts/release-build.sh` (needs the pinned toolchain from `rust-toolchain.toml`, `cargo fetch --locked` into the CARGO_HOME in use, and for the native engine `AIEN_OMEGA_DIR` at `omega.lock` and `AIEN_PHYSICS_DIR` at omega's diff --git a/native-artifacts.lock b/native-artifacts.lock index 0afe3927..cc3fdadf 100644 --- a/native-artifacts.lock +++ b/native-artifacts.lock @@ -1,8 +1,8 @@ -# Recorded digests of the omega archives sovereign-core links (aien-abi-conformance). -# One line per archive: -# A build from the pinned omega checkout for a listed target and compiler must produce exactly -# this digest, or build.rs fails. A combination not listed builds with a warning and its -# native_identity() reports digest "unrecorded", which does not qualify. +# Independent archive digests consumed by aien-abi-conformance. +# One line per archive: +# libcudapp.a uses the authenticated CUDApp revision; libomega_gpu.a and librx_compose.a use Omega. +# A listed source/target/compiler must match exactly. An unlisted combination is "unrecorded" +# and cannot qualify; GPU qualification requires both canonical and companion records. # Update only from a qualification run (scripts/abi-qualify.sh prints the lines to add). librx_compose.a 41f8813a25357256da9b078fe6533a0be1487b6d aarch64-unknown-linux-gnu a701a0db5e396acc1a0898d19acefcaf199556cf7f81b0c57a6b7c8402a02cc4 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a 41f8813a25357256da9b078fe6533a0be1487b6d aarch64-unknown-linux-gnu a687ffa0fe94916ac127b1a704f5df5c078cfba19f6f0132d83999cf2f7af059 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 @@ -39,3 +39,6 @@ libomega_gpu.a 7052d780ad9de52285e1c620e3eefd00ec5dc8db aarch64-unknown-linux-gn librx_compose.a 7052d780ad9de52285e1c620e3eefd00ec5dc8db aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a 1ad2dc1af70f01680fd93cb41a7a94fd0951723f aarch64-unknown-linux-gnu 63c500cec9784cf9ed6d751062f0dfcd27313e80e29b316e16f6bfc6ffc11c01 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 librx_compose.a 1ad2dc1af70f01680fd93cb41a7a94fd0951723f aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +libcudapp.a 7a354dbda9eddd405610fdcabf4fc4e24c1a0f47 aarch64-unknown-linux-gnu cf95a6a7808c1b948a459efb22b62c0093644c10c58461e816e55ef0134befa9 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +libomega_gpu.a cafb7be08e4a92d6dd7347b011a833f524140dee aarch64-unknown-linux-gnu 931d7b07620db1db7f2e91b62d04ac61e363d3ded6e94dca5b46dfbf52ee9fd5 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +librx_compose.a cafb7be08e4a92d6dd7347b011a833f524140dee aarch64-unknown-linux-gnu 0ac258c8fe2bee0fdaf6784f00213c386b46016b45704dc88eb72e1ba1c2a9a2 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 diff --git a/omega.lock b/omega.lock index bae373cf..e3beb3ee 100644 --- a/omega.lock +++ b/omega.lock @@ -1 +1 @@ -1ad2dc1af70f01680fd93cb41a7a94fd0951723f +cafb7be08e4a92d6dd7347b011a833f524140dee diff --git a/scripts/.crumb b/scripts/.crumb index 8ab3769d..be465735 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -4,14 +4,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-17T11:27:44Z", + "compiled_at": "2026-10-28T19:53:33Z", "compiler": "crumb-compile/1", - "digest": "sha256:34b010337138a65931ca4d0177631d839f71af021c5092583f52afd69ddd1b72", + "digest": "sha256:b811ed841b3b36b0be3661290b8adfc1f5ea65710d6dd19d5ce2d0885af9cfcc", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 53, - "generated_at_commit": "fe3677c38c6cd8219db0959d954c8d83e1c8a52c", - "source_tree": "sha256:09dbafbfb7f2503e6def8005c3bee8fe9dbc7d4e2b1f9831ff76d40d02f02097" + "generated_at_commit": "aaab111c93168702da7db22e98555bb656c9bb28", + "source_tree": "sha256:056f61b86750379597ac81850687d8b613d951f5b0064b83acf999865cfd8029" } }, "parent": { diff --git a/scripts/abi-qualify.sh b/scripts/abi-qualify.sh index aa50e5cb..62e04c49 100755 --- a/scripts/abi-qualify.sh +++ b/scripts/abi-qualify.sh @@ -13,8 +13,9 @@ # omega_backend_parity and the crate's linked tests), under the GPU lease # The build scripts check the C headers, a compiled layout probe and the archive symbols against # the checked-in ABI manifests and the archive digests against native-artifacts.lock, and the -# identity tests run with AIEN_ABI_QUALIFY=1, so each linked library must report -# pinned-source + abi pass + digest locked. +# identity tests run with AIEN_ABI_QUALIFY=1: canonical CUDApp and compose must report +# pinned-source + abi pass + digest locked, companion libomega_gpu.a reports pinned-source + +# abi none + digest locked, and native_pair_qualifies must be true. # # Usage: scripts/abi-qualify.sh [--chip] [--pins DIR] [--out DIR] # --pins DIR pinned checkouts (default target/pins), materialized by scripts/pins.sh --gpu @@ -84,17 +85,37 @@ if [ "${AIEN_REQUIRE_NATIVE_LIBS:-}" = "1" ]; then step gpu-host cargo test -p aien-omega-gpu -- --test-threads=1 --nocapture fi -# 2. What was linked: one identity line per native library, each must qualify. +# 2. What was linked: canonical CUDApp qualifies, companion is admitted (abi none, digest locked), pair qualifies. IDS=$(cat "$OUT"/compose.log "$OUT"/gpu-host.log 2>/dev/null | sed -n 's/.*AIEN_NATIVE_IDENTITY \({.*}\).*/\1/p' | sort -u) -for c in librx_compose.a libomega_gpu.a; do - if printf '%s\n' "$IDS" | grep -F "\"component\":\"$c\"" | grep -qF '"qualifies":true'; then - record "identity-$c" pass "" - elif [ "${AIEN_REQUIRE_NATIVE_LIBS:-}" = "1" ]; then - record "identity-$c" fail "no qualifying identity reported" - else - record "identity-$c" incomplete "not built" - fi -done +PAIR_OK=$(cat "$OUT"/gpu-host.log 2>/dev/null | sed -n 's/.*AIEN_NATIVE_PAIR_QUALIFIES \(true\|false\).*/\1/p' | tail -1) +if printf '%s\n' "$IDS" | grep -F '"component":"librx_compose.a"' | grep -qF '"qualifies":true'; then + record "identity-librx_compose.a" pass "" +elif [ "${AIEN_REQUIRE_NATIVE_LIBS:-}" = "1" ]; then + record "identity-librx_compose.a" fail "no qualifying compose identity reported" +else + record "identity-librx_compose.a" incomplete "not built" +fi +if printf '%s\n' "$IDS" | grep -F '"component":"libcudapp.a"' | grep -qF '"qualifies":true'; then + record "identity-libcudapp.a" pass "" +elif [ "${AIEN_REQUIRE_NATIVE_LIBS:-}" = "1" ]; then + record "identity-libcudapp.a" fail "no qualifying canonical CUDApp identity reported" +else + record "identity-libcudapp.a" incomplete "not built" +fi +if printf '%s\n' "$IDS" | grep -F '"component":"libomega_gpu.a"' | grep -F '"link":"pinned-source"' | grep -F '"abi":"none"' | grep -qF '"digest":"locked"'; then + record "identity-libomega_gpu.a" pass "" +elif [ "${AIEN_REQUIRE_NATIVE_LIBS:-}" = "1" ]; then + record "identity-libomega_gpu.a" fail "companion not admitted: requires pinned-source, abi none, and locked digest" +else + record "identity-libomega_gpu.a" incomplete "not built" +fi +if [ "$PAIR_OK" = "true" ]; then + record "identity-pair" pass "" +elif [ "${AIEN_REQUIRE_NATIVE_LIBS:-}" = "1" ]; then + record "identity-pair" fail "native_pair_qualifies returned false or missing" +else + record "identity-pair" incomplete "not built" +fi # 3. GB10 chip tests, only on request, only when the machine is free. if [ "$CHIP" = 1 ] && [ "$fails" -eq 0 ] && [ "$incomplete" -eq 0 ]; then @@ -140,8 +161,10 @@ dirty=false printf '"rustc":"%s",\n"cc":"%s",\n"nm":"%s",\n' "$(j "$(rustc -V)")" "$(j "$(${CC:-cc} --version | head -1)")" "$(j "$(nm --version | head -1)")" printf '"flags":{"RUSTFLAGS":"%s","CFLAGS":"%s","CC":"%s","AIEN_REQUIRE_NATIVE_LIBS":"%s"},\n' \ "$(j "${RUSTFLAGS:-}")" "$(j "${CFLAGS:-}")" "$(j "${CC:-cc}")" "${AIEN_REQUIRE_NATIVE_LIBS:-}" - printf '"commits":{"sovereign_core":"%s","sovereign_core_dirty":%s,"omega_lock":"%s","omega":"%s","physics":"%s","aienos":"%s"},\n' \ - "$(rev "$ROOT")" "$dirty" "$(tr -d '[:space:]' /dev/null || true; DIR="$(cd "$DIR" 2>/dev/null && pwd || echo "$DIR")" die() { echo "pins.sh: $*" >&2; exit 3; } -sha_of() { tr -d '[:space:]' < "$1"; } +sha_of() { + local line value="" + while IFS= read -r line || [ -n "$line" ]; do + line="$(printf '%s' "$line" | tr -d '[:space:]')" + case "$line" in ''|'#'*) continue ;; esac + [ -z "$value" ] || die "multiple source revisions in $1" + value="$line" + done < "$1" + printf '%s' "$value" +} is_sha() { [[ "$1" =~ ^[0-9a-f]{40}$ ]]; } head_of() { git -C "$1" rev-parse HEAD 2>/dev/null || true; } # place NAME SHA: make DIR/NAME a clone at SHA (detached), fetching only when needed. place() { - local name="$1" sha="$2" + local name="$1" sha="$2" repo="${3:-$1}" local d="$DIR/$name" is_sha "$sha" || die "$name pin is not a full 40-hex sha: '$sha'" if [ "$(head_of "$d")" = "$sha" ]; then echo "pins: $name at $sha (present)"; return 0; fi @@ -46,10 +57,10 @@ place() { mkdir -p "$DIR" if [ ! -d "$d/.git" ]; then echo "pins: cloning $name from $BASE" - git clone -q "$BASE/$name" "$d" || { echo "pins.sh: clone of $name failed" >&2; exit 4; } + git clone -q "$BASE/$name" "$d" 2>/dev/null || git clone -q "$BASE/$repo" "$d" || { echo "pins.sh: clone of $name failed" >&2; exit 4; } fi if ! git -C "$d" cat-file -e "$sha^{commit}" 2>/dev/null; then - git -C "$d" fetch -q origin "$sha" || git -C "$d" fetch -q origin || { echo "pins.sh: fetch of $name failed" >&2; exit 4; } + git -C "$d" fetch -q origin "$sha" 2>/dev/null || git -C "$d" fetch -q origin || { echo "pins.sh: fetch of $name failed" >&2; exit 4; } fi git -C "$d" checkout -q --detach "$sha" || { echo "pins.sh: checkout of $name@$sha failed" >&2; exit 4; } [ "$(head_of "$d")" = "$sha" ] || die "$name HEAD is not $sha after checkout" @@ -61,13 +72,42 @@ place omega "$(sha_of "$ROOT/omega.lock")" [ -f "$DIR/omega/aienos.lock" ] || die "omega checkout has no aienos.lock" place physics "$(sha_of "$DIR/omega/physics.lock")" place aienos "$(sha_of "$DIR/omega/aienos.lock")" +OMC_BIN="" +BRIDGE_DIR="" +if [ "$GPU" -eq 1 ]; then + [ -f "$DIR/omega/cudapp.lock" ] || die "omega checkout has no cudapp.lock" + place cudapp "$(sha_of "$DIR/omega/cudapp.lock")" CUDApp + OMC_PIN="2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f" + if [ -n "${OMEGA_OMC:-}" ]; then + [ -f "$OMEGA_OMC" ] || die "OMEGA_OMC not found: $OMEGA_OMC" + [ "$(sha256sum < "$OMEGA_OMC" | cut -c1-64)" = "$OMC_PIN" ] || die "OMEGA_OMC is not the pinned compiler ($OMC_PIN)" + OMC_BIN="$OMEGA_OMC" + elif [ -f "$DIR/omega/seed/out/omc" ] && [ "$(sha256sum < "$DIR/omega/seed/out/omc" | cut -c1-64)" = "$OMC_PIN" ]; then + OMC_BIN="$DIR/omega/seed/out/omc" + else + echo "pins: source pins ready; set OMEGA_OMC to the seeded compiler with SHA-256 $OMC_PIN before building" >&2 + fi + if [ -f "$DIR/cudapp/om/omega-bridge.lock" ]; then + place omega-bridge "$(sha_of "$DIR/cudapp/om/omega-bridge.lock")" + BRIDGE_DIR="$DIR/omega-bridge" + elif [ -n "${OMEGA_BRIDGE:-}" ]; then + die "OMEGA_BRIDGE has no authenticated om/omega-bridge.lock in the pinned CUDApp source" + fi +fi if [ "$CHECK" -eq 0 ]; then { echo "# written by scripts/pins.sh; source it before cargo build/test" echo "export AIEN_OMEGA_COMPOSE_DIR='$DIR/omega'" echo "export AIEN_PHYSICS_DIR='$DIR/physics'" echo "export AIEN_AIENOS_LOCK_REPO='$DIR/aienos'" - if [ "$GPU" -eq 1 ]; then echo "export AIEN_OMEGA_DIR='$DIR/omega'"; else echo "unset AIEN_OMEGA_DIR"; fi + if [ "$GPU" -eq 1 ]; then + echo "export AIEN_OMEGA_DIR='$DIR/omega'" + echo "export AIEN_CUDAPP_DIR='$DIR/cudapp'" + [ -n "$OMC_BIN" ] && echo "export OMEGA_OMC='$OMC_BIN'" + [ -n "$BRIDGE_DIR" ] && echo "export OMEGA_BRIDGE='$BRIDGE_DIR'" + else + echo "unset AIEN_OMEGA_DIR AIEN_CUDAPP_DIR" + fi echo "unset AIEN_OMEGA_GPU_LIB AIEN_OMEGA_COMPOSE_LIB AIEN_OMEGA_COMPOSE_SHA AIEN_FORCE_CPU_STUB AIEN_DEV_FALLBACK" echo "export AIEN_REQUIRE_NATIVE_LIBS=1" } > "$DIR/env.sh" diff --git a/scripts/test-native-identity.sh b/scripts/test-native-identity.sh index be8b24ea..da85749e 100755 --- a/scripts/test-native-identity.sh +++ b/scripts/test-native-identity.sh @@ -13,7 +13,13 @@ ROOT=$(cd "$(dirname "$0")/.." && pwd) WORK=$(mktemp -d) trap 'rm -rf "$WORK"' EXIT export CARGO_TARGET_DIR="${AIEN_IDENTITY_TARGET_DIR:-$ROOT/target/native-identity}" +STAGE_INPUT="${AIEN_CANONICAL_STAGE:-}" +OMEGA_INPUT="${AIEN_OMEGA_DIR:-}" +OMC_INPUT="${OMEGA_OMC:-}" +BRIDGE_INPUT="${OMEGA_BRIDGE:-}" for v in $(env | sed -n 's/^\(AIEN_[A-Z0-9_]*\)=.*/\1/p'); do unset "$v"; done +HOST_TARGET=$(rustc -vV | sed -n 's/^host: //p') +[ -n "$HOST_TARGET" ] || { echo "cannot determine rustc host target" >&2; exit 1; } fails=0 pass() { echo "ok $1"; } @@ -86,9 +92,309 @@ check_crate() { cd "$ROOT" check_crate aien-omega-compose crates/aien-omega-compose/abi/rxc_host_abi.manifest \ AIEN_OMEGA_COMPOSE_LIB AIEN_OMEGA_COMPOSE_DIR rxc_host_recover AIEN_OMEGA_COMPOSE -check_crate aien-omega-gpu crates/aien-omega-gpu/abi/omega_gpu.manifest \ - AIEN_OMEGA_GPU_LIB AIEN_OMEGA_DIR omega_gpu_matmul_f32 AIEN_OMEGA_GPU +check_gpu() { + local crate=aien-omega-gpu + local fake="$WORK/$crate-fake.a" + touch "$fake" + expect_refused "$crate" "obsolete prebuilt override refused" "AIEN_OMEGA_GPU_LIB is obsolete" \ + AIEN_OMEGA_GPU_LIB="$fake" + expect_refused "$crate" "obsolete prebuilt override refused even with stub" "AIEN_OMEGA_GPU_LIB is obsolete" \ + AIEN_FORCE_CPU_STUB=1 AIEN_OMEGA_GPU_LIB="$fake" + expect_refused "$crate" "stub with required native" "contradict each other" \ + AIEN_FORCE_CPU_STUB=1 AIEN_REQUIRE_NATIVE_LIBS=1 + expect_refused "$crate" "required native with no library" "AIEN_REQUIRE_NATIVE_LIBS=1 but" \ + AIEN_REQUIRE_NATIVE_LIBS=1 + expect_refused "$crate" "omega checkout at the wrong commit" "does not match omega.lock" \ + AIEN_OMEGA_DIR="$WRONG" + + # Two-archive negative controls via aien-abi-conformance: + local probe_dir="$WORK/native-identity-probe" + mkdir -p "$probe_dir/src" + cat <<'EOF' >"$probe_dir/Cargo.toml" +[package] +name = "native-identity-probe" +version = "0.1.0" +edition = "2021" + +[dependencies] +aien-abi-conformance = { path = "CRATES_ABI_CONFORMANCE" } +EOF + sed -i "s|CRATES_ABI_CONFORMANCE|$ROOT/crates/aien-abi-conformance|" "$probe_dir/Cargo.toml" + + cat <<'EOF' >"$probe_dir/src/main.rs" +use aien_abi_conformance::build::{qualify_built_with_includes, qualify_companion}; +use aien_abi_conformance::identity; +use std::path::PathBuf; +use std::process::Command; +fn env_or(k: &str, def: &str) -> String { + std::env::var(k).unwrap_or_else(|_| def.to_string()) +} + +fn panic_message(err: Box) -> String { + if let Some(s) = err.downcast_ref::() { + s.clone() + } else if let Some(s) = err.downcast_ref::<&str>() { + s.to_string() + } else { + String::new() + } +} + +fn main() { + let root = PathBuf::from(std::env::var("AIEN_ROOT").expect("AIEN_ROOT")); + let manifest = root.join("crates/aien-omega-gpu/abi/omega_gpu.manifest"); + let artifacts_lock = root.join("native-artifacts.lock"); + let temp = PathBuf::from(std::env::var("AIEN_WORK").expect("AIEN_WORK")); + + // Case 1: Monolithic companion shadow. + // Companion defining a GPU manifest function (e.g. omega_gpu_matmul_f32) must be rejected. + { + let shadow_dir = temp.join("shadow-companion"); + std::fs::create_dir_all(&shadow_dir).unwrap(); + let src = shadow_dir.join("shadow.c"); + std::fs::write(&src, b"int omega_gpu_matmul_f32(void) { return 0; }\n").unwrap(); + assert!(Command::new("cc").current_dir(&shadow_dir).args(["-c", "-o", "shadow.o", "shadow.c"]).status().unwrap().success()); + let archive = shadow_dir.join("libomega_gpu.a"); + let _ = std::fs::remove_file(&archive); + assert!(Command::new("ar").current_dir(&shadow_dir).args(["rcs", "libomega_gpu.a", "shadow.o"]).status().unwrap().success()); + + let res = std::panic::catch_unwind(|| { + qualify_companion("aien-omega-gpu", &manifest, &artifacts_lock, &shadow_dir, &archive, "dummy_source"); + }); + let err = res.expect_err("companion shadowing canonical GPU ABI must be rejected"); + let msg = panic_message(err); + assert!(msg.contains("companion shadows canonical GPU ABI functions"), "unexpected panic: {msg}"); + println!("ok aien-omega-gpu: companion shadowing canonical GPU ABI rejected"); + } + + // Case 2: Companion unrecorded digest. + { + let comp_dir = temp.join("unrecorded-companion"); + std::fs::create_dir_all(&comp_dir).unwrap(); + let src = comp_dir.join("comp.c"); + std::fs::write(&src, b"int omega_cpu_helper(void) { return 42; }\n").unwrap(); + assert!(Command::new("cc").current_dir(&comp_dir).args(["-c", "-o", "comp.o", "comp.c"]).status().unwrap().success()); + let archive = comp_dir.join("libomega_gpu.a"); + let _ = std::fs::remove_file(&archive); + assert!(Command::new("ar").current_dir(&comp_dir).args(["rcs", "libomega_gpu.a", "comp.o"]).status().unwrap().success()); + + let id = qualify_companion("aien-omega-gpu", &manifest, &artifacts_lock, &comp_dir, &archive, "dummy_source"); + assert_eq!(id.digest, "unrecorded"); + assert_eq!(id.abi, "none"); + println!("ok aien-omega-gpu: unrecorded companion digest is unrecorded with abi none"); + } + + // Case 3: Mandatory fixture with TARGET: positive lock passes and wrong digest triggers exact recorded mismatch. + { + let target = env_or("TARGET", ""); + let fixture_source = "1111111111111111111111111111111111111111"; + assert!(!target.is_empty(), "TARGET must not be empty"); + + let fixture_dir = temp.join("locked-fixture"); + std::fs::create_dir_all(&fixture_dir).unwrap(); + let mini_manifest = fixture_dir.join("mini.manifest"); + std::fs::write(&mini_manifest, b"abi mini 1\nheader mini.h\nstruct Mini 8 8\nfield Mini val 0 8 u64 1\nconst MINI_OK 0\nfn mini_fn fn(u64) -> i32\n").unwrap(); + let mini_h = fixture_dir.join("mini.h"); + std::fs::write(&mini_h, b"#include \n#define MINI_OK 0\ntypedef struct { uint64_t val; } Mini;\nint mini_fn(uint64_t);\n").unwrap(); + let mini_c = fixture_dir.join("mini.c"); + std::fs::write(&mini_c, b"#include \"mini.h\"\nint mini_fn(uint64_t x) { return (int)x; }\n").unwrap(); + assert!(Command::new("cc").current_dir(&fixture_dir).args(["-c", "-o", "mini.o", "mini.c"]).status().unwrap().success()); + let archive = fixture_dir.join("libmini.a"); + let _ = std::fs::remove_file(&archive); + assert!(Command::new("ar").current_dir(&fixture_dir).args(["rcs", "libmini.a", "mini.o"]).status().unwrap().success()); + + let actual_sha = identity::sha256_file(&archive).expect("sha256 of libmini.a"); + let cc = env_or("CC", "cc"); + let ccv = identity::cc_version(&cc); + + // Positive check: correct lock passes and reports locked + let good_lock = fixture_dir.join("good.lock"); + std::fs::write(&good_lock, format!("libmini.a {fixture_source} {target} {actual_sha} {ccv}\n")).unwrap(); + let good_id = qualify_built_with_includes("test-mini", &mini_manifest, &good_lock, &fixture_dir, &archive, fixture_source, true, vec![]); + assert_eq!(good_id.digest, "locked"); + assert_eq!(good_id.abi, "pass"); + + // Negative check: wrong sha in lock must panic with exact recorded sha256 mismatch wording + let wrong_lock = fixture_dir.join("wrong.lock"); + let fake_sha = "0000000000000000000000000000000000000000000000000000000000000000"; + std::fs::write(&wrong_lock, format!("libmini.a {fixture_source} {target} {fake_sha} {ccv}\n")).unwrap(); + + let res = std::panic::catch_unwind(|| { + qualify_built_with_includes("test-mini", &mini_manifest, &wrong_lock, &fixture_dir, &archive, fixture_source, true, vec![]); + }); + let err = res.expect_err("qualify_built_with_includes must panic when recorded sha256 mismatches"); + let msg = panic_message(err); + let expected_snippet = format!("has sha256 {actual_sha}, native-artifacts.lock expects {fake_sha}"); + assert!( + msg.contains(&expected_snippet), + "panic message must specify exact recorded sha256 mismatch, expected '{expected_snippet}', got: '{msg}'" + ); + println!("ok aien-omega-gpu: positive lock passes and wrong digest triggers exact recorded mismatch"); + } + + // Case 4: Optional test with REAL canonical stage when AIEN_CANONICAL_STAGE is supplied. + if let Ok(stage_str) = std::env::var("AIEN_CANONICAL_STAGE") { + if !stage_str.is_empty() { + let orig_stage = PathBuf::from(&stage_str); + assert!(orig_stage.is_dir(), "AIEN_CANONICAL_STAGE must name an existing real stage"); + let omega_source = PathBuf::from(std::env::var("AIEN_OMEGA_AUTH_DIR").unwrap_or_default()); + let cudapp_lock = if omega_source.join("cudapp.lock").is_file() { + omega_source.join("cudapp.lock") + } else { + orig_stage.join("pin") + }; + let canonical_pin = std::fs::read_to_string(&cudapp_lock) + .unwrap_or_else(|_| std::fs::read_to_string(orig_stage.join("observed")).unwrap()) + .trim() + .to_string(); + + let orig_canonical_source = orig_stage.join("source"); + let orig_archive = orig_stage.join("build/libcudapp.a"); + let includes: Vec = [ + "src", "m16", "nvrm", + "third_party/nvidia-open-580.173.02/src/common/sdk/nvidia/inc", + "third_party/nvidia-open-580.173.02/kernel-open/common/inc", + "third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm", + "third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include", + ] + .iter() + .map(|p| orig_canonical_source.join(p)) + .collect(); + + // 1. Original good real stage qualifies first + let good_id = qualify_built_with_includes( + "aien-omega-gpu", + &manifest, + &artifacts_lock, + &orig_canonical_source, + &orig_archive, + &canonical_pin, + true, + includes.clone(), + ); + assert_eq!(good_id.digest, "locked", "original real stage must have digest locked"); + assert_eq!(good_id.abi, "pass", "original real stage must have abi pass"); + println!("ok aien-omega-gpu: original good real stage qualifies"); + + // 2. Copy private stage to temp + let priv_stage = temp.join("priv-stage"); + let _ = std::fs::remove_dir_all(&priv_stage); + std::fs::create_dir_all(&priv_stage).unwrap(); + let status = Command::new("cp") + .args(["-a"]) + .arg(format!("{}/.", orig_stage.display())) + .arg(&priv_stage) + .status() + .expect("copy private stage"); + assert!(status.success(), "copy private stage failed"); + + // 3. Append unused symbol object keeping real ABI + let mut_c = priv_stage.join("extra_unused.c"); + std::fs::write(&mut_c, b"int unused_dummy_extra_symbol(void) { return 0; }\n").unwrap(); + assert!(Command::new("cc") + .current_dir(&priv_stage) + .args(["-c", "-o", "extra_unused.o", "extra_unused.c"]) + .status() + .unwrap() + .success()); + let priv_archive = priv_stage.join("build/libcudapp.a"); + assert!(Command::new("ar") + .current_dir(&priv_stage) + .args(["q", "build/libcudapp.a", "extra_unused.o"]) + .status() + .unwrap() + .success()); + + // 4. Update all 4 checksum files to private paths + let priv_source_tar = priv_stage.join("source.tar"); + let priv_pincheck = priv_stage.join("pincheck"); + let sha_source = identity::sha256_file(&priv_source_tar).expect("sha source.tar"); + let sha_guard = identity::sha256_file(&priv_pincheck).expect("sha pincheck"); + let sha_archive = identity::sha256_file(&priv_archive).expect("sha archive"); + + let line_source = format!("{sha_source} {}\n", priv_source_tar.display()); + let line_guard = format!("{sha_guard} {}\n", priv_pincheck.display()); + let line_archive = format!("{sha_archive} {}\n", priv_archive.display()); + + std::fs::write(priv_stage.join("source.sha256"), &line_source).unwrap(); + std::fs::write(priv_stage.join("guard.sha256"), &line_guard).unwrap(); + std::fs::write(priv_stage.join("archive.sha256"), &line_archive).unwrap(); + std::fs::write(priv_stage.join("hashes"), format!("{line_source}{line_guard}{line_archive}")).unwrap(); + + // 5. canonical stage --verify MUST pass (consistency) + if omega_source.join("tools/cudapp-stage.sh").is_file() { + let mut cmd = Command::new("sh"); + cmd.arg(omega_source.join("tools/cudapp-stage.sh")) + .arg("--verify") + .arg(&cudapp_lock) + .arg(&priv_stage); + if let Ok(omc) = std::env::var("OMEGA_OMC") { + cmd.env("OMEGA_OMC", omc); + } + if let Ok(bridge) = std::env::var("OMEGA_BRIDGE") { + cmd.env("OMEGA_BRIDGE", bridge); + } + let st = cmd.status().expect("run cudapp-stage.sh --verify"); + assert!(st.success(), "mutated private stage with consistent checksums must pass stage --verify"); + println!("ok aien-omega-gpu: mutated private stage passes stage --verify"); + } + + // 6. qualify_built_with_includes using REAL Core manifest + native-artifacts.lock MUST recorded hash mismatch + let priv_canonical_source = priv_stage.join("source"); + let priv_includes: Vec = [ + "src", "m16", "nvrm", + "third_party/nvidia-open-580.173.02/src/common/sdk/nvidia/inc", + "third_party/nvidia-open-580.173.02/kernel-open/common/inc", + "third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm", + "third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include", + ] + .iter() + .map(|p| priv_canonical_source.join(p)) + .collect(); + + let res = std::panic::catch_unwind(|| { + qualify_built_with_includes( + "aien-omega-gpu", + &manifest, + &artifacts_lock, + &priv_canonical_source, + &priv_archive, + &canonical_pin, + true, + priv_includes, + ); + }); + let err = res.expect_err("qualify_built_with_includes must panic on mutated archive even with consistent stage checksums"); + let msg = panic_message(err); + assert!( + msg.contains("native-artifacts.lock expects"), + "panic message must specify recorded mismatch against native-artifacts.lock, got: {msg}" + ); + assert!( + msg.contains(&format!("has sha256 {sha_archive}")), + "panic message must name the actual mutated sha256 {sha_archive}, got: {msg}" + ); + println!("ok aien-omega-gpu: real stage mutated archive rejected by native-artifacts.lock"); + } + } +} +EOF + + if AIEN_ROOT="$ROOT" AIEN_WORK="$WORK" TARGET="$HOST_TARGET" HOST="$HOST_TARGET" OUT_DIR="$WORK/probe-output" \ + AIEN_CANONICAL_STAGE="$STAGE_INPUT" AIEN_OMEGA_AUTH_DIR="$OMEGA_INPUT" \ + OMEGA_OMC="$OMC_INPUT" OMEGA_BRIDGE="$BRIDGE_INPUT" \ + cargo run -q --manifest-path "$probe_dir/Cargo.toml" >"$WORK/probe.log" 2>&1; then + pass "$crate: two-archive negative controls (shadow, unrecorded companion, recorded mismatch)" + if [ -n "$STAGE_INPUT" ]; then + pass "$crate: real canonical stage qualifies; forged consistent stage refused by independent archive lock" + fi + else + fail "$crate: two-archive negative controls" + cat "$WORK/probe.log" + fi +} +check_gpu if [ "$fails" -ne 0 ]; then echo "native identity: $fails case(s) failed" exit 1 diff --git a/scripts/test-pins.sh b/scripts/test-pins.sh index 2960e93b..0bdf3c2d 100755 --- a/scripts/test-pins.sh +++ b/scripts/test-pins.sh @@ -2,7 +2,7 @@ # test-pins.sh: offline self-test of scripts/pins.sh with throwaway git repositories # (no network). Proves: correct pins pass (--check and a full run against a local mirror), # a checkout off its pin is refused (exit 3), a malformed lock is refused (exit 3), and -# env.sh carries the three directories and the AIEN_OMEGA_DIR choice. +# env.sh carries the directories, AIEN_CUDAPP_DIR, and the AIEN_OMEGA_DIR choice. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" T=$(mktemp -d); trap 'rm -rf "$T"' EXIT @@ -10,27 +10,43 @@ fail=0 chk() { if eval "$1"; then echo " ok $2"; else echo " FAIL $2"; fail=1; fi; } mk() { # mk NAME [FILE CONTENT]...: a one-commit repo under $T/mirror/NAME, prints its sha local d="$T/mirror/$1"; shift; mkdir -p "$d" - git -C "$d" init -q; while [ $# -ge 2 ]; do printf '%s\n' "$2" > "$d/$1"; shift 2; done + git -C "$d" init -q; while [ $# -ge 2 ]; do mkdir -p "$(dirname "$d/$1")"; printf '%s\n' "$2" > "$d/$1"; shift 2; done [ -n "$(ls -A "$d" | grep -v '^.git$')" ] || : > "$d/.keep" git -C "$d" add -A; git -C "$d" -c user.name=t -c user.email=t@t commit -q -m pin; git -C "$d" rev-parse HEAD } -P=$(mk physics); A=$(mk aienos); O=$(mk omega physics.lock "$P" aienos.lock "$A") +P=$(mk physics); A=$(mk aienos); B=$(mk omega-bridge) +C=$(mk cudapp om/omega-bridge.lock "$B") +O=$(mk omega physics.lock "$P" aienos.lock "$A" cudapp.lock "$C") mkdir -p "$T/root"; printf '%s\n' "$O" > "$T/root/omega.lock" -run() { AIEN_PINS_ROOT="$T/root" AIEN_PINS_REMOTE_BASE="$T/mirror" bash "$ROOT/scripts/pins.sh" "$@"; } +run() { env -u OMEGA_OMC -u OMEGA_BRIDGE AIEN_PINS_ROOT="$T/root" AIEN_PINS_REMOTE_BASE="$T/mirror" bash "$ROOT/scripts/pins.sh" "$@"; } echo "test-pins: full run against a local mirror" chk 'run "$T/pins" >/dev/null' "pins.sh materializes omega, physics, aienos" chk '[ "$(git -C "$T/pins/omega" rev-parse HEAD)" = "$O" ]' "omega at omega.lock" chk '[ "$(git -C "$T/pins/physics" rev-parse HEAD)" = "$P" ]' "physics at omega physics.lock" chk '[ "$(git -C "$T/pins/aienos" rev-parse HEAD)" = "$A" ]' "aienos at omega aienos.lock" -chk 'grep -q "AIEN_OMEGA_COMPOSE_DIR=.*pins/omega" "$T/pins/env.sh" && grep -q "unset AIEN_OMEGA_DIR" "$T/pins/env.sh"' "env.sh: composition only without --gpu" +chk 'grep -q "AIEN_OMEGA_COMPOSE_DIR=.*pins/omega" "$T/pins/env.sh" && grep -q "unset AIEN_OMEGA_DIR AIEN_CUDAPP_DIR" "$T/pins/env.sh"' "env.sh: composition only without --gpu" chk 'run --gpu "$T/pins" >/dev/null && grep -q "export AIEN_OMEGA_DIR=.*pins/omega" "$T/pins/env.sh"' "env.sh: --gpu sets AIEN_OMEGA_DIR" +chk 'grep -q "export AIEN_CUDAPP_DIR=.*pins/cudapp" "$T/pins/env.sh"' "env.sh: --gpu sets AIEN_CUDAPP_DIR" +chk '[ "$(git -C "$T/pins/cudapp" rev-parse HEAD)" = "$C" ]' "cudapp at omega cudapp.lock" +chk '[ "$(git -C "$T/pins/omega-bridge" rev-parse HEAD)" = "$B" ] && grep -q "export OMEGA_BRIDGE=.*pins/omega-bridge" "$T/pins/env.sh"' "CUDApp unit bridge at its own lock, exported" chk 'grep -q "AIEN_REQUIRE_NATIVE_LIBS=1" "$T/pins/env.sh"' "env.sh: stubs refused (AIEN_REQUIRE_NATIVE_LIBS=1)" -chk 'run --check "$T/pins" >/dev/null' "--check passes when every clone is at its pin" +chk 'run --gpu --check "$T/pins" >/dev/null' "--check passes when every clone is at its pin" echo "test-pins: refusals" git -C "$T/pins/physics" -c user.name=t -c user.email=t@t commit -q --allow-empty -m drift rc=0; run --check "$T/pins" >/dev/null 2>&1 || rc=$? chk '[ "$rc" -eq 3 ]' "--check refuses a checkout off its pin (exit 3, got $rc)" chk 'run "$T/pins" >/dev/null && [ "$(git -C "$T/pins/physics" rev-parse HEAD)" = "$P" ]' "a full run moves it back to the pin" +git -C "$T/pins/cudapp" -c user.name=t -c user.email=t@t commit -q --allow-empty -m drift-cudapp +rc=0; run --gpu --check "$T/pins" >/dev/null 2>&1 || rc=$? +chk '[ "$rc" -eq 3 ]' "--gpu --check refuses cudapp checkout off its pin (exit 3, got $rc)" +chk 'run --gpu "$T/pins" >/dev/null && [ "$(git -C "$T/pins/cudapp" rev-parse HEAD)" = "$C" ]' "a full --gpu run moves cudapp back to the pin" +git -C "$T/pins/omega-bridge" -c user.name=t -c user.email=t@t commit -q --allow-empty -m drift-bridge +rc=0; run --gpu --check "$T/pins" >/dev/null 2>&1 || rc=$? +chk '[ "$rc" -eq 3 ]' "--gpu --check refuses bridge checkout off its pin (exit 3, got $rc)" +chk 'run --gpu "$T/pins" >/dev/null && [ "$(git -C "$T/pins/omega-bridge" rev-parse HEAD)" = "$B" ]' "a full --gpu run moves bridge back to its CUDApp pin" +printf 'not the pinned compiler\n' > "$T/bad-omc" +rc=0; env -u OMEGA_BRIDGE AIEN_PINS_ROOT="$T/root" AIEN_PINS_REMOTE_BASE="$T/mirror" OMEGA_OMC="$T/bad-omc" bash "$ROOT/scripts/pins.sh" --gpu "$T/pins" >"$T/bad-omc.log" 2>&1 || rc=$? +chk '[ "$rc" -eq 3 ] && grep -q "OMEGA_OMC is not the pinned compiler" "$T/bad-omc.log"' "wrong compiler hash refused before execution (exit 3, got $rc)" printf 'not-a-sha\n' > "$T/root/omega.lock" rc=0; run "$T/pins" >/dev/null 2>&1 || rc=$? chk '[ "$rc" -eq 3 ]' "malformed omega.lock refused (exit 3, got $rc)" From ece21a2153bf0ef56d28037d97c034027266ff38 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 28 Oct 2026 15:08:51 -0500 Subject: [PATCH 8/9] Invalidate clean engine identity on tracked source changes --- .crumb | 12 +-- crates/aien-serve-http/build.rs | 23 ++++- .../aien-serve-http/tests/build_identity.rs | 99 +++++++++++++++++++ docs/release/BUILD_RECIPE.md | 6 ++ 4 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 crates/aien-serve-http/tests/build_identity.rs diff --git a/.crumb b/.crumb index 40708fe7..73188fcb 100644 --- a/.crumb +++ b/.crumb @@ -101,7 +101,7 @@ }, { "digest": "b811ed841b3b36b0be3661290b8adfc1f5ea65710d6dd19d5ce2d0885af9cfcc", - "last_commit": "fe3677c3", + "last_commit": "fc184dac", "name": "scripts", "purpose": "" }, @@ -119,14 +119,14 @@ } ], "children_root": "sha256:1531c58a660546b73170011d2c04ac2ec5cc48fdea193b4441d0a7c57aaf9753", - "compiled_at": "2026-10-28T19:53:33Z", + "compiled_at": "2026-10-28T20:08:51Z", "compiler": "crumb-compile/1", - "digest": "sha256:1d5bef350231604182802ab54850f0f2d4853802513d53f165ac6380e23b76df", + "digest": "sha256:2a5dde991f0259991bfcf4363bf732d763f1874c0957cf9a12f2893151c887d7", "evidence_files": 3409, "evidence_root": "sha256:09391c156f119df3838e28645c7303b5e7f3dc09d528b9866426aa5c9fc77b93", - "files": 7761, - "generated_at_commit": "aaab111c93168702da7db22e98555bb656c9bb28", - "source_tree": "sha256:4021b67e745f3ac020c6b2aa61bc7fdb7c42d9263f53bd29b3d0645e77422abf" + "files": 7763, + "generated_at_commit": "fc184dacb02a92b38b5a9e2502bfbff61634a1e4", + "source_tree": "sha256:29cb597f043e760a335c44d3f0573747cc652bbea525ff25b91780d9ba555a09" } }, "history": [], diff --git a/crates/aien-serve-http/build.rs b/crates/aien-serve-http/build.rs index 44b9e802..68ede9dd 100644 --- a/crates/aien-serve-http/build.rs +++ b/crates/aien-serve-http/build.rs @@ -5,12 +5,13 @@ //! when set, else `git rev-parse HEAD`, else `unknown`). //! - `AIEN_SERVE_HTTP_GIT_DIRTY`: `1` when `git status` showed modified tracked files at build //! time, `0` when clean (or `AIEN_BUILD_COMMIT` given), `unknown` without git. Re-checked -//! when HEAD or the index moves, not on every unstaged edit. +//! when HEAD, the index, the branch ref or any tracked source changes. use std::path::{Path, PathBuf}; use std::process::Command; fn git(root: &Path, args: &[&str]) -> Option { let out = Command::new("git") + .env("GIT_OPTIONAL_LOCKS", "0") .arg("-C") .arg(root) .args(args) @@ -22,6 +23,25 @@ fn git(root: &Path, args: &[&str]) -> Option { Some(String::from_utf8(out.stdout).ok()?.trim().to_string()) } +fn watch_tracked_files(root: &Path) { + let Ok(out) = Command::new("git") + .arg("-C") + .arg(root) + .args(["ls-files", "-z"]) + .output() + else { + return; + }; + if !out.status.success() { + return; + } + for path in out.stdout.split(|b| *b == 0).filter(|p| !p.is_empty()) { + let path = std::str::from_utf8(path).expect("tracked build identity path is not UTF-8"); + assert!(!path.contains(['\r', '\n']), "tracked build identity path contains a newline"); + println!("cargo:rerun-if-changed={}", root.join(path).display()); + } +} + fn main() { let manifest = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); let root = manifest.join("../.."); @@ -33,6 +53,7 @@ fn main() { let (commit, dirty) = match forced { Some(c) => (c.trim().to_string(), "0".to_string()), None => { + watch_tracked_files(&root); for p in ["HEAD", "index"] { if let Some(path) = git(&root, &["rev-parse", "--git-path", p]) { let path = if Path::new(&path).is_absolute() { diff --git a/crates/aien-serve-http/tests/build_identity.rs b/crates/aien-serve-http/tests/build_identity.rs new file mode 100644 index 00000000..f24d7d3d --- /dev/null +++ b/crates/aien-serve-http/tests/build_identity.rs @@ -0,0 +1,99 @@ +//! Host-only regression for the actual build script's Cargo invalidation contract. +use std::path::{Path, PathBuf}; +use std::process::Command; +use std::sync::atomic::{AtomicU64, Ordering}; + +static NEXT: AtomicU64 = AtomicU64::new(0); +struct Fixture(PathBuf); +impl Drop for Fixture { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.0); + } +} +fn run(command: &mut Command) -> String { + let output = command.output().expect("run host fixture command"); + assert!(output.status.success(), "{command:?}: {}", String::from_utf8_lossy(&output.stderr)); + String::from_utf8(output.stdout).unwrap().trim().to_string() +} +fn cargo_command(root: &Path, manifest: &Path) -> Command { + let mut command = Command::new(env!("CARGO")); + command.current_dir(root) + .args(["run", "--verbose", "--locked", "--offline", "--manifest-path"]) + .arg(manifest) + .env("CARGO_TARGET_DIR", root.join("target")) + .env("GIT_OPTIONAL_LOCKS", "0") + .env_remove("AIEN_BUILD_COMMIT"); + command +} +fn cargo_run(root: &Path, manifest: &Path) -> String { + run(&mut cargo_command(root, manifest)) +} +fn cargo_fresh(root: &Path, manifest: &Path) -> String { + let output = cargo_command(root, manifest).output().unwrap(); + let stderr = String::from_utf8(output.stderr).unwrap(); + assert!(output.status.success() && stderr.contains("Fresh core-build-identity-fixture"), "{stderr}"); + String::from_utf8(output.stdout).unwrap().trim().to_string() +} +fn source(version: &str) -> String { + format!("fn main() {{ println!(\"{{}}:{{}}:{version}\", env!(\"AIEN_SERVE_HTTP_GIT_COMMIT\"), env!(\"AIEN_SERVE_HTTP_GIT_DIRTY\")); }}\n") +} + +#[test] +fn tracked_source_and_noncrate_changes_invalidate_the_clean_build_stamp() { + let path = std::env::temp_dir().join(format!("core-build-identity-{}-{}", std::process::id(), NEXT.fetch_add(1, Ordering::Relaxed))); + std::fs::create_dir(&path).unwrap(); + let fixture = Fixture(path); + let root = &fixture.0; + let package = root.join("crates/fixture"); + std::fs::create_dir_all(package.join("src")).unwrap(); + let manifest = package.join("Cargo.toml"); + std::fs::write(&manifest, "[package]\nname = \"core-build-identity-fixture\"\nversion = \"0.0.0\"\nedition = \"2021\"\n").unwrap(); + std::fs::copy(Path::new(env!("CARGO_MANIFEST_DIR")).join("build.rs"), package.join("build.rs")).unwrap(); + let main = package.join("src/main.rs"); + let baseline = source("baseline"); + std::fs::write(&main, &baseline).unwrap(); + let outside = root.join("tracked-input.txt"); + std::fs::write(&outside, "baseline\n").unwrap(); + run(Command::new(env!("CARGO")).current_dir(root) + .args(["generate-lockfile", "--offline", "--manifest-path"]).arg(&manifest) + .env("CARGO_TARGET_DIR", root.join("target"))); + run(Command::new("git").current_dir(root).args(["init", "-q"])); + for (key, value) in [("user.name", "Build identity fixture"), ("user.email", "fixture@example.invalid"), ("core.hooksPath", "/dev/null"), ("commit.gpgsign", "false")] { + run(Command::new("git").current_dir(root).args(["config", key, value])); + } + run(Command::new("git").current_dir(root).args(["add", "crates", "tracked-input.txt"])); + run(Command::new("git").current_dir(root).args(["commit", "-q", "-m", "fixture"])); + let commit = run(Command::new("git").current_dir(root).args(["rev-parse", "HEAD"])); + assert_eq!(cargo_run(root, &manifest), format!("{commit}:0:baseline")); + assert_eq!(cargo_fresh(root, &manifest), format!("{commit}:0:baseline")); + + // No index or HEAD change: compiling modified tracked source must not retain clean=0. + std::fs::write(&main, source("modified")).unwrap(); + assert_eq!(cargo_run(root, &manifest), format!("{commit}:1:modified")); + std::fs::write(&main, &baseline).unwrap(); + assert_eq!(cargo_run(root, &manifest), format!("{commit}:0:baseline")); + + // A tracked file outside this crate must also invalidate the whole-checkout stamp. + std::fs::write(&outside, "modified\n").unwrap(); + assert_eq!(cargo_run(root, &manifest), format!("{commit}:1:baseline")); + + // Negative control: remove the watcher in this private fixture only. The old + // behavior compiles new source while retaining the previous clean identity. + std::fs::write(&outside, "baseline\n").unwrap(); + let build_script = package.join("build.rs"); + let original = std::fs::read_to_string(&build_script).unwrap(); + let mutant = original.replace("watch_tracked_files(&root);", ""); + assert_ne!(mutant, original, "negative control must remove the watcher"); + std::fs::write(&build_script, mutant).unwrap(); + run(Command::new("git").current_dir(root).args(["add", "crates/fixture/build.rs"])); + run(Command::new("git").current_dir(root).args(["commit", "-q", "-m", "watcher-removed negative control"])); + let mutant_commit = run(Command::new("git").current_dir(root).args(["rev-parse", "HEAD"])); + assert_eq!(cargo_run(root, &manifest), format!("{mutant_commit}:0:baseline")); + assert_eq!(cargo_fresh(root, &manifest), format!("{mutant_commit}:0:baseline")); + std::fs::write(&main, source("modified")).unwrap(); + assert_eq!(cargo_run(root, &manifest), format!("{mutant_commit}:0:modified")); + std::fs::write(&main, &baseline).unwrap(); + assert_eq!(cargo_run(root, &manifest), format!("{mutant_commit}:0:baseline")); + std::fs::write(&outside, "modified\n").unwrap(); + assert_eq!(cargo_fresh(root, &manifest), format!("{mutant_commit}:0:baseline")); +} diff --git a/docs/release/BUILD_RECIPE.md b/docs/release/BUILD_RECIPE.md index bdf63e78..e286505b 100644 --- a/docs/release/BUILD_RECIPE.md +++ b/docs/release/BUILD_RECIPE.md @@ -52,6 +52,7 @@ After sourcing the pinned environment, the host-only acceptance commands are: bash scripts/abi-qualify.sh --out /absolute/path/to/new-host-evidence-directory cargo test --locked --offline -p aien-inference-abi --test omega_backend_parity cargo test --locked --offline -p aien-serve-http --lib --test loopback --test kv_persist -- --test-threads=1 +cargo test --locked --offline -p aien-serve-http --test build_identity ``` Do not add `--chip`, `--ignored`, or a real model directory to this host rehearsal. @@ -60,6 +61,11 @@ ephemeral listener; it does not launch the resident 35B workload. Persistence bi sources, both archive digests, both targets and the clean engine commit in a length-framed, domain-separated `v2:` SHA-256 identity. The bounded identifier preserves the existing KV format limit; old single-archive identities cannot hit the new namespace. +The build script watches every tracked checkout file and reads Git without optional +index writes. The `build_identity` test uses real Cargo rebuilds: a no-op must be Fresh, +source and outside-crate edits must invalidate the clean stamp, and a watcher-removed +private mutant must reproduce the stale-clean identity. An always-rerunning script is +not sufficient evidence for this contract. This rehearsal still uses the reviewed CUDApp #169 source. The separately verified #173 repair is not a merged combined candidate, and user-owned #174 is pending. Keep the guide From d9217f092a398768ca558f3a09adea1985416913 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 28 Oct 2026 15:33:15 -0500 Subject: [PATCH 9/9] Pin hermetic canonical CUDApp stage and record its measured identities omega.lock moves to omega-mv 3303dd79 (draft #924), whose cudapp-stage.sh builds the authenticated CUDApp tree under env -i with PHYSICS_DIR=. Before it, build.rs's make PHYSICS_DIR= reached the nested CUDApp make through MAKEFLAGS and compiled physics' nvrm.c/nvrm.h/m16_native.c into libcudapp.a; that archive (cf95a6a7...) is not CUDApp 7a354dbd and is removed from native-artifacts.lock together with the cafb7be companion and compose lines that were measured only beside it. Recorded from the measured qualification run with pins omega 3303dd79, cudapp 7a354dbd, physics 048e5f5e, aienos b84c0a67, bridge 0c4cb9ff: libcudapp.a 353b1131..., libomega_gpu.a 931d7b07..., librx_compose.a 0ac258c8... --- .crumb | 10 +++++----- native-artifacts.lock | 6 +++--- omega.lock | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.crumb b/.crumb index 73188fcb..6921dbaa 100644 --- a/.crumb +++ b/.crumb @@ -119,14 +119,14 @@ } ], "children_root": "sha256:1531c58a660546b73170011d2c04ac2ec5cc48fdea193b4441d0a7c57aaf9753", - "compiled_at": "2026-10-28T20:08:51Z", + "compiled_at": "2026-10-28T20:33:04Z", "compiler": "crumb-compile/1", - "digest": "sha256:2a5dde991f0259991bfcf4363bf732d763f1874c0957cf9a12f2893151c887d7", + "digest": "sha256:6d1079a74d45b40be6beaeacdb3a4906cd31501a990e2939e87b273f4d400954", "evidence_files": 3409, "evidence_root": "sha256:09391c156f119df3838e28645c7303b5e7f3dc09d528b9866426aa5c9fc77b93", - "files": 7763, - "generated_at_commit": "fc184dacb02a92b38b5a9e2502bfbff61634a1e4", - "source_tree": "sha256:29cb597f043e760a335c44d3f0573747cc652bbea525ff25b91780d9ba555a09" + "files": 7764, + "generated_at_commit": "ece21a2153bf0ef56d28037d97c034027266ff38", + "source_tree": "sha256:33e7adb95075af1772f29eed6b337e5f5cd3983d3feb0bbaa06cae36cf7ba078" } }, "history": [], diff --git a/native-artifacts.lock b/native-artifacts.lock index cc3fdadf..3b89d70e 100644 --- a/native-artifacts.lock +++ b/native-artifacts.lock @@ -39,6 +39,6 @@ libomega_gpu.a 7052d780ad9de52285e1c620e3eefd00ec5dc8db aarch64-unknown-linux-gn librx_compose.a 7052d780ad9de52285e1c620e3eefd00ec5dc8db aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 libomega_gpu.a 1ad2dc1af70f01680fd93cb41a7a94fd0951723f aarch64-unknown-linux-gnu 63c500cec9784cf9ed6d751062f0dfcd27313e80e29b316e16f6bfc6ffc11c01 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 librx_compose.a 1ad2dc1af70f01680fd93cb41a7a94fd0951723f aarch64-unknown-linux-gnu e598074e58533dc5fb08281f1392d265943f6f8def2fc4950f04a5729c100758 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 -libcudapp.a 7a354dbda9eddd405610fdcabf4fc4e24c1a0f47 aarch64-unknown-linux-gnu cf95a6a7808c1b948a459efb22b62c0093644c10c58461e816e55ef0134befa9 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 -libomega_gpu.a cafb7be08e4a92d6dd7347b011a833f524140dee aarch64-unknown-linux-gnu 931d7b07620db1db7f2e91b62d04ac61e363d3ded6e94dca5b46dfbf52ee9fd5 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 -librx_compose.a cafb7be08e4a92d6dd7347b011a833f524140dee aarch64-unknown-linux-gnu 0ac258c8fe2bee0fdaf6784f00213c386b46016b45704dc88eb72e1ba1c2a9a2 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +libcudapp.a 7a354dbda9eddd405610fdcabf4fc4e24c1a0f47 aarch64-unknown-linux-gnu 353b11312829fa5a73da7423ebcddc9bf9386524d8ff50dd1e396d22abf6f6b3 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +libomega_gpu.a 3303dd79b3c3096a773b51d09316c01330e3f9f2 aarch64-unknown-linux-gnu 931d7b07620db1db7f2e91b62d04ac61e363d3ded6e94dca5b46dfbf52ee9fd5 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +librx_compose.a 3303dd79b3c3096a773b51d09316c01330e3f9f2 aarch64-unknown-linux-gnu 0ac258c8fe2bee0fdaf6784f00213c386b46016b45704dc88eb72e1ba1c2a9a2 cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 diff --git a/omega.lock b/omega.lock index e3beb3ee..a67bf705 100644 --- a/omega.lock +++ b/omega.lock @@ -1 +1 @@ -cafb7be08e4a92d6dd7347b011a833f524140dee +3303dd79b3c3096a773b51d09316c01330e3f9f2