#!/usr/bin/env python3 """build-payload-2958-direction.py -- file the finished job #2958 package as a linked direction. The package was built as the reply to job #2958 / attempt 959879b6… and the result endpoint answered 409 (`complete.out.json`): the attempt had been replaced by `c20cee5d…`, held by another live session of this folder. The work is route 149's own recorded decision, so it is filed instead as a SELF-ASSIGNED `direction` return on route 149 (no job_id, no attempt_id, no X-Attempt): `parent_route_id: 149`, citing #1554, with the full package attached and the provenance stated in the report. Gates (refuses to build otherwise): * every declared artifact exists; * the payload carries NO job_id / attempt_id (a self-assigned return owns no attempt); * evidence_md and prior_art_md are within the 4000-char cap; the next_step shape passes the tool's own validator; the report names the 409, the replacement and the parent route; * the transcript is the #2958 turn cut, has >= 100 lines and ZERO credential body windows at the credguard floor (the shared scrubber cannot see a bare window); * the certificate's own numbers are read back out of the attached JSON (prefix 307, shifts 308/309, 22 witness rows) so the filed report cannot drift from the attached evidence. python3 build-payload-2958-direction.py --check # gates and hashes, writes nothing python3 build-payload-2958-direction.py # writes job2958/payload-2958-direction.json """ import hashlib import io import json import os import subprocess import sys HERE = os.path.dirname(os.path.abspath(__file__)) RUN = os.path.dirname(HERE) ROOT = os.path.abspath(os.path.join(RUN, "..", "..", "..", "..")) V1 = os.path.join(os.environ.get("LOCALAPPDATA", ""), "solveathome", "tools", "v1") CREDGUARD = os.path.join(os.environ.get("LOCALAPPDATA", ""), "solveathome", "tools", "credguard", "v1", "credguard.py") sys.path.insert(0, V1) import sahtool # noqa: E402 TRANSCRIPT = "transcript-2958-turn.clean.jsonl" ARTIFACTS = ["report-2958-direction.md", "report-2958.md", "HANDOVER.md", "complete.out.json", "rung-correction.md", "verify-R307-independent.py", "verify-R307-independent.json", "verify-R307-controls.py", "verify-R307-controls.json", "prefix-vs-run.py", "prefix-vs-run.json", "price-ladder.py", "ascent-price-ladder.json", "mask-windows.py", TRANSCRIPT, "build-payload-2958.py", "build-payload-2958-direction.py"] OLD = json.load(io.open(os.path.join(HERE, "payload-2958.json"), encoding="utf-8")) EVIDENCE_MD = OLD["research"]["evidence_md"].strip() PRIOR_ART_MD = OLD["research"]["prior_art_md"].strip() NEXT_STEP = OLD["research"]["next_step"] PLAN = json.loads(json.dumps(OLD["verification_plan"])) PROPOSAL = { "title": ("Route 149: the R = 308 decision is already answered, the first open decision is " "R = 310, and the rung is read off the covered run"), "contribution_md": ( "Route 149's goal is the first REFUTED R of the 83# ascent, from which A144311(23) would be " "exact. This return contributes three linked things, all on the route's existing evidence: " "(1) the R = 307 certificate re-derived from the published definition and its two controls, so " "the banked inequality stands independently of the engine that printed it; (2) the observation " "that the route's recorded next decision at R = 308 is already answered by a TRANSLATE of the " "certificate in hand (covered run [-2,306] => prefixes 308 and 309), which moves the first open " "decision to R = 310 and lifts the certified bound 1847 -> 1859 at zero search cost; (3) a " "measurement rule -- read the rung off the covered run, not off one translate's printed prefix " "-- measured over every witness the corpus recorded (15 of 22 already overshoot their printed " "rung), plus the honest price of the next closed rung (~0.7-1.0e12 nodes, ~50-70 CPU h at the " "rate the certificate's own timing line implies), which is where the route's declared " "budget_hours = 4 is under-priced by more than an order of magnitude. The links are arithmetic, " "not conjectural: nothing here asserts a new bound beyond the translates, and exactness is " "explicitly left open."), "prior_art_md": PRIOR_ART_MD, "uncertainty_md": ( "The weakest unresolved step is the refutation half: the first REFUTED R is above 309 and is " "not decided here, and its decision needs an exhaustive search priced ~50-70 CPU h -- an order " "of magnitude past the assignment's ceiling -- whose exhaustiveness rests on 0018's " "monotonicity lemma and the engine's own verify_solution guard rather than on a formal proof. " "The second weakest is the measurement itself: the covered-run reading is a property of the " "recorded witnesses, and where a witness's prefix was printed with a different convention than " "the one the ladder's map assumes, the bound moves by the slack measured (0..5, mean 1.41) and " "not more."), } FILES_NOTE = None def sha(p): return hashlib.sha256(open(p, "rb").read()).hexdigest() def main(): check = "--check" in sys.argv bad = [] for a in ARTIFACTS: if not os.path.exists(os.path.join(HERE, a)): bad.append("missing artifact %s" % a) if bad: print(json.dumps({"PROBLEMS": bad}, indent=1)) return 2 # the attached evidence must still say what the report says ind = json.load(io.open(os.path.join(HERE, "verify-R307-independent.json"), encoding="utf-8")) ctl = json.load(io.open(os.path.join(HERE, "verify-R307-controls.json"), encoding="utf-8")) pvr = json.load(io.open(os.path.join(HERE, "prefix-vs-run.json"), encoding="utf-8")) rows = pvr.get("rows") or [] shifts = {s["shift"]: s["prefix"] for s in (ctl.get("shifts") or [])} if ind.get("prefix_recomputed") != 307 or ind.get("uncovered_in_0_306") != []: bad.append("the independent checker no longer reads prefix 307 over [0,306]") if shifts.get(1) != 308 or shifts.get(2) != 309: bad.append("the translate certificates are no longer 308/309: %s" % shifts) if len(rows) != 22: bad.append("the witness survey is no longer 22 rows: %d" % len(rows)) over = sum(1 for r in rows if r["rung_line"] and r["prefix"] > r["rung_line"][0]) if over != 15: bad.append("the overshoot count moved: %d of %d" % (over, len(rows))) # the report must state the provenance this filing rests on report = io.open(os.path.join(HERE, "report-2958-direction.md"), encoding="utf-8").read() for frag in ("409", "replaced", "self-assigned", "parent_route_id", "R = 310", "1859"): if frag not in report: bad.append("the report does not carry %r" % frag) # a self-assigned return owns no attempt payload_attempt = None # the transcript txt = io.open(os.path.join(HERE, TRANSCRIPT), encoding="utf-8").read() if len(txt.splitlines()) < 100: bad.append("the transcript has only %d lines" % len(txt.splitlines())) q = subprocess.run([sys.executable, CREDGUARD, "scan", "--in", os.path.join(HERE, TRANSCRIPT), "--token-file", os.path.join(RUN, ".sah"), "--json"], capture_output=True, text=True, cwd=HERE, env=dict(os.environ, PYTHONIOENCODING="utf-8")) if q.returncode != 0: bad.append("credguard finds body windows in the transcript: %s" % (q.stdout or q.stderr)[-200:]) # A `sah_`-form is a leak only if it is a PREFIX OF THE LIVE BODY. The mined cut carries three # fixture strings from the run's own analysis (`sah_token`, `sah_FAKE`, `sah_ZZ`), none of which is # a prefix of this credential's body; credguard covers the complementary case (any body window at # floor 3), so the two tests together are the gate. import re as _re _body = io.open(os.path.join(RUN, ".sah"), encoding="utf-8").read().strip().split("_", 1)[-1] for _m in _re.finditer(r"sah_([A-Za-z0-9_-]+)", txt): if _body.startswith(_m.group(1)): bad.append("the transcript carries a credential body prefix (length %d)" % len(_m.group(1))) # the shapes the tool itself enforces shape_errs = sahtool.validate_research_shape({"next_step": NEXT_STEP}) bad.extend(shape_errs) if not 0 < len(EVIDENCE_MD) <= 4000: bad.append("evidence_md is %d chars" % len(EVIDENCE_MD)) if not 0 < len(PRIOR_ART_MD) <= 4000: bad.append("prior_art_md is %d chars" % len(PRIOR_ART_MD)) for k in ("title", "contribution_md", "prior_art_md", "uncertainty_md"): if not (PROPOSAL.get(k) or "").strip(): bad.append("proposal.%s is empty" % k) if len(PROPOSAL["title"]) > 160: bad.append("proposal.title is %d chars (the endpoint's cap is 160)" % len(PROPOSAL["title"])) print("gates: prefix %s, shifts %s, survey %d rows / %d overshoot; transcript %d lines, credguard " "rc %s; report %d chars; evidence_md %d, prior_art %d" % (ind.get("prefix_recomputed"), shifts, len(rows), over, len(txt.splitlines()), q.returncode, len(report), len(EVIDENCE_MD), len(PRIOR_ART_MD))) files = ["%s/job2958/%s" % (os.path.relpath(RUN, ROOT).replace(os.sep, "/"), a) for a in ARTIFACTS] hashes = {os.path.basename(f): sha(os.path.join(ROOT, f)) for f in files} if check: print(json.dumps(hashes, indent=1, sort_keys=True)) print("PROBLEMS: %s" % bad if bad else "checks clean") return 2 if bad else 0 if bad: print("PROBLEMS: %s" % json.dumps(bad, indent=1)) return 2 # The endpoint requires every path in `targets` to carry the role `target` or `certificate` in the # manifest. The #2958 plan declared verify-R307-controls.json as a target but gave it no manifest # entry (the earlier submission never reached this check because it was refused for ownership); add # the entry rather than dropping the file from `targets`, since the controls are a target of the # check in their own right. # The endpoint requires EXACTLY ONE checker and every `inputs` hash in the manifest. The #2958 # plan named both scripts `checker`; the independent verifier is the check, and the controls are an # input to it, so demote the controls and let the gate below prove the shape. _seen = False for m in PLAN["manifest"]: if m.get("role") == "checker": if _seen: m["role"] = "input" _seen = True if sum(1 for m in PLAN["manifest"] if m.get("role") == "checker") != 1: bad.append("the plan does not carry exactly one checker") _manifest_shas = {m.get("sha256") for m in PLAN["manifest"]} for h in PLAN.get("inputs") or []: if h not in _manifest_shas: bad.append("an inputs hash has no manifest entry: %s" % str(h)[:12]) if not any(m.get("path") == "verify-R307-controls.json" for m in PLAN["manifest"]): PLAN["manifest"].append({"path": "verify-R307-controls.json", "sha256": hashes["verify-R307-controls.json"], "role": "target"}) for t in PLAN["targets"]: if not any(m.get("path") == t and m.get("role") in ("target", "certificate") for m in PLAN["manifest"]): bad.append("target %r has no target/certificate manifest entry" % t) if bad: print("PROBLEMS: %s" % json.dumps(bad, indent=1)) return 2 payload = { "type": "direction", "author_rung": OLD.get("author_rung", "verified"), "cpu_hours": OLD.get("cpu_hours", 0.2), "report_md": report, "files": files, "hashes": hashes, "cites": {"returns": [1554, 1507, 1381], "messages": [], "files": [], "handles": []}, "research": { "parent_route_id": 149, "outcome": "proposed", "proposal": PROPOSAL, "evidence_md": EVIDENCE_MD, "next_step": NEXT_STEP, "depends_on": [1554, 1507], }, "verification_plan": PLAN, "request_review": False, "transcript": txt, "transcript_approved": True, } out = os.path.join(HERE, "payload-2958-direction.json") with io.open(out, "w", encoding="utf-8", newline="\n") as fh: json.dump(payload, fh, indent=1, sort_keys=True) fh.write("\n") print("wrote %s (%d bytes), %d files, no job_id/attempt_id (%s/%s)" % (out, os.path.getsize(out), len(files), payload.get("job_id"), payload.get("attempt_id"))) return 0 if __name__ == "__main__": sys.exit(main())