#!/usr/bin/env python3 """Enumerate the accepted lane: which served returns carry a patch or a revision. Job 2866 (pursue route 139). #2744 walked ids 1..1370; this walk covers 1..LAST and stores a compact index plus the patch text of every bearing return, so the certifier never re-walks. Read-only. Writes lane-index.json + patches/lane-.patch. """ import json, os, sys, time HERE = os.path.dirname(os.path.abspath(__file__)) SAH_HOME = os.path.abspath(os.path.join(HERE, "..", "..", "..")) sys.path.insert(0, os.path.join(SAH_HOME, "tools")) import sah LAUNCH = "launch-zdvw3ktup0yka1yia4jkri3g" LAST = int(os.environ.get("LAST", "1530")) state = sah.state_dir() run_dir = os.path.join(state, "runs", LAUNCH) launch = json.load(open(os.path.join(run_dir, "launch.json"))) binding = json.load(open(os.path.join(state, "device-binding.json"))) iden = sah.identity() H = {"Authorization": "Bearer " + sah.cred(), "Accept": "application/json", "X-Model": iden["model"], "X-Effort": iden["effort"], "X-Department": binding["department_id"], "X-Session": launch["session"], "X-Attempt": launch["attempt_id"], "User-Agent": "deepseek-harness/sah-tools " + sah.TOOL_VERSION} os.makedirs(os.path.join(HERE, "patches"), exist_ok=True) idx, bearing = {}, [] t0 = time.time() for rid in range(1, LAST + 1): xrid, status, txt = sah.request(LAUNCH, "GET", sah.PROJECT + f"/return/{rid}", headers=H) if status != 200: continue try: d = json.loads(txt) except Exception: continue patch = d.get("patch") or "" rec = {"id": rid, "job_id": d.get("job_id"), "type": d.get("type"), "status": d.get("status"), "final_rung": d.get("final_rung"), "patch_status": (d.get("patch_status") or "")[:60] or None, "has_patch": bool(patch.strip()), "patch_len": len(patch), "revision_path": d.get("revision_path"), "revision_sha": d.get("revision_sha"), "model": d.get("model"), "created_at": d.get("created_at"), "files": [{"name": f.get("name"), "sha256": f.get("sha256")} for f in (d.get("files") or []) if isinstance(f, dict)]} idx[str(rid)] = rec if rec["has_patch"] or rec["revision_sha"]: bearing.append(rid) open(os.path.join(HERE, "patches", f"lane-{rid}.patch"), "w").write(patch) print(f"#{rid:<5} {rec['type']:<8} {rec['status']:<10} patch={rec['patch_len']:<7} " f"rev={bool(rec['revision_sha'])} files={len(rec['files'])} " f"status={str(rec['patch_status'])[:40]}", flush=True) if rid % 100 == 0: print(f"... {rid} walked, {len(bearing)} bearing, {time.time()-t0:.0f}s", flush=True) time.sleep(0.05) json.dump({"last": LAST, "walked": len(idx), "bearing": bearing, "index": idx}, open(os.path.join(HERE, "lane-index.json"), "w"), indent=1) print(f"\nDONE: {len(idx)} returns, {len(bearing)} patch/revision-bearing, {time.time()-t0:.0f}s") print("bearing:", bearing)