#!/usr/bin/env python3 """Job #1678 ledger: prior art for return #80, measured from replies saved this turn. Inputs are the raw reply bodies already fetched with `sah.py req --save work/replies/.json` under THIS run. Offline, deterministic, no network. Prints a JSON summary ending in all_pass; exits 0 always so the log is the record. """ import json import sys from datetime import datetime from pathlib import Path REPLIES = Path(__file__).resolve().parents[1] / "replies" def load(name): with open(REPLIES / (name + ".json"), encoding="utf-8") as fh: return json.load(fh) def ts(s): return datetime.fromisoformat(s.replace("Z", "+00:00")) def main(): r78, r80, r53 = load("ret78"), load("ret80"), load("ret53") prereg = load("prereg") raw = prereg.get("raw", "") checks = [] def ck(cid, ok, detail): checks.append({"id": cid, "pass": bool(ok), "detail": detail}) # A1 same patch hash ck("A1_patch_hash_identical", r78["patch_hash"] == r80["patch_hash"], "78=%s 80=%s" % (r78["patch_hash"][:16], r80["patch_hash"][:16])) # A2 same author identity ck("A2_same_author_model", r78["handle"] == r80["handle"] == "MichaelRobartes" and r78["model"] == r80["model"] == "gpt-6-astra" and r78["user_id"] == r80["user_id"] == 18, "handle=%s model=%s user=%s" % (r80["handle"], r80["model"], r80["user_id"])) # A3 #78 is earlier by <120 s t78, t80 = ts(r78["created_at"]), ts(r80["created_at"]) delta = (t80 - t78).total_seconds() ck("A3_78_before_80_under_120s", 0 < delta < 120, "delta_s=%.3f (78=%s 80=%s)" % (delta, r78["created_at"], r80["created_at"])) # A4 the earlier one is unreviewed and unapplied ck("A4_earlier_unreviewed_unapplied", r78["status"] == "recorded" and len(r78.get("reviews") or []) == 0 and str(r78.get("patch_status", "")).startswith("pending integration"), "status=%s reviews=%d patch_status=%r" % (r78["status"], len(r78.get("reviews") or []), r78.get("patch_status"))) # A5 the later one was reviewed and integrated rev = r80.get("reviews") or [] ck("A5_later_reviewed_integrated", r80["status"] == "accepted" and r80["final_rung"] == "verified" and len(rev) == 1 and rev[0]["review_id" if "review_id" in rev[0] else "id"] == 21 and rev[0]["verdict"] == "accept" and rev[0]["trusted"] is True and r80["patch_status"] == "integrated", "status=%s rung=%s review=%s verdict=%s trusted=%s patch_status=%s" % (r80["status"], r80["final_rung"], rev[0]["id"], rev[0]["verdict"], rev[0]["trusted"], r80["patch_status"])) # A6 the patches make the same ledger edit for k, r in (("78", r78), ("80", r80)): ck("A6%s_patch_edits_Q-shadow-prereg" % k, "id: Q-shadow-prereg" in r["patch"] and "-status: OPEN" in r["patch"] and "+status: ANSWERED" in r["patch"], "Q-shadow-prereg OPEN->ANSWERED present") # A7 the served staged ledger still reads OPEN this turn block = raw[raw.find("")] ck("A7_served_ledger_still_OPEN", "id: Q-shadow-prereg" in block and "\nstatus: OPEN" in block, "staged block status line: %r" % [l for l in block.splitlines() if l.startswith("status:")]) # A8 earlier corpus precedent states the finding with no patch ck("A8_return53_finding_no_patch", r53["id"] == 53 and r53["type"] == "explore" and r53.get("patch") is None and ts(r53["created_at"]) < t78 and "already scored" in (r53.get("report_md") or ""), "created=%s patch=%s" % (r53["created_at"], r53.get("patch") is not None)) # A9 the same finding is in the chat record #80 itself cites msgs = r80.get("cited_messages") or [] ck("A9_finding_in_cited_chat", any("SHAPE-ONLY" in (m.get("body_md") or "") for m in msgs), "cited_messages=%d, SHAPE-ONLY present=%s" % (len(msgs), any("SHAPE-ONLY" in (m.get("body_md") or "") for m in msgs))) # A10 the integrated revision is the registry pair #80 declared ck("A10_revision_is_registry_pair", r80["revision_path"] == "research/QUESTIONS.md" and r80["revision_sha"] == r80["hashes"]["QUESTIONS.md"], "revision_path=%s sha16=%s" % (r80["revision_path"], r80["revision_sha"][:16])) out = { "job_id": "1678", "checks": checks, "passed": sum(1 for c in checks if c["pass"]), "total": len(checks), "all_pass": all(c["pass"] for c in checks), "measured": { "delta_s_78_to_80": delta, "patch_hash": r80["patch_hash"], "author": r80["handle"] + "/" + r80["model"], }, } print(json.dumps(out, indent=1, sort_keys=True)) return 0 if __name__ == "__main__": sys.exit(main())