#!/usr/bin/env python3 r"""Job #1446 -- framework self-review, exercised rather than described. What the assignment's framework section requires before research on an assignment, and what this file actually observes (each item is a subprocess, and its exit code / parsed output is recorded; nothing here is asserted from memory): 1. task tracking + the outstanding-work check over ALL issued attempts (an issued attempt with NO submission must be reported outstanding and must fail the all-complete check); 2. the shared publication scrubber: it must REFUSE a malformed record, REDACT a secret that is nested inside a tool-output string after decoding, and leave usage/research fields intact; 3. REAL execution controls: `limits-run` must actually kill a spinning child, with no residual; 4. the allocation registry, and the tool version/hash actually in use; 5. the identity lookup for this turn (model + effort, with its sources). Usage: python framework_checks.py [--out checks.json] """ import argparse import hashlib import json import os import pathlib import subprocess import sys import time HERE = pathlib.Path(__file__).parent R = HERE.parent.parent # the run directory STORE = pathlib.Path(os.environ.get("LOCALAPPDATA", "")) / "solveathome" / "tools" TOOL = STORE / "v1" / "sahtool.py" GUARD = STORE / "guard" / "v1" / "driftguard.py" PY = sys.executable def run(args, timeout=180): t0 = time.time() p = subprocess.run([PY] + list(args), capture_output=True, text=True, timeout=timeout, cwd=str(R), encoding="utf-8", errors="replace") return {"argv": [str(a) for a in args], "exit": p.returncode, "seconds": round(time.time() - t0, 2), "stdout": p.stdout or "", "stderr": p.stderr or "", "stdout_tail": (p.stdout or "")[-700:], "stderr_tail": (p.stderr or "")[-400:]} def sha(p): return hashlib.sha256(pathlib.Path(p).read_bytes()).hexdigest() def credential(): """The scrubber fixture needs a REAL secret to be worth anything, and the caller's environment is not a reliable place to find one: this script's first run read an unset $SOLVEATHOME_TOKEN, built a fixture containing an empty string, and reported the redaction as broken. The tool's own documented precedence is followed instead, with the run's `.sah` file first.""" for p in (R / ".sah",): if p.exists(): v = p.read_text(encoding="utf-8").strip() if v: return v return (os.environ.get("SOLVEATHOME_TOKEN") or "").strip() def main(): ap = argparse.ArgumentParser() ap.add_argument("--out", default=str(HERE / "checks.json")) a = ap.parse_args() out = {"tool": "framework_checks/1", "job": 1446, "at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "python": sys.version.split()[0], "checks": {}} # ---- 1. outstanding over all issued attempts ------------------------------------------------ c = run([str(TOOL), "outstanding", "--state", ".", "--json"]) try: body = json.loads(c["stdout"][c["stdout"].index("{"):]) except Exception: body = None # THE MANDATORY FIXTURE, and its criterion is not "exit 0": while this assignment is open the # check MUST report it outstanding and MUST fail the all-complete check. That is exactly what # exit 1 plus an entry with reason "issued with no submission" means -- the first draft of this # file required exit 0 and so reported the working tool as broken. live = [e for e in (body or {}).get("outstanding", []) if e.get("reason") == "issued with no submission"] out["checks"]["outstanding"] = dict(c, parsed=body, reported_outstanding=[e.get("job_id") for e in live], all_complete_would_fail=c["exit"] != 0) out["checks"]["outstanding"]["ok"] = bool(body is not None and c["exit"] != 0 and live) issued = [] led = R / "ledger.jsonl" for line in led.read_text(encoding="utf-8").splitlines(): try: e = json.loads(line) except ValueError: continue if e.get("kind") == "issued": issued.append({"job_id": e.get("job_id"), "attempt_id": e.get("attempt_id")}) seen, uniq = set(), [] for e in issued: if e["attempt_id"] not in seen: seen.add(e["attempt_id"]) uniq.append(e) out["checks"]["issued_attempts"] = {"count": len(uniq), "jobs": [e["job_id"] for e in uniq]} # ---- 2. the publication scrubber ------------------------------------------------------------ fx = HERE / "fx" fx.mkdir(exist_ok=True) bad = fx / "bad.jsonl" bad.write_text('{"a": 1, this is not json}\n', encoding="utf-8") good = fx / "good.jsonl" secret = credential() good.write_text( json.dumps({"kind": "receipt", "return_id": 1, "usage": {"input": 10, "output": 5}, "tool_output": "leaked: " + secret, "research": {"outcome": "result", "headline": "kept"}}, ensure_ascii=False) + "\n", encoding="utf-8") out["checks"]["scrub_malformed"] = run([str(TOOL), "scrub", "--in", str(bad), "--out", str(fx / "bad.out.jsonl")]) out["checks"]["scrub_malformed"]["must_refuse"] = out["checks"]["scrub_malformed"]["exit"] != 0 sc = run([str(TOOL), "scrub", "--in", str(good), "--out", str(fx / "good.out.jsonl")]) out["checks"]["scrub_secret"] = sc body_txt = (fx / "good.out.jsonl").read_text(encoding="utf-8") out["checks"]["scrub_secret"].update({ "secret_absent": bool(secret) and secret not in body_txt, "usage_kept": '"usage"' in body_txt, "research_kept": '"headline": "kept"' in body_txt, "ok": sc["exit"] == 0 and secret not in body_txt and '"usage"' in body_txt, }) # the same gate on the real outbound payload later (preflight), and on a real transcript out["checks"]["scrub_transcript"] = run([str(TOOL), "scrub", "--in", str(HERE / "transcript.jsonl"), "--out", str(fx / "t.out.jsonl")]) # ---- 3. REAL execution controls -------------------------------------------------------------- out["checks"]["limits_run"] = run( [str(TOOL), "limits-run", "--timeout", "3", "--", PY, "-c", "import time\nprint('spinning', flush=True)\nend=time.time()+60\nwhile time.time()= 2 and out["checks"]["identity"]["effort_sources"] >= 2) out["summary"] = { "outstanding_ok": out["checks"]["outstanding"]["ok"], "scrubber_ok": out["checks"]["scrub_malformed"]["must_refuse"] and out["checks"]["scrub_secret"]["ok"], "limits_ok": out["checks"]["limits_run"]["ok"], "guard_ok": out["checks"]["versions"]["guard_selftest_ok"], "identity_ok": out["checks"].get("identity", {}).get("ok", False), } out["all_ok"] = all(out["summary"].values()) pathlib.Path(a.out).write_text(json.dumps(out, indent=1, sort_keys=True), encoding="utf-8", newline="\n") print(json.dumps(out["summary"], indent=1)) print("all_ok:", out["all_ok"], "->", a.out) return 0 if out["all_ok"] else 1 if __name__ == "__main__": sys.exit(main())