146 lines
6.5 KiB
Python
146 lines
6.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Close the #2479 dichotomy-wave drift_compression gap contract (RUST 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 1fbc504b close PARTIAL gaps — dichotomy wave (3/7 -> 7/7)
|
|
refactor 772b1758 Phase B language-advantage pass
|
|
|
|
Usage: close_contract_drift_compression.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 = "1fbc504b"
|
|
PHASEB_SHA = "772b1758"
|
|
EVIDENCE = f"parity {PARITY_SHA}, phase B {PHASEB_SHA}"
|
|
|
|
NEED = (
|
|
"drift_compression dichotomy gap-close (RUST): name-preserving port "
|
|
"of the 4 audit-missing functions into src/rust/memory_scoring "
|
|
"compression.rs — the audit alias now follows the live delegation "
|
|
"chain (drift_compression -> drift_core._ms_core -> ms_loader -> "
|
|
"libmemory_scoring.so) instead of cognition_core. NEW kernel: "
|
|
"get_compression_stats (SQL stays in the Python facade per the "
|
|
"boundary law; row-reduction math — int() truncation after the float "
|
|
"multiply, banker's rounding at the 1e2 scale, SQL-null coercion, "
|
|
"empty-store int-shaped 0 — in Rust + ms_get_compression_stats FFI + "
|
|
"loader wrapper + oracle delegation with a load-bearing "
|
|
"_py_get_compression_stats fallback). Fix-first defect proven by the "
|
|
"new frozen battery: warn_before_compress emitted the COERCED "
|
|
"rock_status where the oracle emits the raw value (present-None rides "
|
|
"the warning dict as null). Frozen truth 65 cases via the shared "
|
|
"freeze_truth harness (the six _py_* kernels — delegation-proof by "
|
|
"construction), byte-identical across repeated gen + --verify runs; "
|
|
"cargo battery 7/7 (include_str! embed); clippy -D warnings + fmt "
|
|
"clean; live parity 1935/1935 (pinned facade / live facade / kernel "
|
|
"direct / db-level sqlite seam / fuzz seed 2479); Python both pins "
|
|
"green; ruff clean. Dichotomy audit 3/7 PARTIAL -> 7/7 FULL (RUST). "
|
|
"Delivered on gitea/master: feat " + PARITY_SHA + ", phase B "
|
|
+ PHASEB_SHA + "."
|
|
)
|
|
|
|
iface = ConstructionInterface(builder="factory-gap-dcomp")
|
|
|
|
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": "drift_compression dichotomy completion — parity "
|
|
f"{PARITY_SHA} feat(drift_compression): close PARTIAL "
|
|
"gaps — dichotomy wave; pushed gitea/master. Rust port "
|
|
"at src/rust/memory_scoring (compression.rs kernels + "
|
|
"ms_* FFI + ms_loader seam) closes the audit gaps "
|
|
"name-preserving: the pure five already lived there "
|
|
"(H3 slice 2) behind a stale audit alias (now mapped to "
|
|
"the live delegation chain); get_compression_stats is "
|
|
"new kernel work (SQL stays Python — boundary law; "
|
|
"int() truncation, banker's rounding at 1e2, SQL-null "
|
|
"coercion, empty-store int-shaped 0; crash parity: "
|
|
"short rows -> 'list index out of range'). Generator "
|
|
"scripts/gen_drift_compression_truth.py: 65-case frozen "
|
|
"truth (shared freeze_truth harness, the six _py_* "
|
|
"kernels — delegation-proof by construction) "
|
|
"regenerates byte-identical; freeze_truth --verify OK "
|
|
"twice against the live oracle. Battery 7/7 replay "
|
|
"VERBATIM (65 rows, include_str! embed + crash-parity "
|
|
"row shapes); live parity "
|
|
"scripts/check_drift_compression_parity.py 1935/1935 "
|
|
"(pinned facade / live facade / kernel direct / "
|
|
"db-level sqlite seam / fuzz seed 2479); clippy -D "
|
|
"warnings + fmt clean; Python both pins green "
|
|
"(test_ms_loader_seam 7/7 incl. 2 new stats tests; "
|
|
"shims failures pre-exist identically on base). Audit "
|
|
"3/7 → 7/7 FULL (RUST). Phase B 772b1758: zero-copy "
|
|
"char_indices prefix, exhaustive match dispatch, "
|
|
"try_fold accumulators — behavior-identical, battery + "
|
|
"parity re-green. Divergences (documented): integral "
|
|
"floats crossing the FFI render int-shaped "
|
|
"(savings_pct 50.0 oracle-side vs 50 envelope-side) — "
|
|
"compared structurally, byte shape pinned by the Rust "
|
|
"battery's frozen replay.",
|
|
}],
|
|
scope_files=[
|
|
"src/rust/memory_scoring/src/compression.rs",
|
|
"src/rust/memory_scoring/src/lib.rs",
|
|
"src/rust/memory_scoring/src/branch_battery.rs",
|
|
"src/rust/memory_scoring/src/frozen_dcomp_truth.json",
|
|
"src/rune/drift_compression.py",
|
|
"src/rune/ms_loader.py",
|
|
"scripts/gen_drift_compression_truth.py",
|
|
"scripts/check_drift_compression_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)
|