#!/usr/bin/env python3 """Completeness scan for the route-83 step check, job #4473. The step was set by return #1830 (2026-09-26T13:37:28.204Z). A step check must decide whether a return recorded after it answers the step. The server named exactly one such return (#1835, route 134). This script widens the comparison to *every* return in the record with a larger id and keyword-scans it for the step's own identifiers, so the negative is machine-checked rather than asserted. Read-only. Progress goes to stderr, results to stdout / a JSON artefact. python scan_after_1830.py [--lo 1831] [--hi 1990] [--json out.json] """ import json, os, sys, hashlib, re HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.abspath(os.path.join(HERE, "..", "..")) sys.path.insert(0, os.path.join(ROOT, ".solveathome", "tools")) import sah # noqa: E402 RUN = "launch-1rqz5jwid5234jrtdjvdo0it" OUT = os.path.join(HERE, "served", "scan") os.makedirs(OUT, exist_ok=True) # The step's own identifiers (return #1830, research.next_step). A return that # answers the step has to name at least one of these. KEYWORDS = [ "siegel-walfisz", "siegel\u2013walfisz", "barban", "davenport", "halberstam", "bdh", "2412.19644", "1208.5992", "1704.04831", "general-sequence", "general sequence", "lam0", "lam1", "varE", "vare", "friable", "squarefree", "square-free", "smooth number", "bdh-reduction", "job1945", "e_d", "ethan", "unbalanced cell", "mirror case", ] # identifiers that name route 83's own object; kept separate so the report can # distinguish "same route's vocabulary" from "a BDH/SW locator". ROUTE83 = ["varE", "vare", "lam0", "lam1", "e_d", "unbalanced", "friable", "job1945", "attack-0830"] def headers(): binding = json.load(open(os.path.join(sah.state_dir(), "device-binding.json"))) iden = sah.identity() return { "Authorization": "Bearer " + sah.cred(), "Accept": "application/json", "X-Model": iden.get("model") or "unmeasured", "X-Effort": iden.get("effort") or "unmeasured", "X-Department": binding["department_id"], "X-Session": "3e916252bda6e15c443d10ee", "User-Agent": "deepseek-harness/sah-tools scan_after_1830", } def fetch(rid, h): p = os.path.join(OUT, "return-%d.json" % rid) if os.path.exists(p): try: return "cached", json.load(open(p, encoding="utf-8")) except Exception: pass _xrid, status, txt = sah.request(RUN, "GET", "%s/return/%d" % (sah.PROJECT, rid), headers=h) if status != 200: return status, None with open(p, "w", encoding="utf-8", newline="") as fh: fh.write(txt) return status, json.loads(txt) def text_of(b): parts = [] for k in ("report_md", "recipe_md", "finding", "human_md"): v = b.get(k) if isinstance(v, str): parts.append(v) r = b.get("research") if isinstance(r, dict): parts.append(json.dumps(r)) return "\n".join(parts) def main(): lo, hi, js = 1831, 1990, None a = sys.argv[1:] for i, x in enumerate(a): if x == "--lo": lo = int(a[i + 1]) elif x == "--hi": hi = int(a[i + 1]) elif x == "--json": js = a[i + 1] h = headers() rows, missing = [], [] for rid in range(lo, hi + 1): status, d = fetch(rid, h) if d is None: missing.append(rid) sys.stderr.write("r%d: HTTP %s (absent)\n" % (rid, status)) continue b = d.get("body", d) t = text_of(b) low = t.lower() hits = sorted({k for k in KEYWORDS if k.lower() in low}) hits83 = sorted({k for k in ROUTE83 if k.lower() in low}) rows.append({ "id": b.get("id"), "created_at": b.get("created_at"), "route": b.get("research_route_id"), "type": b.get("type"), "model": b.get("model"), "handle": b.get("handle"), "status": b.get("status"), "final_rung": b.get("final_rung"), "outcome": (b.get("research") or {}).get("outcome") if isinstance(b.get("research"), dict) else None, "depends_on": (b.get("research") or {}).get("depends_on") if isinstance(b.get("research"), dict) else None, "title": (b.get("report_md") or "").split("\n")[0][:120], "hits": hits, "hits_route83": hits83, "text_len": len(t), "sha256": hashlib.sha256(t.encode()).hexdigest()[:16], }) sys.stderr.write("r%d route=%s hits=%s\n" % (rid, b.get("research_route_id"), hits)) out = {"lo": lo, "hi": hi, "absent": missing, "n_present": len(rows), "rows": rows} if js: with open(js, "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1, sort_keys=True) print(json.dumps({"absent": missing, "n_present": len(rows)}, sort_keys=True)) for r in rows: if r["hits"]: print("HIT %s route=%s %s :: %s" % (r["id"], r["route"], r["hits"], r["title"])) if __name__ == "__main__": main()