#!/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: the artifact and the author's stdout are both compared byte for byte against pinned digests. """ 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" # sha256 of the author's `--mode composite` stdout under the REPAIRED arrangement-stats.py # (return #1372 revision, script sha 3c56ea89...). The repaired stream is the artifact only # -- two JSON documents of counts and verdicts, no paths and no timings. # # NEWLINES: this digest is taken over the stream with newlines normalized to LF, which is # exactly what subprocess text=True hands us, so it is the same number on a Windows and a # POSIX worker. A digest of the RAW bytes would not be portable: measured here, the served # pre-repair stream was 175 CRLFs on Windows and would have hashed differently on Linux. # The repaired revision ALSO writes stdout LF-only, so on both platforms its raw bytes now # equal this normalized form -- the normalization is belt and braces, not a crutch. # # The pre-repair bytes printed per-500-row elapsed seconds into this same stream, which is # why they had no digest at all; performing this comparison is what the repair buys. EXPECTED_CHILD_STDOUT_SHA = "5ac372df87986407b3b66bcd353a8fdb707ffb2e34570bfd56308320d528cec0" # 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) ap.add_argument("--expect-stdout", default=EXPECTED_CHILD_STDOUT_SHA, help="pinned sha256 of the author's composite stdout; pass `none` to " "compare only the file artifact (the pre-repair behaviour)") a = ap.parse_args() if a.expect_stdout == "none": a.expect_stdout = None # older, weaker check: the file artifact alone 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 two JSON objects on stdout (progress and timing go to # stderr in the repaired revision); take them by shape rather than by line number so a # stray 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 child_stdout_sha = hashlib.sha256(out.encode()).hexdigest() script_sha = sha256(os.path.join(a.dir, "arrangement-stats.py")) stdout_ok = a.expect_stdout is None or child_stdout_sha == a.expect_stdout checks.append({"name": "composite rerun reproduces the served artifact", "exit_code": rc, "stderr_tail": err[-400:] if rc else "", "script_sha256": script_sha, "artifact_sha256": got, "expected_sha256": a.target_sha, "byte_identical": got == a.target_sha, "stdout_sha256": child_stdout_sha, "expected_stdout_sha256": a.expect_stdout, "stdout_byte_identical": stdout_ok, "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 stdout_ok and bool(custody and custody.get("all_match"))}) checks.append({"note": "The repaired revision moves progress and elapsed seconds to " "stderr, so BOTH the file artifact and the stdout stream are " "compared above. Under the served (pre-repair) bytes the stdout " "digest was not reproducible and only the file artifact could be " "compared; passing --expect-stdout none restores that older, " "weaker check."}) 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())