From 7446c70dfac45d239dda1ded69a44e0dbd118854 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Tue, 6 Oct 2026 06:41:34 +0200 Subject: [PATCH] fix: probe CUDA engine in compatible runtime image --- .github/workflows/linux.yml | 3 ++- scripts/build-linux-package.py | 24 +++++++++++++++++++---- scripts/build-runtime-image.py | 5 ++++- scripts/test-cuda-docker-builder.py | 2 ++ scripts/test-linux-package.py | 26 +++++++++++++++++++++++++ scripts/test-runtime-image.py | 30 +++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 6 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index d1ca0421..962ba6f1 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -112,7 +112,8 @@ jobs: package="$RUNNER_TEMP/strata-hosted-cuda-package" /usr/bin/time -v python3 scripts/build-linux-package.py --engine "$engine" \ --sha256 "$(sha256sum "$engine" | cut -d ' ' -f 1)" --revision "$GITHUB_SHA" \ - --cargo-target-dir "$RUNNER_TEMP/strata-hosted-package-build" --output "$package" + --cargo-target-dir "$RUNNER_TEMP/strata-hosted-package-build" --output "$package" \ + --defer-engine-help-probe-to-runtime-image python3 scripts/build-runtime-image.py --package "$package" \ --receipt-sha256 "$(sha256sum "$package/SHA256SUMS" | cut -d ' ' -f 1)" \ > "$RUNNER_TEMP/strata-hosted-image.json" diff --git a/scripts/build-linux-package.py b/scripts/build-linux-package.py index 5688d067..213b3e53 100644 --- a/scripts/build-linux-package.py +++ b/scripts/build-linux-package.py @@ -68,6 +68,15 @@ def static_outer(binary): return {'program_headers': headers, 'dynamic_section': dynamic} +def probe_engine_help(binary, stage, env, *, defer_to_runtime_image): + if defer_to_runtime_image: + return 'deferred-to-runtime-image' + probe = stage / 'probe.json' + probe.write_text(json.dumps({'engine': {'executable': '@embedded'}, 'engine_probe': True})) + run([binary, 'provision', '--config', probe], env=env, timeout=30) + return 'passed-on-package-builder-host' + + @contextlib.contextmanager def lock(path): # Caller-controlled build/output paths are private; keep the inode for reuse. @@ -95,6 +104,9 @@ def publish(source, output): def assemble(args): if platform.system() != 'Linux' or platform.machine() != 'x86_64': raise ValueError('package assembly requires Linux x86_64') + defer_help = getattr(args, 'defer_engine_help_probe_to_runtime_image', False) + if defer_help and args.cpu_fixture: + raise ValueError('only CUDA package builds may defer the loader probe to the runtime image') source_check(REPO, args.revision) output = args.output.absolute() output.parent.mkdir(parents=True, exist_ok=True) @@ -137,17 +149,19 @@ def assemble(args): info['declared_source_revision'] == args.revision and info['bytes'] == size and info['target_os'] == 'linux' and info['target_arch'] == 'x86_64'): raise ValueError('combined engine identity does not match pinned input') - probe = stage / 'probe.json' - probe.write_text(json.dumps({'engine': {'executable': '@embedded'}, 'engine_probe': True})) - run([binary, 'provision', '--config', probe], env=probe_env, timeout=30) + help_probe = probe_engine_help(binary, stage, probe_env, + defer_to_runtime_image=defer_help) source_check(REPO, args.revision) provenance = {'schema_version': 1, 'kind': 'cpu-fixture' if args.cpu_fixture else 'static-cuda-preview', 'source_revision': args.revision, 'target': TARGET, 'engine': info, + 'engine_help_probe': help_probe, 'engine_elf_audit': audit, 'outer_elf_audit': outer, 'cargo_lock_sha256': sha256(REPO / 'control-plane/Cargo.lock'), 'rustc': run(['rustc', '--version']), 'cargo': run(['cargo', '--version']), 'gpu_tested': False, 'model_tested': False, 'clean_node_tested': False, - 'qualification': 'Exact payload identity, outer ELF and GPU-hidden loader help only; no inference.', + 'qualification': ('Exact payload identity and outer ELF; loader help is verified in the compatible runtime image; no inference.' + if help_probe == 'deferred-to-runtime-image' else + 'Exact payload identity, outer ELF and GPU-hidden loader help on package builder host; no inference.'), 'source_provenance': 'Operator/CI-declared engine revision, not binary-to-source attestation.'} (published / 'PROVENANCE.json').write_text(json.dumps(provenance, indent=2) + '\n') (published / 'SHA256SUMS').write_text(''.join(f'{sha256(p)} {p.name}\n' for p in [binary, published / 'PROVENANCE.json'])) @@ -165,6 +179,8 @@ def main(): parser.add_argument('--output', type=Path, required=True) parser.add_argument('--cargo-target-dir', type=Path, required=True, help='dedicated build directory; do not run other Cargo commands here concurrently') parser.add_argument('--cpu-fixture', action='store_true', help='explicit non-CUDA test artifact; never a GPU release') + parser.add_argument('--defer-engine-help-probe-to-runtime-image', action='store_true', + help='run the embedded engine loader probe only in the final runtime image, for CUDA engines with a newer glibc floor than the build host') args = parser.parse_args() try: print(json.dumps(assemble(args))) diff --git a/scripts/build-runtime-image.py b/scripts/build-runtime-image.py index bfe4d491..9929be2c 100644 --- a/scripts/build-runtime-image.py +++ b/scripts/build-runtime-image.py @@ -70,6 +70,8 @@ def freeze(package, stage, receipt_sha, cpu_fixture): not re.fullmatch(r'[0-9a-f]{64}', engine.get('sha256', ''))): raise ValueError('invalid embedded engine identity') if not cpu_fixture: + if p.get('engine_help_probe') != 'deferred-to-runtime-image': + raise ValueError('CUDA package must defer loader help until the compatible runtime image') audit = p.get('engine_elf_audit', {}) if audit.get('toolkit_shared_libraries') is not False or audit.get('host_glibc_required') is not True: raise ValueError('missing static CUDA ELF audit') @@ -138,7 +140,8 @@ def assemble(args): isolated_run(image, ['engine-help']) result = {'schema_version': 1, 'image': image, 'base': args.base, 'base_glibc': glibc, 'package_receipt_sha256': args.receipt_sha256, 'source_revision': p['source_revision'], - 'kind': p['kind'], 'gpu_tested': False, 'model_tested': False, + 'kind': p['kind'], 'engine_help_probe': 'passed-in-runtime-image', + 'gpu_tested': False, 'model_tested': False, 'qualification': 'Non-root GPU-hidden embedded identity and loader help only.'} success = True return result diff --git a/scripts/test-cuda-docker-builder.py b/scripts/test-cuda-docker-builder.py index e59f2620..d94b911b 100644 --- a/scripts/test-cuda-docker-builder.py +++ b/scripts/test-cuda-docker-builder.py @@ -234,6 +234,8 @@ else: self.assertIn('gh release create', job) self.assertRegex(job, r'apt-get install -y .*\btime\b') self.assertIn('/usr/bin/time -v python3 scripts/build-linux-package.py', job) + self.assertIn('--defer-engine-help-probe-to-runtime-image', job) + self.assertIn('scripts/build-runtime-image.py --package', job) self.assertNotIn('strata-gpu', job) self.assertNotIn('actions/upload-artifact', job) self.assertNotIn('static_cuda_package', workflow) diff --git a/scripts/test-linux-package.py b/scripts/test-linux-package.py index 13e931a7..d756dad0 100644 --- a/scripts/test-linux-package.py +++ b/scripts/test-linux-package.py @@ -76,6 +76,20 @@ class PackageTests(unittest.TestCase): with pkg.lock(alias): self.fail('symlink lock accepted') + def test_cuda_loader_probe_can_be_deferred_only_as_declared(self): + probe_binary = self.root / 'strata-next' + stage = self.root / 'stage' + stage.mkdir() + with patch.object(pkg, 'run') as run: + self.assertEqual(pkg.probe_engine_help(probe_binary, stage, {}, defer_to_runtime_image=True), + 'deferred-to-runtime-image') + run.assert_not_called() + with patch.object(pkg, 'run') as run: + self.assertEqual(pkg.probe_engine_help(probe_binary, stage, {}, defer_to_runtime_image=False), + 'passed-on-package-builder-host') + run.assert_called_once() + self.assertTrue((stage / 'probe.json').is_file()) + @unittest.skipUnless(sys.platform == 'linux', 'Linux atomic publication') def test_atomic_publication_never_replaces_existing_directory(self): staged, output = self.root / 'stage', self.root / 'out' @@ -117,6 +131,18 @@ class PackageTests(unittest.TestCase): build.assert_not_called() self.assertEqual((output / 'old').read_text(), 'keep') + def test_cpu_fixture_cannot_defer_loader_probe(self): + from types import SimpleNamespace + args = SimpleNamespace(engine=self.root/'engine', sha256='0'*64, revision='a'*40, + output=self.root/'out', cargo_target_dir=self.root/'target', + cpu_fixture=True, defer_engine_help_probe_to_runtime_image=True) + with patch.object(pkg.platform, 'system', return_value='Linux'), \ + patch.object(pkg.platform, 'machine', return_value='x86_64'), \ + patch.object(pkg.subprocess, 'run') as build: + with self.assertRaisesRegex(ValueError, 'only CUDA package builds'): + pkg.assemble(args) + build.assert_not_called() + if __name__ == '__main__': unittest.main() diff --git a/scripts/test-runtime-image.py b/scripts/test-runtime-image.py index d0d6b4a3..c8aca429 100644 --- a/scripts/test-runtime-image.py +++ b/scripts/test-runtime-image.py @@ -28,6 +28,7 @@ class PackageTests(unittest.TestCase): 'source_revision': 'a'*40, 'target': 'x86_64-unknown-linux-musl', 'engine': {'embedded': True, 'target_os': 'linux', 'target_arch': 'x86_64', 'declared_source_revision': 'a'*40, 'bytes': 3, 'sha256': 'b'*64}, + 'engine_help_probe': 'deferred-to-runtime-image', 'engine_elf_audit': {'toolkit_shared_libraries': False, 'host_glibc_required': True, 'minimum_glibc': '2.43'}} (self.pkg/b.NAME).write_bytes(b'not executable; validator does not execute input') @@ -110,6 +111,35 @@ class PackageTests(unittest.TestCase): with self.assertRaisesRegex(ValueError, 'size limit'): b.frozen_file(self.pkg/b.NAME, Path(stage)/'out', 1) + def test_cuda_package_requires_runtime_image_loader_probe(self): + self.provenance.pop('engine_help_probe') + self.write() + with self.assertRaisesRegex(ValueError, 'defer loader help'): + self.freeze() + + def test_successful_image_probes_embedded_help_after_identity(self): + args = SimpleNamespace(base=b.BASE, package=self.pkg, receipt_sha256=self.sha, cpu_fixture=False) + image = 'sha256:' + 'd'*64 + isolated = [] + def docker(*argv, **kwargs): + if argv[0] == 'build': + Path(argv[argv.index('--iidfile')+1]).write_text(image) + return SimpleNamespace(stdout='') + def probe(probe_image, arguments, *, entrypoint=None): + isolated.append((probe_image, arguments, entrypoint)) + if entrypoint == 'getconf': + return 'glibc 2.43\n' + if arguments == ['engine-info']: + return json.dumps(self.provenance['engine']) + if arguments == ['engine-help']: + return '' + raise AssertionError((arguments, entrypoint)) + with patch.object(b, 'docker', side_effect=docker), patch.object(b, 'isolated_run', side_effect=probe): + result = b.assemble(args) + self.assertEqual(result['engine_help_probe'], 'passed-in-runtime-image') + self.assertEqual([call[1] for call in isolated], [['GNU_LIBC_VERSION'], ['engine-info'], ['engine-help']]) + self.assertEqual([call[2] for call in isolated], ['getconf', None, None]) + def test_runtime_probe_script_has_valid_bash_syntax(self): subprocess.run(['bash', '-n'], input=smoke.PROBE_SCRIPT, text=True, capture_output=True, check=True)