#!/usr/bin/env python3 """build-payload-2962.py -- the payload for the mirror-cut reversion audit (job 2962, attempt a73b84ee...). An EXPLORE return on an ASSIGNED route, so it carries attempt_id + job_id and `research: {route_id: 128, outcome: result, ...}`. The builder refuses to build unless the evidence on disk still shows the claims: * `verify-served-reversion.py` PASSES against the ATTACHED bundle (offline, no token): the nine still-serving reverts, the registered changed-line counts under both normalisations, the repaired document, and the registry flip under BOTH parsers -- with its five controls detected; * `credguard scan` finds ZERO credential body windows in the transcript that will be filed (the shared scrubber reports ok:true while bare windows survive, so the floor-3 scan is the gate); * the published audit JSON still carries 9 reverts / 1 many_versions / 2 two_versions / 1,199 version-less documents, all controls holding and exactly one registry flip; * evidence_md and prior_art_md are within the server's 4000-character cap, budget_hours is in the schema's 0.1-4 range, and the report carries the corrected registry finding (554 wide / 482 strict, one flip) rather than only the route's 482. python3 build-payload-2962.py --check # gates and hashes, writes nothing python3 build-payload-2962.py # writes job2962/payload-2962.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") TRANSCRIPT = "transcript-2962-turn.clean.jsonl" ARTIFACTS = ["report-2962.md", "evidence_md.txt", "prior_art_md.txt", "reversion-audit.py", "served-reversion-audit.json", "reversion-evidence.json", "verify-served-reversion.py", "bundle-evidence.py", "diff-detail.py", "diff-detail.txt", "inventory.txt", "audit-summary.txt", "repair-note.txt", "served-1556-reversion_sweep2.py", TRANSCRIPT, "build-payload-2962.py"] EVIDENCE_MD = io.open(os.path.join(HERE, "evidence_md.txt"), encoding="utf-8").read().strip() PRIOR_ART_MD = io.open(os.path.join(HERE, "prior_art_md.txt"), encoding="utf-8").read().strip() NEXT_STEP = { "question": ("After the remaining nine discarded revisions are re-applied (or recorded as " "superseded) and the registry is regenerated, does the served tree still serve any " "pre-cut content, and does the Q-shadow-prereg row return to ANSWERED?"), "method": ("Re-run `reversion-audit.py --state ` (endpoint-only, deterministic, cached) " "and `verify-served-reversion.py --bundle ` after the regeneration, then " "require (a) no document whose newest version repeats an earlier version's content, " "(b) `registry.status_flips == []` under BOTH the wide and the #1556-strict row rules, " "(c) for each of the ten documents a served revision newer than the discarded one and a " "re-application marker in its served text (the fixed-endpoint pattern), and (d) the five " "controls unchanged. The detector must be the stable rule, not the fixed three-version " "shape: the repaired document has four versions and the fixed shape reports it as " "nothing."), "success": ("Zero still-serving reverts, zero registry flips, and a newer served revision carrying " "the re-application marker for every one of the ten; the audit's own controls fire " "throughout."), "failure": ("Any document still serves the pre-cut content after the regeneration, or a " "re-application is claimed but the served bytes carry no marker (a silent re-file), or " "the registry flip survives -- then the maintenance item is open and is recorded as " "such rather than closed."), "budget_hours": 0.5, "compute": {"cpu_hours": 0.5, "ram_gb": 2, "disk_gb": 1}, "required_tools": ["python3"], "required_sources": ["docs-endpoint", "history-endpoint", "files-endpoint"], } 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 # 1. the checker PASSES against the attached bundle, offline p = subprocess.run([sys.executable, os.path.join(HERE, "verify-served-reversion.py"), "--bundle", os.path.join(HERE, "reversion-evidence.json"), "--audit", os.path.join(HERE, "served-reversion-audit.json")], capture_output=True, text=True, cwd=HERE, env=dict(os.environ, PYTHONIOENCODING="utf-8")) try: verdict = json.loads(p.stdout) except Exception: # noqa: BLE001 verdict = {"verdict": "UNPARSABLE", "stdout": p.stdout[-300:], "stderr": p.stderr[-300:]} if p.returncode != 0 or verdict.get("verdict") != "PASS": bad.append("the checker does not PASS (rc=%s): %s" % (p.returncode, verdict.get("differences") or verdict.get("stdout"))) if not verdict.get("controls_all_detected"): bad.append("the checker's controls were not all detected: %s" % verdict.get("controls")) derived = verdict.get("derived") or {} reg = derived.get("registry") or {} if (derived.get("counts") or {}).get("reverted_and_still_serving") != 9: bad.append("the checker derives %s reverts" % (derived.get("counts") or {})) if reg.get("wide_rows") != 554 or reg.get("strict_rows") != 482 or len(reg.get("status_flips") or []) != 1: bad.append("the checker's registry read-back moved: %s" % reg) # 2. the published audit JSON still says what the return says au = json.load(io.open(os.path.join(HERE, "served-reversion-audit.json"), encoding="utf-8")) kinds = au.get("kinds") or {} if (au.get("revert_count") != 9 or kinds.get("three_version_revert") != 9 or kinds.get("many_versions") != 1 or kinds.get("two_versions") != 2 or kinds.get("no_versions") != 1199): bad.append("the published audit counts moved: %s / %s" % (au.get("revert_count"), kinds)) if (au.get("substantive_vs_cosmetic") or {}).get("surviving_both_normalisations") != 9: bad.append("the audit no longer reports 9 surviving both normalisations") if len((au.get("registry") or {}).get("status_flips") or []) != 1: bad.append("the audit's registry block no longer carries exactly one flip") ctl = au.get("controls") or {} if not (ctl.get("positive_both_still_fire") is True and (ctl.get("positive_third_document_is_REPAIRED_not_reverted") or {}).get("holds") is True and (ctl.get("absent_path_is_visible") or {}).get("holds") is True): bad.append("a control in the published audit no longer holds") # 3. the transcript: zero credential body windows at the credguard floor txt = io.open(os.path.join(HERE, TRANSCRIPT), encoding="utf-8").read() 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 still finds body windows in the transcript (rc=%s): %s" % (q.returncode, (q.stdout or q.stderr)[-300:])) if len(txt.splitlines()) < 100: bad.append("the transcript has only %d lines" % len(txt.splitlines())) # a credential form is `sah_` immediately followed by a body character; the mined cut carries # only the scrubber's own marker `sah_` and prose ABOUT the prefix, so the gate is # the pattern and not the bare prefix. import re as _re if _re.search(r"sah_[A-Za-z0-9]", txt): bad.append("the transcript still carries a credential-prefixed token form") # 4. the prose 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)) if not 0.1 <= NEXT_STEP["budget_hours"] <= 4: bad.append("budget_hours out of range") report = io.open(os.path.join(HERE, "report-2962.md"), encoding="utf-8").read() for frag in ("554", "482", "Q-shadow-prereg", "10 historical", "1,211"): if frag not in report: bad.append("the report does not carry %r" % frag) print("gates: checker %s (controls %s; reverts %s; registry %s/%s, flips %d); audit 9/1/2/1199, " "controls hold; credguard rc %s; transcript %d lines; evidence_md %d chars, prior_art %d " "chars, report %d chars" % (verdict.get("verdict"), verdict.get("controls_all_detected"), (derived.get("counts") or {}).get("reverted_and_still_serving"), reg.get("wide_rows"), reg.get("strict_rows"), len(reg.get("status_flips") or []), q.returncode, len(txt.splitlines()), len(EVIDENCE_MD), len(PRIOR_ART_MD), len(report))) files = ["%s/job2962/%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 plan = { "schema_version": 1, "tools": ["python3"], "manifest": [ {"path": "verify-served-reversion.py", "sha256": hashes["verify-served-reversion.py"], "role": "checker"}, {"path": "reversion-evidence.json", "sha256": hashes["reversion-evidence.json"], "role": "target"}, {"path": "bundle-evidence.py", "sha256": hashes["bundle-evidence.py"], "role": "input"}, {"path": "reversion-audit.py", "sha256": hashes["reversion-audit.py"], "role": "input"}, {"path": "served-reversion-audit.json", "sha256": hashes["served-reversion-audit.json"], "role": "target"}, ], "targets": ["reversion-evidence.json", "served-reversion-audit.json"], "claim": ("Over the 12 documents the serving layer keeps a version record for (of 1,211 walked), " "exactly 9 are reverted and still serving: the newest recorded version's bytes equal " "an earlier version's bytes while a distinct verified revision sits between them, and " "the served /docs bytes hash to that newest version. For those 9 the served text " "differs from the discarded revision's blob by the registered line counts under raw, " "whitespace-normalised and link-stripped comparison (e.g. corner-correlation.md " "22/21/19, fold-arithmetic-bridge.md 69/52/52), so none is cosmetic. A tenth document " "(research/fixed-endpoint-discrepancy.md) was reverted and then repaired by return " "#1333, and the registry flip is exactly one row under BOTH a wide row rule (554 rows) " "and #1556's strict rule (482 rows): Q-shadow-prereg served OPEN / discarded ANSWERED."), "scope": ("the serving endpoint's version records and the served bytes of the 12 version-tracked " "documents, plus the two QUESTIONS.md layouts for the registry. The 1,199 " "version-less documents are outside it: /history gives them no versions, so the " "question cannot be posed there. Nothing mathematical is claimed, and no route's " "conclusion is shown to change."), "assumptions": ("the version list returned by /history is the serving layer's own record of what " "was published, and the served /docs bytes are what it serves; SHA-256 equality " "of document bytes decides every classification, and the changed-line counts are " "a text-level reading under the two normalisations named."), "checker": hashes["verify-served-reversion.py"], "inputs": [hashes["reversion-evidence.json"], hashes["served-reversion-audit.json"], hashes["bundle-evidence.py"], hashes["reversion-audit.py"]], "environment": ("python3 (%s), standard library only, NO network and NO credential: the checker " "reads the attached bundle, which holds the raw /history answers, the served " "documents and every version blob. The bundle itself is reproducible offline " "from the audit's cache (`bundle-evidence.py`), and the audit is re-runnable " "live with a token (`reversion-audit.py --state `)." % sys.version.split()[0]), "command": ("python3 verify-served-reversion.py --bundle reversion-evidence.json " "--audit served-reversion-audit.json"), "expected": ("exit 0, `verdict` PASS, `differences` empty, `controls_all_detected` true: the nine " "registered documents still serving with the nine registered line counts under all " "three comparisons, the repaired document at 4 versions classified " "reverted-then-revisioned with the marker present, the registry at 554 rows (wide " "rule) and 482 rows (#1556's strict rule) with the same single flip, and the " "published audit JSON agreeing with the bytes on all five keys."), "supports": ("establishes the finite claim of this return from the raw bytes alone, including " "that the flip survives two different row parsers and that the pre-cut content of " "the nine differs substantively (not by reflow or link stripping). It does NOT " "establish: whether the other 1,199 documents carry a contradicted status (no " "version record exists to ask); whether the re-applied document is byte-faithful to " "the discarded revision (it is not -- 8 whitespace-normalised lines differ, one " "marked in the served text); or any mathematical consequence."), "coverage": "decisive", "coverage_md": ("all 12 version-tracked documents, each read from its /history answer and the " "blob bytes of every version; the 9 reverts diffed three ways; the repaired " "document and both two-version documents classified; both registry rules " "applied. Excluded: the 1,199 version-less documents, the mathematical content " "of the documents, and any statement about what the serving layer would do " "after a repair."), "comparison": ("exact integer equality of the nine registered (raw, ws, ws+link) triples and of " "the two row counts; exact set equality of the still-serving paths and of the " "single flipped row; no tolerance is used anywhere."), "availability": {"status": "complete", "details": ("the checker, the bundle, the published audit JSON and the " "instrument are all attached to this return; the check needs only " "python3 and runs in about ten seconds"), "required_sources": [], "network": False}, "cost": {"minutes": 1, "judgment_minutes": 10, "cpu_hours": 0.02, "ram_gb": 1, "disk_gb": 1}, } payload = { "type": "explore", "job_id": 2962, "attempt_id": "a73b84ee96bff090d84d8b52f5851b6c", "author_rung": "verified", "cpu_hours": 0.1, "report_md": report, "files": files, "hashes": hashes, "cites": {"returns": [1556, 1402, 1400, 305, 1333], "messages": [], "files": [], "handles": []}, "research": { "route_id": 128, "outcome": "result", "evidence_md": EVIDENCE_MD, "prior_art_md": PRIOR_ART_MD, "next_step": NEXT_STEP, "depends_on": [1556, 1402, 1400], }, "verification_plan": plan, "request_review": True, "transcript": txt, "transcript_approved": True, } out = os.path.join(HERE, "payload-2962.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, transcript %d chars" % (out, os.path.getsize(out), len(files), len(txt))) return 0 if __name__ == "__main__": sys.exit(main())