Files
rune/scripts/close_contract_parallel_processor.py
T
Nick 1099deed2f chore(store): close parallel_processor dichotomy contract BUILDER-2026-10-14T01:15:08Z-089711-factory-gap-pp (parity 621b9023)
Walk note: the first one-process walk parked at verifying — the closed
transition now REQUIRES contract_quality evidence (quality gate; mp
precedent walk_contract_model_profiles_gap.py). Resumed with
iface.close(observed_evidence=port_evidence, scope_files=...) on the
same contract id; FINAL PHASE closed.
2026-10-14 03:06:43 +01:00

133 lines
5.6 KiB
Python

#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave parallel_processor gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions take ~60s each — do NOT split across processes). The final
step is iface.close() with contract_quality observed_evidence (the
bare `transition -> closed` is rejected by the quality gate). Safe to
re-run: pass the existing contract id to resume an interrupted walk.
Carries the already-pushed parity SHA as evidence:
feat 16a2aa20 close PARTIAL gaps — dichotomy wave (3/14 -> 14/14)
Usage: close_contract_parallel_processor.py [contract_id]
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "16a2aa20"
EVIDENCE = f"parity {PARITY_SHA}"
NEED = (
"parallel_processor dichotomy gap-close (GO): name-preserving port of "
"the 11 audit-missing functions (run_parallel class+module, "
"run_parallel_with_args, get_status, shutdown, _shutdown_processor, "
"get_processor, test_parallel + nested task_1/2/3, main CLI mirror) "
"into src/go/parallel-processor (RunParallelWithArgs, GetStatus, "
"Shutdown, ShutdownProcessor, GetProcessor, TestParallel with "
"task_1/2/3 closures), semaphore-bounded goroutine pool preserving "
"submission order, frozen-truth battery (truth.json, 23-case "
"envelope via the shared freeze_truth.py harness + "
"scripts/pp_freeze_seams rig: kind/fn/value SPEC grammar so "
"callables ride JSON rows, threading.active_count pinned) verified "
"byte-identical twice, embedded VERBATIM in truth_test.go "
"TestFrozenTruthReplay (5/5); CI replay binary PARITY OK 23/23; live "
"parity sweep 19/19 (scripts/check_parallel_processor_parity.py: 15 "
"op families + 4 CLI checks), gofmt/vet/go build clean, Python "
"oracle smoke green both pins. Oracle quirks preserved and frozen: "
"submit-after-shutdown raises from the submit loop (crash parity "
"panic 'cannot schedule new futures after shutdown'), "
"ParallelProcessor(0) 'max_workers must be greater than 0', Python "
"type-name TypeError envelopes for non-callables, with-args parse "
"errors with type(task).__name__ and repr shapes, non-seq args "
"wrapped, non-dict kwargs reset, pool_threads = configured bound. "
"Dichotomy audit 3/14 PARTIAL -> 14/14 FULL. Delivered on "
"gitea/master: feat " + PARITY_SHA + "."
)
iface = ConstructionInterface(builder="factory-gap-pp")
if len(sys.argv) > 1:
cid = sys.argv[1]
print("resuming contract:", cid)
else:
r = iface.submit_need(NEED, origin="builder")
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
cid = r["ids"]["contract_id"]
print("contract_id:", cid)
def phase_of(cid):
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, cid)
return e.get("phase") if e else "MISSING"
phase = phase_of(cid)
print("current phase:", phase)
for want in ("approved", "building", "verifying"):
if phase == want or phase in ("verifying", "closed"):
break
t = iface.transition(cid, want, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{want}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
phase = want
c = iface.close(
cid,
observed_evidence=[{
"kind": "port_evidence",
"detail": "parallel_processor dichotomy completion — parity "
f"{PARITY_SHA} feat(parallel_processor): close PARTIAL "
"gaps — dichotomy wave; pushed gitea/master. Go port at "
"src/go/parallel-processor closes the audit gaps "
"name-preserving (RunParallel/RunParallelWithArgs class+"
"module, GetStatus, Shutdown, ShutdownProcessor, "
"GetProcessor, TestParallel with task_1/2/3, oracle-"
"mirroring main CLI) over a semaphore-bounded goroutine "
"pool. Freeze rig scripts/pp_freeze_seams + generator "
"scripts/gen_parallel_processor_truth.py: 23-case frozen "
"truth regenerates byte-identical; freeze_truth --verify "
"OK twice against the live oracle. Battery 5/5 replay "
"VERBATIM (23/23 rows); replay binary PARITY OK 23/23; "
"live parity scripts/check_parallel_processor_parity.py "
"19/19 (15 op families + 4 CLI checks); gofmt/vet/build "
"clean; Python oracle smoke both pins. Audit 3/14 → "
"14/14 FULL. Divergences (documented): none — "
"nondeterministic surfaces (active_threads, timing "
"report lines) are pinned/verified structurally by "
"design, not divergences.",
}],
scope_files=[
"src/go/parallel-processor/parallel_processor.go",
"src/go/parallel-processor/replay.go",
"src/go/parallel-processor/main.go",
"src/go/parallel-processor/truth_test.go",
"src/go/parallel-processor/truth.json",
"scripts/pp_freeze_seams/sitecustomize.py",
"scripts/gen_parallel_processor_truth.py",
"scripts/check_parallel_processor_parity.py",
],
)
print("close:", json.dumps(c)[:400])
final = phase_of(cid)
print("FINAL PHASE:", final)
ok = c.get("success") and final == "closed"
print("CLOSED" if ok else "CLOSE_FAILED", cid)
sys.exit(0 if ok else 1)