#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Independent checker for job #4545 (route 148 step check, second-and-third serve). Re-derives, from the shipped served bytes only (no network, no credential): A. the assigned step is byte-identical across five records (brief, route-148 stored next_step, and research.next_step of #1837 / #2019 / #2026), i.e. nothing on the record has moved it; B. route 148's job history: 4527 and 4537 are the two prior step checks (both promising, both copying the step verbatim), the single pursuit #4180 expired without a return, and 4545 is the third step check of the same step -- the queue loop; C. the comparison window rebuilt over a public id range (1838..2070), routeless returns included: no return in it implements or tests the step; D. the pinned sahdated 1.1.2 producer guards by a 25-line text window, has no ast call inside producers, has no 'unresolved' status and no 'hashed-artifact' class; E. test_recognition_2940.py excludes the LIMIT case from passed/total and from the exit predicate, and test-v112.json records that case as failing while the suite is 12/12; F. #1837's own population.json: 28 of 41 real file writes unguarded = 68.3 % against the step's 20 % failure threshold; G. NEW: the step's named success clause for reader_table_2940.py cannot be produced by the step's own resolution rule -- all three of its "3 deliberate undated dumps" pass a non-literal first argument (one a for-target name bound twice, two a call), and the pinned 1.1.2 already calls two of the three `guarded`; H. NEW: the served job2830 fixture is four files, not the six of #1541's verdict, so the step's job2830 clause names a tree that is on no return; I. the four hashed JSON outputs are byte-pinned by return #1837 and carry no top-level instant key, so a typed exemption can be machine-checked against (return, sha256); J. the replacement next_step is well formed and is not the old step. stdlib + numpy + sympy. Exit 0 iff every check passes. Writes check.out.json. """ import ast import glob import hashlib import importlib.util import io import json import os import re import sys import numpy as np import sympy HERE = os.path.dirname(os.path.abspath(__file__)) OUT = [] FAILS = [] def P(ok, label, detail=""): OUT.append({"check": label, "pass": bool(ok), "detail": str(detail)[:400]}) if not ok: FAILS.append(label) print(("%s %s" % ("PASS" if ok else "FAIL", label)) + (" [%s]" % str(detail)[:200] if detail and not ok else "")) def find(name): for cand in (os.path.join(HERE, name), os.path.join(HERE, "served", name)): if os.path.exists(cand): return cand raise SystemExit("input not found: %s" % name) def load(name): with open(find(name), "rb") as fh: raw = fh.read() return raw, json.loads(raw) def sha_of(name): with open(find(name), "rb") as fh: return hashlib.sha256(fh.read()).hexdigest() def canon(obj): return json.dumps(obj, sort_keys=True, separators=(",", ":")) CONST_INSTANT = ("covered_at", "observed_at", "measured_at", "generated_at", "walked_at", "stamped_at", "recorded_at", "written_at", "at") def main(): # ---------------------------------------------------------------- A. step identity step_rec = json.loads(open(find("step.json"), encoding="utf-8").read()) step = step_rec["step"] old = json.loads(open(find("step4537.json"), encoding="utf-8").read())["step"] _, route = load("route-148.json") _, r1837 = load("return-1837.json") _, r2019 = load("return-2019.json") _, r2026 = load("return-2026.json") _, r1541 = load("return-1541.json") ref = canon(step) ref_sha = hashlib.sha256(ref.encode()).hexdigest() P(canon(old) == ref, "A1 brief step == the previous check's shipped step (#4537 step.json)") P(canon(route["next_step"]) == ref, "A2 brief step == route-148 stored next_step (revision %s)" % route.get("revision")) P(canon(r1837["research"]["next_step"]) == ref, "A3 brief step == the step-setter #1837's research.next_step") P(canon(r2019["research"]["next_step"]) == ref, "A4 brief step == #2019's research.next_step (its copy-forward)") P(canon(r2026["research"]["next_step"]) == ref, "A5 brief step == #2026's research.next_step (its copy-forward)") P(ref_sha == "29dc60cd368a34737cbf532f428d88ee632d5a44921596462743e549d6ff776e", "A6 every copy hashes to one string (canonical sha256)", ref_sha) # ---------------------------------------------------------------- B. the loop jobs = {str(j["id"]): j for j in (route.get("jobs") or [])} P(str(route.get("revision")) == "5" and route.get("state") == "active" and str(route.get("last_return_id")) == "2026", "B1 route 148 is revision 5, active, last_return_id 2026") P([j for j in ("4527", "4537", "4545") if j in jobs and jobs[j]["research_stage"] == "first_look" and jobs[j]["type"] == "explore"] == ["4527", "4537", "4545"], "B2 jobs 4527/4537/4545 are three consecutive first_look explore step checks on route 148") P(jobs.get("4180", {}).get("status") == "expired" and jobs.get("4180", {}).get("research_stage") == "pursue", "B3 the one pursue job for this step (4180) expired without a return", jobs.get("4180")) P(str(r2019.get("job_id")) == "4527" and r2019["research"]["outcome"] == "promising" and canon(r2019["research"]["next_step"]) == ref, "B4 #2019 (job 4527) filed promising and copied the step verbatim") P(str(r2026.get("job_id")) == "4537" and r2026["research"]["outcome"] == "promising" and canon(r2026["research"]["next_step"]) == ref, "B5 #2026 (job 4537) filed promising and copied the step verbatim") P(jobs.get("4545", {}).get("status") == "assigned", "B6 job 4545 is the third step check of the same step: the loop") # ---------------------------------------------------------------- C. window _, manifest = load("fetch_manifest.json") req = {m["path"] for m in manifest if m["path"].startswith("return-")} got = {m["path"] for m in manifest if m["path"].startswith("return-") and "error" not in m} expect = {"return-%d.json" % i for i in range(1838, 2071)} P(expect <= req, "C1 every id 1838..2070 was requested (%d paths)" % len(expect)) absent = sorted(int(p[7:-5]) for p in expect - got) P(set(absent) == {1858, 1866, 1870, 1938, 1939, 1961, 1965, 1999, 2000, 2030} | set(range(2032, 2071)), "C2 the server-side absences are recorded, not invented (%d)" % len(absent), absent) P(max(int(p[7:-5]) for p in got) == 2031, "C3 live head of the window is #2031") scan = json.loads(open(find("scan.json"), encoding="utf-8").read()) cut = scan["cutoff"] P(scan["cut_owner"] == 1837 and cut == r1837["created_at"], "C4 the scan cut is the step-setter #1837's own created_at") rows = scan["rows"] P(len(rows) == 184, "C5 184 returns are recorded strictly after #1837", len(rows)) corp = [json.loads(l) for l in open(find("corpus_after.jsonl"), encoding="utf-8") if l.strip()] P(np.array_equal(np.array([c["id"] for c in corp], dtype=np.int64), np.array([r["id"] for r in rows], dtype=np.int64)) and len(corp) == len(rows), "C6 corpus_after.jsonl and scan.json cover the same window in the same order") P(all(c["return_sha256"] == r["return_sha256"] for c, r in zip(corp, rows)), "C7 every corpus row carries the fetched record's own raw-byte sha256") P(sorted(r["id"] for r in rows if str(r["route"]) == "148") == [2019, 2026], "C8 the only route-148 returns in the window are the two step checks #2019/#2026") strong = sorted(r["id"] for r in rows if r["strong"]) P(strong == [2019, 2026], "C9 the only returns using >=3 of the step's own words are " "#2019 and #2026 (both step checks)", strong) hits_rows = [r for r in rows if r["attach_hits"]] P([r["id"] for r in hits_rows] == [2026], "C10 the only attachment-name hits in the window belong to #2026, the previous step " "check itself", [r["id"] for r in hits_rows]) pin1837 = {f["name"]: f["sha256"] for f in r1837["files"]} rep26 = [f for f in (r2026.get("files") or []) if f["name"] in pin1837] P(len(rep26) == 8 and all(f["sha256"] == pin1837[f["name"]] for f in rep26), "C11 every one of #2026's 8 re-shipped step files is byte-identical to #1837's own " "published sha256 (a re-ship, not an implementation)", len(rep26)) post = sorted(r["id"] for r in rows if r["created_at"] > r2026["created_at"]) P(post == [2027, 2028, 2029, 2031], "C12 the post-#2026 window is complete and read: #2027/#2028/#2029/#2031 " "(#2030 is a 404)", post) P(all(not r["strong"] and not r["attach_hits"] for r in rows if r["id"] in (2027, 2028, 2029, 2031)), "C13 no return recorded after the previous step check answers the step") # ---------------------------------------------------------------- D. pinned 1.1.2 v112_sha = sha_of("f1837_sahdated-1.1.2.py") pin = {f["name"]: f["sha256"] for f in r1837["files"]} P(v112_sha == pin["sahdated-1.1.2.py"] == "4cf3d5f1302576469d6422e54eb8ab74b5f9c2f527b11a2a3dc06fc31dc9f43a", "D1 the pinned 1.1.2 source matches return #1837's own published sha256", v112_sha) src = open(find("f1837_sahdated-1.1.2.py"), encoding="utf-8").read() tree = ast.parse(src) prod = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == "producers") ast_calls = [n.func.attr for n in ast.walk(prod) if isinstance(n, ast.Call) and isinstance(n.func, ast.Attribute) and isinstance(n.func.value, ast.Name) and n.func.value.id == "ast"] P(not ast_calls, "D2 no `ast.` call inside producers (the dumped object is never resolved)", ast_calls) P("def producers(paths, exempt=None, guard_window=25)" in src and "join(code[max(0, n - guard_window):n])" in src, "D3 the guard evidence is a 25-line text window `near`") P('"guarded" if (routed or keyed) else "unguarded"' in src, "D4 the verdict is a window boolean, not the dumped object") P('for s in ("guarded", "routed", "not-a-write", "exempt", "unguarded", "unreadable")' in src and '"unresolved"' not in src, "D5 the status vocabulary is exactly the six names and carries no `unresolved` " "status (the word occurs only in prose)") P("hashed-artifact" not in src and "hashed_artifact" not in src, "D6 `hashed-artifact` occurs in no line of the pinned 1.1.2 source") _, exl = load("f1541_sahdated-write-exemptions.json") P(all(set(e) == {"path", "contains", "why"} for e in exl["exempt"]), "D7 every 1.1.2 exemption record carries only path/contains/why") # ---------------------------------------------------------------- E. harness tsrc = open(find("f1837_test_recognition_2940.py"), encoding="utf-8").read() ttree = ast.parse(tsrc) calls = [n for n in ast.walk(ttree) if isinstance(n, ast.Call) and isinstance(n.func, ast.Name) and n.func.id == "test"] P(len(calls) == 13, "E1 test_recognition_2940.py defines 13 test() cases", len(calls)) P(tsrc.count('r["kind"] != "LIMIT"') == 2 and 'sum(r["pass"] for r in results if r["kind"] != "LIMIT")' in tsrc and 'sys.exit(0 if out["passed"] == out["total"] else 1)' in tsrc, "E2 passed/total AND the exit predicate both filter `kind != LIMIT` (two places)") P('st.get("h_window_leak.py") == ["unguarded"]' in tsrc, "E3 the LIMIT case asserts the leak is FIXED (site must be unguarded)") P('if r["kind"] != "LIMIT"' in tsrc and 'known_limits' in tsrc, "E4 the LIMIT verdict is reported out-of-band under known_limits") _, tv112 = load("f1837_test-v112.json") lim = tv112["known_limits"] P(tv112["passed"] == 12 and tv112["total"] == 12 and list(lim.values()) == [["guarded"]] and tv112["failed_gap"] == [] and tv112["failed_control"] == [], "E5 test-v112.json records 12/12 with the LIMIT case `guarded`, i.e. FAILING", lim) _, tv111 = load("f1837_test-v111.json") P(tv111["passed"] == 7 and tv111["total"] == 12 and len(tv111["failed_gap"]) == 5, "E6 test-v111.json records 7/12 with exactly the 5 GAP tests failing") # ---------------------------------------------------------------- F. population price _, pop = load("f1837_population.json") nc = pop["new_counts"] P(pop["files"] == 21 and nc == {"exempt": 0, "guarded": 5, "not-a-write": 33, "routed": 8, "unguarded": 28, "unreadable": 0}, "F1 population.json: 21 served scripts; guarded 5 / routed 8 / not-a-write 33 / " "unguarded 28") real = nc["guarded"] + nc["routed"] + nc["unguarded"] share = sympy.Rational(nc["unguarded"], real) P(real == 41 and share == sympy.Rational(28, 41) and share > sympy.Rational(1, 5), "F2 baseline unresolved share %s = %.1f%% > the step's 20%% failure threshold" % (share, float(share) * 100)) pref = sorted({c["file"].split("/")[0] for c in pop["changed"]}) P(pref == ["f1447", "f1453", "f1455", "f1541", "f1549"], "F3 the 21-script population is built from served return attachments (%s)" % pref) ids_new = sorted(r["id"] for r in rows if r["id"] in (2026,)) P(ids_new == [2026], "F4 the price in F2 is #1837's own recorded measurement, not a rerun") # ---------------------------------------------------------------- G. NEW: the 3 sites rsrc = open(find("f1837_reader_table_2940.py"), encoding="utf-8").read() rtree = ast.parse(rsrc) dumps = {} for n in ast.walk(rtree): if isinstance(n, ast.Call) and isinstance(n.func, ast.Attribute) \ and n.func.attr in ("dump", "dumps") and isinstance(n.func.value, ast.Name) \ and n.func.value.id == "json" and n.args: dumps[n.lineno] = n.args[0] P(sorted(dumps) == [37, 50, 68, 95], "G1 the served reader_table_2940.py has exactly 4 json.dump(s) sites", sorted(dumps)) a37, a50, a68 = dumps[37], dumps[50], dumps[68] P(isinstance(a37, ast.Name) and a37.id == "rec" and isinstance(a50, ast.Call) and isinstance(a68, ast.Call) and isinstance(a50.func, ast.Name) and a50.func.id == "strip" and isinstance(a68.func, ast.Name) and a68.func.id == "strip", "G2 the three json.dump sites pass a name (`rec`) and two calls (`strip(...)`)") forbind = [n for n in ast.walk(rtree) if isinstance(n, ast.For) and any(isinstance(t, ast.Name) and t.id == "rec" for t in ast.walk(n.target))] assign_rec = [n for n in ast.walk(rtree) if isinstance(n, ast.Assign) and any(isinstance(t, ast.Name) and t.id == "rec" for t in n.targets)] P(forbind and not assign_rec, "G3 `rec` is bound only by a for-target (two different records in two iterations), " "never by an assignment", {"for_lines": [n.lineno for n in forbind], "assign_lines": [n.lineno for n in assign_rec]}) P('for tag, rec in (("dated", base), ("stripped", strip(base))):' in rsrc, "G4 the two loop bindings are one DATED record and one STRIPPED (undated) record") spec = importlib.util.spec_from_file_location("sd112", find("f1837_sahdated-1.1.2.py")) sd = importlib.util.module_from_spec(spec) spec.loader.exec_module(sd) rep = sd.producers([find("f1837_reader_table_2940.py")]) got_st = {s["line"]: s["status"] for s in rep["sites"]} P(got_st == {37: "guarded", 50: "guarded", 68: "unguarded", 95: "not-a-write"}, "G5 the pinned 1.1.2 calls only 1 of the 3 named sites unguarded (2 are `guarded`)", got_st) P(rep["counts"]["guarded"] == 2 and rep["counts"]["unguarded"] == 1, "G6 the same file's three undated dumps get INCONSISTENT window verdicts") P(not any(isinstance(d, ast.Dict) for d in (a37, a50, a68)) and not any( isinstance(n, ast.Assign) and isinstance(n.value, ast.Dict) and any(isinstance(t, ast.Name) and t.id == "rec" for t in n.targets) for n in ast.walk(rtree)), "G7 none of the three first arguments is a dict literal, so the step's own rule " "('dict literal or last assignment in the enclosing scope') yields `unresolved` for " "all three, never `unguarded`") # ---------------------------------------------------------------- H. NEW: job2830 cs_sha = sha_of("f1541_census-selftest.py") pin1541 = {f["name"]: f["sha256"] for f in r1541["files"]} P(cs_sha == exl["source_sha256"]["census-selftest.py"] == pin1541["census-selftest.py"] == "f103fedf669f317e4ef4e2119e54a43cb6dd159cd0fa3c5693c34ce7cbc784ac", "H1 the served census-selftest.py is exactly the file the exemption list pins " "(f103fedf...)", cs_sha) csl = open(find("f1541_census-selftest.py"), encoding="utf-8").read().split("\n") lines_ok = all(e["contains"] in csl[e["line"] - 1] for e in exl["exempt"] if "line" in e) P(all(e["path"] == "job2830/census-selftest.py" for e in exl["exempt"]) and len(exl["exempt"]) == 8, "H2 all 8 published job2830 exemptions name census-selftest.py") P(lines_ok, "H3 every exemption entry with a line number matches the served bytes there") body = [e for e in exl["exempt"] if "contains" in e] P(len(exl["exempt"]) == 8 and len(body) == 8 and all(any(e["contains"] in l for l in csl) for e in body), "H4 all eight exemption `contains` strings occur in the served bytes", len(body)) pub_py = sorted(f["name"] for f in r1541["files"] if f["name"].endswith(".py")) P(pub_py == ["accepted-text-published.py", "census-selftest.py", "census.py", "sahdated-1.1.1-served.py"], "H5 #1541 published exactly 4 .py files (the job2830 fixture it names has 6)", pub_py) v112t = open(find("f1837_producers-job2830-v112.txt"), encoding="utf-8").read() v111t = open(find("f1837_producers-job2830-v111.txt"), encoding="utf-8").read() P("21 write site(s) in 4 file(s): exempt 5, guarded 3, not-a-write 9, routed 4" in v112t and "VERDICT closed" in v112t, "H6 the published 1.1.2 run reaches 21 sites in 4 files, VERDICT closed") P("25 write site(s) in 4 file(s): exempt 9, guarded 16" in v111t, "H7 the published 1.1.1 run reaches 25 sites in the same 4 files") P("28 write sites in 6 files" in r1541["report_md"], "H8 #1541's own verdict is 28 write sites in 6 files -- a tree the served record does " "not carry") P("job2830 = the 4 scripts #1541 published" in r1837["report_md"], "H9 #1837 already had to reinterpret the clause as the 4 published scripts") # ---------------------------------------------------------------- I. hashed artifacts four = ["population.json", "reader-table.json", "test-v111.json", "test-v112.json"] ok_sha, ok_key = True, True for name in four: served_name = "f1837_" + name if sha_of(served_name) != pin[name]: ok_sha = False doc = json.loads(open(find(served_name), encoding="utf-8").read()) if any(k in doc for k in CONST_INSTANT): ok_key = False P(ok_sha, "I1 the four hashed JSON outputs match return #1837's published sha256 pins") P(ok_key, "I2 none of the four carries a top-level instant key (the " "byte-for-byte conflict the hashed-artifact class exists to close)") P(all(name in pin for name in four) and all(isinstance(pin[name], str) and len(pin[name]) == 64 for name in four), "I3 every one of the four is machine-checkable as (return #1837, published sha256)") # ---------------------------------------------------------------- J. replacement step new = json.loads(open(find("newstep.json"), encoding="utf-8").read())["step"] P(canon(new) != ref, "J1 the shipped next_step is a REPLACEMENT, not the old step copied") P(isinstance(new.get("budget_hours"), (int, float)) and 0.1 <= new["budget_hours"] <= 4, "J2 replacement budget_hours in 0.1..4", new.get("budget_hours")) P(len(new.get("question", "")) <= 1000 and len(new.get("method", "")) <= 4000 and len(new.get("success", "")) <= 2000 and len(new.get("failure", "")) <= 2000, "J3 replacement field lengths within the API limits", [len(new.get(k, "")) for k in ("question", "method", "success", "failure")]) P(isinstance(new.get("compute"), dict) and all(k in new["compute"] for k in ("ram_gb", "disk_gb", "cpu_hours")), "J4 replacement carries a compute object") P(new.get("required_tools") == ["python"] and new.get("required_sources") == ["return-endpoint", "files-endpoint"], "J5 replacement keeps the step's tool/source requirements") P(("passed=13/total=13" in new["success"] or "13/13" in new["success"]) and "unresolved" in new["success"] and "reader_table_2940.py" in new["success"] and "unguarded" in new["failure"] and "hashed-artifact" in new["method"], "J6 the replacement disambiguates the three unreachable clauses the old step left") # ---------------------------------------------------------------- summary res = {"checks": OUT, "passed": len(OUT) - len(FAILS), "total": len(OUT), "failed": FAILS, "step_sha256": ref_sha, "window": {"n_after_1837": len(rows), "head": 2031, "post_2026": post}} with open(os.path.join(HERE, "check.out.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(res, fh, indent=1, sort_keys=True) print("%d/%d checks passed" % (res["passed"], res["total"])) return 0 if not FAILS else 1 if __name__ == "__main__": sys.exit(main())