Files
rune/scripts/close_contract_event_envelope.py
Nick 9ee62d87b3 chore(store): close event_envelope dichotomy contract BUILDER-2026-10-14T04:22:42Z-8a4d5b-factory-gap-ee (parity fb1fd834)
Walked submit_need -> approved -> building -> verifying -> close()
(predicted-vs-observed quality gate) in the worktree process.
Evidence: verification/ee-*.exit + ee-summary.md — frozen-truth
83 cases byte-identical (freeze_truth --verify x2 under the
ee_freeze_seams rig), live parity 91/91 with a divergence-detecting
negative control, gofmt/vet/go build clean, Python suite 25+25 both
pins, ruff clean. Audit regenerated (event_envelope 8/8 FULL,
programme headline 98/192); factory-claims: event_envelope landed.
2026-10-14 05:44:23 +01:00

115 lines
4.9 KiB
Python

#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave event_envelope gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions can take ~60s each — do NOT split across processes). Carries
the rebased parity SHA as evidence:
feat 7f1f919d close PARTIAL gaps — dichotomy wave
Usage: close_contract_event_envelope.py
"""
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 = "7f1f919d"
EVIDENCE = f"parity {PARITY_SHA}"
iface = ConstructionInterface(builder="factory-gap-ee")
# Resume support: the first walk attempt hit the quality-gate law at the
# final step (raw `closed` transition refused) — pass the existing
# contract id to finish it; no argument walks a fresh contract end to end.
existing = sys.argv[1] if len(sys.argv) > 1 else None
if existing:
r = {"success": True, "ids": {"contract_id": existing}}
else:
r = iface.submit_need(
"event_envelope dichotomy gap-close (GO): name-preserving port of the 3 "
"audit-missing functions (to_dict, to_canonical_dict, test_envelope) "
"into src/go/event-bus as ToDict / ToCanonicalDict / TestEnvelope plus "
"the canonical-bridge classmethod CreateEnvelope (EventEnvelope.create: "
"CHANNELS prior vocabulary, prior-or-channel-or-source-or-unknown "
"fallback), and parity-driven defect fixes to the old-era port: "
"classifyAuthority/classifyUrgency now use the oracle's \\b<word>\\b "
"regex semantics with Unicode word chars (multi-word 'stop doing' vs "
"bare 'stop', punctuation adjacency, 'stopé' never matches; low "
"urgency 'when you can'/'no rush' multi-word entries), pyQuoteEvent "
"gains ensure_ascii escaping (unicode payload_hash parity, DEL/astral/"
"surrogate pairs), createEnvelope derives text from payload['text'] "
"(oracle signature), and minted ids/timestamps go through the "
"no-clock/no-random seams (EE_FROZEN_NOW + per-op uuid counter; "
"random uuid4-shaped ids in production). Frozen-truth battery "
"(truth_envelope.json, 83 cases incl. the loud RuntimeError branch "
"for un-bridged envelopes, schema_version-first canonical key order, "
"content-addressed payload_hash, captured test_envelope stdout) "
"generated under the scripts/ee_freeze_seams rig via freeze_truth.py "
"and verified byte-identical x2, embedded VERBATIM in "
"truth_envelope_test.go TestFrozenEnvelopeTruthReplay + seam units; "
"live parity sweep 91/91 PYTHON-json byte compare "
"(scripts/check_event_envelope_parity.py, negative control detects "
"divergence); gofmt/vet/go build clean; Python oracle battery green "
"both pins (25 live + 25 RUNE_EVENT_ENVELOPE_CORE=python). Dichotomy "
"audit 5/8 PARTIAL -> 8/8 FULL. Delivered on gitea/master: feat " + PARITY_SHA + ".",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
if not existing:
for phase in ("approved", "building", "verifying"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
# QUALITY-GATE LAW (2026-10-13): `closed` enters via close() — the
# predicted-vs-observed quality computation — never a raw transition.
closed = iface.close(c, observed_evidence=[{
"kind": "port_evidence",
"detail": (
f"parity {PARITY_SHA}: frozen-truth battery 83 cases byte-identical "
"(truth_envelope.json, freeze_truth.py --verify x2 under "
"scripts/ee_freeze_seams), live parity 91/91 "
"(scripts/check_event_envelope_parity.py), gofmt/vet/go build clean, "
"Python suite green both pins (25 live + 25 pinned), dichotomy "
"audit 5/8 -> 8/8 FULL"
),
}], scope_files=[
"src/rune/event_envelope.py",
"src/go/event-bus/envelope.go",
"src/go/event-bus/bus.go",
"src/go/event-bus/main.go",
"src/go/event-bus/truth_envelope.json",
"src/go/event-bus/truth_envelope_test.go",
"scripts/gen_event_envelope_truth.py",
"scripts/check_event_envelope_parity.py",
"scripts/ee_freeze_seams/sitecustomize.py",
])
print("close:", "ok" if closed.get("success") else json.dumps(closed)[:400])
if not closed.get("success"):
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)