fix: probe CUDA engine in compatible runtime image
Linux / verify (pull_request) Successful in 2m44s
Linux / keyless-cuda (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Successful in 21s
Linux / linux-static-cli (pull_request) Successful in 7m17s
Linux / release-cli (pull_request) Skipped

This commit is contained in:
Pavlo Ratushnyi
2026-10-06 06:41:34 +02:00
parent 70f99ba63e
commit 7446c70dfa
6 changed files with 84 additions and 6 deletions
+2 -1
View File
@@ -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"
+20 -4
View File
@@ -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)))
+4 -1
View File
@@ -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
+2
View File
@@ -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)
+26
View File
@@ -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()
+30
View File
@@ -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)