#!/usr/bin/env python3 """Independent execution of return #1372's served package (route 116/118, the arrangement step). WHAT THIS ESTABLISHES (one claim, finite): Rerunning the package as served reproduces its published row artifact byte for byte, and the five published K* custody gates the step requires pass again. METHOD: `rerun` -- this runs the AUTHOR'S OWN supplied scripts from a clean directory rebuilt from the served artifacts. It is NOT an independent implementation: the algorithms are the author's. The expected answer was visible to this worker (it is on the return), which is recorded in the output so a reviewer can weigh it. WHAT IT DOES NOT ESTABLISH: nothing about the correctness of the algorithms themselves, nothing about the route's mathematical claims, and nothing about the P=30030 class (that scan is not run here; it needs a windowed scan over 6.47e9 slots). USAGE python3 rerun-1372.py --dir [--skip-composite] Exit codes: 0 all checks pass, 3 a check failed, 2 the directory is incomplete. Every file is read as served; nothing is fetched and no network is used. Deterministic apart from the artifact timings the author's own script prints to stdout (see note in the output). """ import argparse import hashlib import json import os import subprocess import sys # sha256 of the served target artifact, arrangement-composite.json, as served by return #1372 and # as reproduced byte for byte on 2026-09-22 by the executing run. TARGET_SHA = "3a04416d0add73883cd62d7afaf25af7f144c9bcac7fbbe2153f2c9d22f87ba9" # The five published custody gates (route 112/98/100/117 lineage), as the author's GATES list holds # them: (base, killer set, expected K*). Kept here so the plan is auditable without the module. GATES = [(30, (7, 11, 19), 9), (390, (7, 11, 19), 8), (30, (7, 11, 13, 19), 10), (30, (7, 13, 19, 23), 12), (330, (7, 13, 19, 23), 10)] REQUIRED = ["killer-marginal.py", "arrangement-stats.py", "prereg-arrangement.md", "prereg-arrangement-sha.txt", "compose-2e6.json", "rows-r5.json", "margin-p30030.json", "arrangement-composite.json"] def sha256(path): h = hashlib.sha256() with open(path, "rb") as fh: for chunk in iter(lambda: fh.read(1 << 20), b""): h.update(chunk) return h.hexdigest() def run(args, cwd, timeout=1800): p = subprocess.run([sys.executable, "-u"] + args, cwd=cwd, capture_output=True, text=True, timeout=timeout) return p.returncode, p.stdout, p.stderr def main(): ap = argparse.ArgumentParser() ap.add_argument("--dir", required=True) ap.add_argument("--skip-composite", action="store_true") ap.add_argument("--target-sha", default=TARGET_SHA) a = ap.parse_args() missing = [f for f in REQUIRED if not os.path.exists(os.path.join(a.dir, f))] if missing: print(json.dumps({"ok": False, "stage": "incomplete directory", "missing": missing}, indent=1)) return 2 def block(marker, text): """The first JSON object that starts at `marker`. Match the marker, never '{': the gate lines carry set notation ('K*(30 ,{7,11,19})'), so a brace search finds the wrong one.""" i = text.find(marker) if i < 0: return None try: obj, _ = json.JSONDecoder().raw_decode(text[i:]) return obj except Exception: return None checks = [] # 1. the five published custody gates, through the author's module. rc, out, err = run(["killer-marginal.py", "--mode", "gates"], a.dir, timeout=600) gates = block('{\n "mode"', out) checks.append({"name": "five custody gates", "exit_code": rc, "stderr_tail": err[-400:] if rc else "", "observed": gates.get("rows") if gates else None, "pass": rc == 0 and bool(gates and gates.get("all_pass"))}) if not a.skip_composite: rc, out, err = run(["arrangement-stats.py", "--mode", "composite", "--cap", "2000000"], a.dir, timeout=1800) # the author's script writes progress+timing to stdout, then two JSON objects; take them # by shape rather than by line number so a progress line cannot shift the parse. custody = block('{\n "rows"', out) claims = block('{\n "claims"', out) art = os.path.join(a.dir, "arrangement-composite.json") got = sha256(art) if os.path.exists(art) else None checks.append({"name": "composite rerun reproduces the served artifact", "exit_code": rc, "stderr_tail": err[-400:] if rc else "", "artifact_sha256": got, "expected_sha256": a.target_sha, "byte_identical": got == a.target_sha, "custody_all_match": bool(custody and custody.get("all_match")), "must_hold_violations": (claims or {}).get("must_hold_violations"), "pass": rc == 0 and got == a.target_sha and bool(custody and custody.get("all_match"))}) checks.append({"note": "stdout of the author's script carries per-500-row progress with " "timings, so the stdout stream is not byte-reproducible; the file " "artifact is. This is the defect already recorded in the return's " "own file_notes."}) ok = all(c.get("pass") for c in checks if "pass" in c) print(json.dumps({"ok": ok, "method": "rerun", "expected_answer_visible": True, "checks": checks, "does_not_establish": ["the correctness of the author's algorithms", "the route's mathematical claims", "the P=30030 class (scan not run)"]}, indent=1, sort_keys=True)) return 0 if ok else 3 if __name__ == "__main__": sys.exit(main())