Files
leleka/scripts/smoke-native-bootstrap.py
Pavlo Ratushnyi 056ab3d689 Retire the oracles, generators and scripts that only worked against the vendored Strata tree (STRA-406)
The vendored Strata tree engine/strata is removed for good (owner decision 2026-11-23): Leleka never builds or runs it, the vanilla
benchmark builds from its own checkout, the comparison measurements are finished and the CUDA ports are frozen. Everything below
compiled or read that tree, so it cannot run without it and is retired (the tree stays in git history, see third_party/strata/UPSTREAM.md).
Checked-in fixtures, golden JSON, sealed PTX, seal plans and MANIFEST hashes are untouched and keep being replayed by the cargo tests.

Drift guard
- crates/experimental-ref/tests/literal_port.rs: include_str! of the Original .cu files compared with the checked-in experimental ports.

Oracle generators and builders (they compile or extract from the Strata C++/Python sources; their outputs are the checked-in goldens)
- crates/experimental-ref/oracle/gen_{cvec,kv,remote,stream}_golden.{cpp,sh}, gen_seal_additions.py and the cuda_runtime stub they used
- crates/sampler-ref/oracle/build_oracle.sh, gen_fixtures.cpp, gen_sampling_keys.py, stub/ (run_port_host_tests.sh and the fixtures stay)
- crates/serving-policy/oracle/ (build_oracle.sh, gen_{host,cvec,vision}_fixtures.cpp)
- crates/context/tests/rope_plan_golden/gen_* (plan, rope, kv pool)
- crates/engine-core/src/conversation/golden/gen*.{sh,cpp} and stub/
- crates/cuda-driver/oracle/gen_prefill_ring_trace.py and drivers/prefill_ring_trace.cpp (extracted prefill.cpp), check_cu_syntax.sh
- crates/engine-qwen35-cuda/tests/stra161_reference/reference.py (fixtures.json and the Rust constants stay)
- control-plane/tests/golden/gen_goldens.py, scripts/offline/ (Python differentials and golden generators against the Strata Python tools)

Source-compiling CUDA oracles and builders
- scripts/build-cuda-{projection-family,q5,q6,qsa}-oracle.sh with scripts/cuda-{projection-family,q5,q6,qsa}-oracle/ (include the Original .cu; sha256 pins of them)
- scripts/build-original-verify-ptx.sh, scripts/q8/rebuild_quantizer_ptx.sh, scripts/decode-sm120/make_iq_prefix.py (needs engine/strata/include)
- scripts/cuda-stubs/ (check-cu.py and literal_diff.py need the strata headers and the Original sources; the stub headers served only them)
- tools/chain-probe/build.sh, tools/kernel-ab/{cpp,aa.sh,smoke.sh,time_smoke.sh} (the C++ comparator is built from the Strata CPU kernels; verify_manifest.py stays)
- scripts/e2e/codex/speed/verify-hc-down-kernel-microbench-vs-upstream/ (compiles the upstream kernel from the tree)

Engine builds and Python smokes that need the tree
- scripts/build-cpu.sh, scripts/build-static-cuda.sh, scripts/check-keyless-gpu.sh, scripts/test-static-cuda-profile.py (CMake of engine/strata)
- scripts/compare-real-tokenizer.py, scripts/smoke-mtp-pack.py (reads src/core/mtp.cpp and a bench manifest), scripts/prepare-keyless-routing.py and its test
- scripts/smoke-native-pack.py became scripts/native-pack-fixture.py: the synthetic GGUF fixtures the four other smokes import stay, the iq_pack.py oracle comparison goes

Gates and CI
- scripts/check-local.sh: no live Python oracle differentials, no literal_port note, no check-cu, no build-cpu, no retired test scripts
- .github/workflows/linux.yml: the keyless-cuda, static-cuda-package and hosted-cuda-package jobs (they built the engine from the tree) and their dispatch
  inputs, and the two oracle smoke steps; .github/workflows/port.yml: the Python oracle environment and the llama.cpp fetch of port-oracles
  (the sampler host shim still runs)
- limits.json and scripts/check_limits_test.py exclude third_party/strata/ instead of engine/strata/

Documentation and comments: README.md names third_party/strata and the pin; deploy/README.md marks the retired build and smoke commands; comments
in Rust, Python and Markdown that named engine/strata/... now name "Strata 41cf05a0, ..."; the gpu-bringup scratch-copy test no longer copies the
removed include directories. Stale engine/strata paths in sealed .cu, .ptx, seal-plan and MANIFEST files are left as they are (hashes may depend on the bytes).
2026-11-23 21:19:11 +01:00

187 lines
9.0 KiB
Python

#!/usr/bin/env python3
"""CPU subprocess bootstrap contract: real download/pack, synthetic worker only."""
import copy
import fcntl
import hashlib
import http.client
import http.server
import importlib.util
import json
import os
from pathlib import Path
import socket
import subprocess
import sys
import tempfile
import threading
import time
def main():
binary = str(Path(sys.argv[1]).resolve())
spec = importlib.util.spec_from_file_location('pack_fixture', Path(__file__).with_name('native-pack-fixture.py'))
fixture = importlib.util.module_from_spec(spec)
spec.loader.exec_module(fixture)
requests = []
data = b''
class Source(http.server.BaseHTTPRequestHandler):
def log_message(self, *_):
pass
def do_GET(self):
requests.append(self.path)
self.send_response(200)
self.send_header('Content-Length', str(len(data)))
self.end_headers()
self.wfile.write(data)
with tempfile.TemporaryDirectory(prefix='strata-native-bootstrap-') as tmp:
root = Path(tmp).resolve()
gguf = root / 'fixture.gguf'
fixture.write_gguf(gguf, fixture.fixtures())
data = gguf.read_bytes()
server = http.server.ThreadingHTTPServer(('127.0.0.1', 0), Source)
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
manifest = root / 'manifest.json'
manifest.write_text(json.dumps({'schema_version': 1, 'files': [{
'name': 'model.gguf', 'url': f'http://127.0.0.1:{server.server_port}/model.gguf',
'size': len(data), 'sha256': hashlib.sha256(data).hexdigest()}]}))
marker = root / 'started'
worker = root / 'worker.sh'
# Assert the actual pinned engine's --native PATH / --pack DIR grammar.
worker.write_text('''#!/bin/sh
set -eu
[ "$1" = --serve ]
marker="$2"
[ "$3" = --pack ]; pack="$4"
[ "$5" = --native ]; source="$6"
[ -s "$source" ] && [ -s "$pack/receipt.json" ]
[ -s "$pack/dense.bin" ] && [ -s "$pack/tokenizer/vocab.json" ]
printf '%s\\n%s\\n' "$pack" "$source" > "$marker"
printf 'READY 256 stop\\n'
while IFS= read -r line; do case "$line" in QUIT) exit 0 ;; esac; done
''')
worker.chmod(0o700)
with socket.socket() as probe:
probe.bind(('127.0.0.1', 0))
port = probe.getsockname()[1]
source, output = root / 'sources-v1', root / 'pack-v1'
config = {'bind': f'127.0.0.1:{port}', 'native_model': {
'manifest': str(manifest), 'source_dir': str(source), 'output': str(output)},
'engine': {'executable': str(worker), 'args': [str(marker)], 'startup_timeout_s': 5, 'max_restarts': 0}}
config_path = root / 'config.json'
env = {'PATH': os.defpath}
count = 0
processes = []
def save():
config_path.write_text(json.dumps(config))
def run(command='provision', ok=True):
nonlocal count
save()
r = subprocess.run([binary, command, '--config', str(config_path)], env=env, capture_output=True, text=True, timeout=15)
assert (r.returncode == 0) == ok, (r.stdout, r.stderr)
count += 1
return r
def gated_failure():
marker.unlink(missing_ok=True)
run('serve', ok=False)
assert not marker.exists()
with socket.socket() as check:
check.bind(('127.0.0.1', port))
def start():
nonlocal count
save()
log = open(root / f'serve-{len(processes)}.log', 'w+')
p = subprocess.Popen([binary, 'serve', '--config', str(config_path)], env=env, stdout=log, stderr=log)
processes.append((p, log))
deadline = time.monotonic() + 12
while time.monotonic() < deadline:
assert p.poll() is None, 'server exited during bootstrap'
try:
c = http.client.HTTPConnection('127.0.0.1', port, timeout=1)
c.request('GET', '/ready')
response = c.getresponse(); response.read(); c.close()
if response.status == 200:
break
except (OSError, http.client.HTTPException):
pass
time.sleep(.03)
else:
raise AssertionError('bootstrap never ready')
assert marker.read_text().splitlines() == [config['native_model']['output'], str(source / 'model.gguf')]
p.terminate(); p.wait(timeout=8)
count += 1
try:
report = json.loads(run('check-config').stdout)
assert report['native_model_configured'] and not report['native_model_verified'] and not report['tokenizer_validated']
assert not requests and not source.exists() and not output.exists()
# Malformed other asset manifest must fail before any source acquisition.
bad = root / 'bad.json'; bad.write_text('{}')
config['assets'] = [{'manifest': str(bad), 'directory': str(root / 'aux')}]
gated_failure()
assert not requests
del config['assets']
start() # Empty node -> download -> exact conversion -> synthetic worker -> ready.
assert requests == ['/model.gguf']
before = {str(p.relative_to(output)): p.read_bytes() for p in output.rglob('*') if p.is_file()}
server.shutdown(); server.server_close(); thread.join()
report = json.loads(run().stdout)
assert report['native_model_prepared'] and not report['worker_started']
start() # Offline startup, no regeneration.
assert requests == ['/model.gguf']
assert before == {str(p.relative_to(output)): p.read_bytes() for p in output.rglob('*') if p.is_file()}
# Each invalid cache must fail before listener/worker and preserve the damaged version.
dense = output / 'dense.bin'; original = dense.read_bytes()
dense.write_bytes(bytes([original[0] ^ 1]) + original[1:])
gated_failure(); assert dense.read_bytes() != original
dense.write_bytes(original)
extra = output / 'extra'; extra.write_text('unexpected'); gated_failure(); extra.unlink()
receipt = output / 'receipt.json'; raw = receipt.read_bytes()
r = json.loads(raw); r['sources']['model.gguf']['sha256'] = '0' * 64
receipt.write_text(json.dumps(r)); gated_failure(); receipt.write_bytes(raw)
dense.unlink(); dense.symlink_to(gguf); gated_failure(); dense.unlink(); dense.write_bytes(original)
raw_source = (source / 'model.gguf').read_bytes()
(source / 'model.gguf').write_bytes(b'bad'); gated_failure(); (source / 'model.gguf').write_bytes(raw_source)
lock = open(root / '.pack-v1.native-model-lock', 'a+')
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
gated_failure(); lock.close()
# New version failure must never mutate previous validated output.
wrong = root / 'wrong.gguf'; fixture.write_gguf(wrong, fixture.fixtures(), architecture='unsupported')
source2 = root / 'sources-v2'; source2.mkdir(); (source2 / 'model.gguf').write_bytes(wrong.read_bytes())
manifest2 = root / 'manifest-v2.json'; m = json.loads(manifest.read_text())
m['files'][0].update(size=wrong.stat().st_size, sha256=hashlib.sha256(wrong.read_bytes()).hexdigest())
manifest2.write_text(json.dumps(m))
initial = copy.deepcopy(config)
config['native_model'].update(manifest=str(manifest2), source_dir=str(source2), output=str(root / 'pack-v2'))
gated_failure(); assert not (root / 'pack-v2').exists()
assert before == {str(p.relative_to(output)): p.read_bytes() for p in output.rglob('*') if p.is_file()}
config = copy.deepcopy(initial)
config['native_model']['output'] = str(source / 'inside'); gated_failure()
config = copy.deepcopy(initial)
alias = root / 'pack-alias'; alias.symlink_to(output, target_is_directory=True)
config['native_model']['source_dir'] = str(alias / 'new-sources')
gated_failure()
assert not (output / 'new-sources').exists()
alias.unlink()
config = copy.deepcopy(initial)
config['engine']['args'].append('--native'); gated_failure()
config = copy.deepcopy(initial)
config['engine']['tokenizer_dir'] = str(output / 'tokenizer'); gated_failure()
config = copy.deepcopy(initial)
del config['engine']; run(ok=False)
print(json.dumps({'status': 'passed', 'scenarios': count, 'real_model': False, 'worker': 'synthetic', 'gpu_used': False}))
finally:
for p, log in processes:
if p.poll() is None:
p.kill(); p.wait(timeout=5)
log.close()
if thread.is_alive():
server.shutdown(); server.server_close(); thread.join()
if __name__ == '__main__':
main()