#!/usr/bin/env python3 """Job #4551 (route 1 step check): build the searchable comparison window from the served bytes. Reads ./served/return-*.json (fetched verbatim from the public return endpoint), keeps the whole post-setter record (routeless returns included), and writes served_window.jsonl with the fields the check needs: identity, full report text, the research object and every step-like object the return carries. Machine-local paths in served text are replaced by a placeholder and each substitution is recorded in window_scrub.json; nothing else is altered. The step this check compares is route 1's next experiment, set by return #1841: sha256(canonical(json)) of route-1.json "next_step" and of the brief's step object. """ import datetime import hashlib import json import os import re HERE = os.path.dirname(os.path.abspath(__file__)) SERVED = os.path.join(HERE, "served") SETTER = 1841 ABS = re.compile(r"(?", uv) fields[k] = v res = rec.get("research") steps = {} if res is not None: flat = json.dumps(res, sort_keys=True) unesc = flat.replace("\\\\", "\\") if ABS.search(unesc): scrub.append({"id": rec["id"], "field": "research"}) res = json.loads(ABS.sub("", unesc)) steps = {("research" + p): s for p, s in collect_steps({"research": res}).items()} row = {"id": rec["id"], "route": rec.get("research_route_id"), "created_at": rec.get("created_at"), "status": rec.get("status"), "type": rec.get("type"), "model": rec.get("model"), "job_id": rec.get("job_id"), "research": res, "steps": {p: {"sha256": canon(s), "obj": s} for p, s in steps.items()}} row.update(fields) rows.append(row) rows.sort(key=lambda r: r["id"]) with open(os.path.join(HERE, "served_window.jsonl"), "w", encoding="utf-8", newline="\n") as fh: for r in rows: fh.write(json.dumps(r, sort_keys=True) + "\n") route = json.load(open(os.path.join(SERVED, "route-1.json"), encoding="utf-8")) with open(os.path.join(HERE, "window_scrub.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump({"served_return_sha256": files, "scrubbed": scrub, "route1_next_step_sha256": canon(route["next_step"]), "step_setter": SETTER, "built_at": datetime.datetime.now(datetime.timezone.utc).isoformat()}, fh, indent=1) print("served_window.jsonl: %d returns (ids %d..%d), %d scrubbed machine-local path(s)" % (len(rows), rows[0]["id"], rows[-1]["id"], len(scrub))) print("post-setter returns (id > %d): %d" % (SETTER, len([r for r in rows if r["id"] > SETTER]))) print("route-1 next_step sha256: %s" % canon(route["next_step"])) if __name__ == "__main__": main()