#!/usr/bin/env python3 """Check native Floating Islands owner identity and hashes at W1/W8/W12.""" from __future__ import annotations import json import re import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l140/determinism" DATA = ROOT / "Standalone/data/owner_world.json" STAMP = "6205e6c180ef32c41792dc3e0d8bf443a96df41974f40334af4bf3a157ab88da" BINARIES = { "clang": ROOT / "Saved/Linux/l140/bin/VoxelForgeCoreHeadless-l140-clang", "gcc": ROOT / "Saved/Linux/l140/bin/VoxelForgeCoreHeadless-l140-gcc", } CAMERA = "25.836914,3.199219,-737.000000,0,0" STAMP_RE = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=([0-9a-f]+)$", re.M) HASH_RE = re.compile( r"^\[Pipeline(?:FullDetailHash|WholeViewHash|MaterialHash|LODHash|ExactQueryHash)\].*$", re.M) NATIVE_FI = re.compile( r"^\[DensityDispatch\] strate=1 generator=FloatingIslands " r"recipe=FloatingIslands\.ClusterField version=10 " r"bound_path=FloatingIslands-native adapter=FFloatingIslandFieldAdapter$", re.M) FI_RECIPE_HASH = re.compile(r"^\[FloatingIslandWorldAssembly\].*recipe_hash=([0-9a-f]+) status=PASS$", re.M) FI_CLEARANCE = re.compile(r"^\[FloatingIslandPassageClearance\].*status=PASS$", re.M) FI_ROUTE_AUDIT = re.compile(r"^\[FloatingIslandRouteAudit\].*status=PASS$", re.M) def main() -> int: if not DATA.is_file() or any(not path.is_file() for path in BINARIES.values()): raise SystemExit("missing L140 Clang/GCC determinism binary or owner fixture") OUT.mkdir(parents=True, exist_ok=True) rows: list[dict[str, object]] = [] reference_hashes: list[str] | None = None reference_identity: str | None = None for compiler, binary in BINARIES.items(): for workers in (1, 8, 12): name = f"native-owner-fi-{compiler}-w{workers}" log, layout = OUT / f"{name}.log", OUT / f"{name}.json" command = ["taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(binary), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", f"--workers={workers}", "--clip-radius=3", "--max-clip-level=8", "--max-level=0", f"--camera={CAMERA}", "--stream-hash", "--force-generate", "--seed=0", "--recipe=surface-world", "--native-owner-fi", "--render-distance-chunks=0", "--density-dispatch-report", f"--resolved-layout-output={layout}"] started = time.monotonic() with log.open("w", encoding="utf-8") as output: proc = subprocess.run(command, cwd=ROOT, stdout=output, stderr=subprocess.STDOUT, check=False, timeout=1740) content = log.read_text(encoding="utf-8", errors="replace") stamp = STAMP_RE.search(content) hashes = HASH_RE.findall(content) current_layout = json.loads(layout.read_text(encoding="utf-8")) if layout.is_file() else {} identity = current_layout.get("stable_identity") native_ok = bool(NATIVE_FI.search(content)) plan_ok = ("[FloatingIslandRouteAudit]" in content and "[FloatingIslandPassageClearance]" in content) recipe_hash = FI_RECIPE_HASH.search(content) clearance = FI_CLEARANCE.search(content) route_audit = FI_ROUTE_AUDIT.search(content) passed = (proc.returncode == 0 and stamp is not None and stamp.group(1) == STAMP and len(hashes) >= 4 and native_ok and plan_ok and recipe_hash is not None and clearance is not None and route_audit is not None and bool(identity)) if reference_hashes is None and passed: reference_hashes, reference_identity = hashes, identity else: passed = passed and hashes == reference_hashes and identity == reference_identity row = {"compiler": compiler, "workers": workers, "exit": proc.returncode, "source_stamp": stamp.group(1) if stamp else None, "hash_lines": hashes, "layout_identity": identity, "native_fi_dispatch": native_ok, "native_plan_audits": plan_ok, "floating_island_recipe_hash": recipe_hash.group(1) if recipe_hash else None, "passage_clearance_line": clearance.group(0) if clearance else None, "route_audit_line": route_audit.group(0) if route_audit else None, "passed": bool(passed), "elapsed_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT)), "layout": str(layout.relative_to(ROOT))} rows.append(row) print("[L140DeterminismRun] " + json.dumps(row, sort_keys=True), flush=True) (OUT / "runs-partial.json").write_text(json.dumps(rows, indent=2) + "\n") if not passed: (OUT / "summary.json").write_text(json.dumps({"status": "FAIL", "runs": rows}, indent=2) + "\n") raise SystemExit(f"native owner determinism mismatch; see {log}") summary = {"status": "PASS", "source_stamp": STAMP, "layout_identity": reference_identity, "runs": rows} (OUT / "summary.json").write_text(json.dumps(summary, indent=2) + "\n") (ROOT / "Standalone/Research/WorldAssemblerM3/Linux140/baselines").mkdir(parents=True, exist_ok=True) (ROOT / "Standalone/Research/WorldAssemblerM3/Linux140/baselines/native-owner-fi-seed0.json").write_text( json.dumps(summary, indent=2) + "\n", encoding="utf-8") print(f"[L140DeterminismSummary] runs={len(rows)} source_stamp={STAMP} status=PASS") return 0 if __name__ == "__main__": raise SystemExit(main())