Files
rune/scripts/close_contract_context_pressure.py
T

106 lines
5.3 KiB
Python

#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave contract for context_pressure in ONE
process (submit → approved → building → verifying → closed), with SHA
evidence. Run with CS_RUST_LIB pointing at a built capability_scoring .so."""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
PARITY_SHA = sys.argv[1] if len(sys.argv) > 1 else ""
if not PARITY_SHA:
sys.exit("usage: close_contract_context_pressure.py <parity_sha>")
from rune.construction_interface import ConstructionInterface
iface = ConstructionInterface(builder="factory-gap-cps")
r = iface.submit_need(
"Port context_pressure to FULL Rust (#2479 dichotomy tranche, RUST "
"verdict — was 3/9 PARTIAL): the pure compute + entry assembly with "
"exact oracle semantics — codepoint-based token estimation (Python "
"len(), max(1, int(len/3.5))), the pressure ladder (raw-pressure "
"gates vs banker-correct round(x, 3) display, ZeroDivisionError "
"parity on max_tokens=0), degradation signals (avg-first/avg-last "
"trend, \\w+ unique-ratio repetition, generic-ratio composite with "
"the int-0 max(0, x) type law), JSONL entry assembly "
"({timestamp, session_id, **measurement} spread-override law), the "
"log tail reader (deque(maxlen) semantics, file-iteration law — no "
"phantom line after a final newline, blank/unparseable skip, "
"negative-limit [] floor), stats counting (exact AttributeError on "
"parsed non-dict lines), the on-message hook (data truthiness, "
"message/text/str(data) fallback with Python repr shapes), and CLI "
"dispatch (argparse shapes incl. code-2 exits, .1% renders, "
"indent=2 dumps). File IO (LOG_PATH append/read) and the wall clock "
"stay in the Python facade (no-clock law — now is always an "
"argument); cps_loader.py is the ctypes seam (RUNE_CPS_CORE / "
"RUNE_CONTEXT_PRESSURE_CORE pins, error envelopes raise the mapped "
"exceptions so crash parity holds). Frozen truth 75 cases under the "
"cps_freeze_seams rig (explicit core pins, frozen clock, hermetic "
"RUNE_MEMORY_DIR scratch, CPS_SEED_LOG for CLI subprocess rows); "
"byte-identical regeneration x2; shared-harness --verify OK; live "
"parity frozen=78 regen=6 fuzz=1400 live=18 failures=0; Rust "
"battery 10/10; clippy -D warnings + fmt clean; pytest 34/34 both "
"pins; audit 3/9 PARTIAL -> 9/9 FULL (RUST).",
origin="builder",
)
print("submit_need:", json.dumps(r)[:200])
if not r.get("success"):
sys.exit(1)
cid = r["ids"]["contract_id"]
print("contract_id:", cid)
for phase in ("approved", "building", "verifying"):
t = iface.transition(cid, phase)
if not t.get("success"):
print(f"transition->{phase} FAILED:", json.dumps(t)[:300])
sys.exit(1)
print("walked to verifying")
c = iface.close(cid, observed_evidence=[{
"kind": "port_evidence",
"detail": (
f"context_pressure RUST dichotomy completion — parity commit {PARITY_SHA}; "
"fn coverage 3/9 PARTIAL -> 9/9 FULL (audit CURRENT instrument, "
"docs/dichotomy-rebase-honest-audit.md regenerated at that commit); "
"frozen-truth battery replays 75 cases byte-identical "
"(src/rust/context_pressure/src/frozen_cp_truth.json via include_str! "
"in branch_battery.rs, generated from the live oracle floor under "
"scripts/cps_freeze_seams: scripts/gen_context_pressure_truth.py — "
"re-run regenerates byte-identical, sha256-stable x2); shared harness "
"freeze_truth.py --verify OK (28 envelope cases byte-identical); live "
"parity scripts/check_context_pressure_parity.py frozen=78 regen=6 "
"fuzz=1400 live=18 failures=0 (crash parity with exact str(e) "
"contract); cargo test 10/10, cargo clippy -D warnings clean, cargo "
"fmt clean, cargo build --release green; Python suite "
"tests/test_context_pressure.py 34 passed BOTH pins (python pin + "
"kernel live), ruff clean. Documented divergences: _now stays Python "
"(no-clock law — timestamps are arguments); file IO (LOG_PATH "
"append/read, CLI printing) stays in the facade — the kernel owns "
"entry assembly, log parsing, stats counting, hook derivation and "
"CLI dispatch decisions; read_log negative limit mirrors the "
"oracle's OBSERVED [] (best-effort floor swallows deque's "
"ValueError); integral floats crossing FFI render int-shaped "
"envelope-side (pyjson Num law) — live parity compares "
"structurally, byte shape pinned by the battery."
),
}], scope_files=[
"src/rune/context_pressure.py",
"src/rune/cps_loader.py",
"src/rust/context_pressure/Cargo.toml",
"src/rust/context_pressure/Cargo.lock",
"src/rust/context_pressure/src/lib.rs",
"src/rust/context_pressure/src/branch_battery.rs",
"src/rust/context_pressure/src/frozen_cp_truth.json",
"scripts/gen_context_pressure_truth.py",
"scripts/context_pressure_truth.py",
"scripts/check_context_pressure_parity.py",
"scripts/cps_freeze_seams/sitecustomize.py",
"scripts/close_contract_context_pressure.py",
"tests/test_context_pressure.py",
"verification/summary-cp.md",
])
print("close:", json.dumps(c)[:300])
print("CONTRACT", cid, "closed" if c.get("success") else "CLOSE_FAILED")