Walked draft->approved->building->verifying->closed in ONE process via the designed iface.close() entry (quality-gate law). Contract covers the tier_manager 6/10 -> 10/10 RUST gap-close into cognition_core. observations.jsonl carries 14 additional rows from interface test traffic (test-kernel-rebuild-trap regression + minidoc-test x2) produced by a platform daemon (mimo-wait-resume) whose cwd resolved into this worktree at 15:03-15:15Z; those rows are real append-only events but their entity files are deliberately NOT committed (test-probe artifacts, not lane work). Flagged to the coordinator.
165 lines
7.8 KiB
Python
165 lines
7.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Close the #2479 dichotomy-wave tier_manager gap contract (Rust port,
|
|
cognition_core extension) in ONE process (shared-store clobber hazard;
|
|
segment transitions can take ~60s each — do NOT split across processes).
|
|
|
|
QUALITY-GATE LAW (scaffold.py, 2026-10-13): entering `closed` happens via
|
|
iface.close(contract_id, observed_evidence=..., scope_files=...) — the
|
|
predicted-vs-observed quality computation — never a raw transition.
|
|
|
|
Resumable: if an open factory-gap-cz-db contract already exists in the
|
|
store (e.g. a prior walk stopped at `verifying`), the LATEST is resumed
|
|
and duplicates are abandoned with a note. Otherwise the canonical
|
|
submit_need → approved → building → verifying walk runs first.
|
|
|
|
Usage: close_contract_tier_manager.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 = "4890e4f5"
|
|
PHASE_B_SHA = "eb6ea1f4"
|
|
EVIDENCE = f"parity {PARITY_SHA}"
|
|
|
|
NEED_TEXT = (
|
|
"tier_manager dichotomy gap-close (RUST): name-preserving port of the 4 "
|
|
"audit-missing functions (demotion_sweep, get_tier_config, should_search, "
|
|
"should_compress) into src/rust/cognition_core (tier_demotion_sweep / "
|
|
"tier_get_tier_config / tier_should_search / tier_should_compress kernels "
|
|
"+ cc_tier_* FFI + cc_loader wrappers + tier_manager facade delegation "
|
|
"with load-bearing _py fallbacks), extending cognition_core per the audit "
|
|
"alias — tier_manager's live delegation chain is cc_loader → "
|
|
"libcognition_core.so. Parity-driven defect fix: parse_strict_aware "
|
|
"gained datetime.fromisoformat calendar-range validation (month 13, Feb "
|
|
"30, day 0, hour 24 with nonzero minutes raise in the oracle → warm "
|
|
"fallback; the old fixed-position parser computed off-calendar epochs); "
|
|
"recorded as quirk #22 in docs/dichotomy-oracle-quirks.json. Frozen-truth "
|
|
"battery: frozen_tier_truth.json 121 cases via the shared freeze_truth.py "
|
|
"harness (byte-identical across gen x2 and --verify x2, RUNE_COGNITION_"
|
|
"CORE=python oracle pin) + frozen_tier_methods.json kernel-shaped rows, "
|
|
"both embedded VERBATIM in the cfg(test) tier_battery. Live parity "
|
|
"1720/1720 via scripts/check_tier_parity.py (frozen rows + seeded fuzz + "
|
|
"config fuzz, both clocks pinned). cargo test + clippy -D warnings clean; "
|
|
"ruff clean; Python suite green both pins (12 passed live + 12 pinned "
|
|
"RUNE_COGNITION_CORE=python); collateral green with kernels resolved "
|
|
"(shims+tier+witness 59/59, cognition consumers 109/109). Delegation "
|
|
"suite recency cases made drift-immune (relative timestamps). Phase B "
|
|
"language-advantage pass: exhaustive bracket match in tier_get (single "
|
|
"decision, single allocation) + TIER_CONFIG closed-set const table as "
|
|
"the one source for config lookup and the should_* projections. "
|
|
"Dichotomy audit 6/10 PARTIAL -> 10/10 FULL. Delivered on gitea/master: "
|
|
"feat " + PARITY_SHA + " + phase B " + PHASE_B_SHA + "."
|
|
)
|
|
|
|
OBSERVED_DETAIL = (
|
|
f"tier_manager RUST dichotomy completion — parity commit {PARITY_SHA}, "
|
|
f"phase B {PHASE_B_SHA}; fn coverage 6/10 PARTIAL -> 10/10 FULL (audit "
|
|
"regenerated, tier_manager row now 10/10 RUST); frozen truth 121 harness "
|
|
"cases byte-identical across gen x2 and freeze_truth --verify x2 "
|
|
"(src/rust/cognition_core/src/frozen_tier_truth.json, scripts/"
|
|
"gen_tier_truth.py); cargo battery replays it + frozen_tier_methods.json "
|
|
"verbatim (tier_battery.rs, 3 battery fns, 65 unit + 5 doc green); live "
|
|
"parity 1720/1720 via scripts/check_tier_parity.py (frozen rows + seeded "
|
|
"fuzz + config fuzz, both clocks pinned); clippy -D warnings + cargo fmt "
|
|
"clean; Python suite green both pins (12 passed live + 12 passed "
|
|
"RUNE_COGNITION_CORE=python); collateral green with kernels resolved "
|
|
"(*_RUST_LIB at the main checkout, CC at this worktree's build): shims+"
|
|
"tier+witness 59/59 and cognition consumers 109/109. Fix-first: "
|
|
"parse_strict_aware fromisoformat calendar-range validation (quirk #22, "
|
|
"docs/dichotomy-oracle-quirks.json) — proven by the frozen battery's "
|
|
"crash-class rows. Documented divergences: sub-second last_accessed "
|
|
"excluded from truth corpora (kernel parser is seconds-resolution, "
|
|
"fractional seconds dropped per the W3.4 seam); bool wash_count "
|
|
"truthiness equal on both sides (bracket decision identical). Phase B: "
|
|
"exhaustive bracket match in tier_get + TIER_CONFIG closed-set const "
|
|
"table driving config/should_search/should_compress (single source of "
|
|
"truth mirroring the oracle's one dict). Evidence files: verification/"
|
|
"tier-*.{log,exit} + verification/summary-tier_manager.md."
|
|
)
|
|
|
|
SCOPE_FILES = [
|
|
"src/rune/tier_manager.py",
|
|
"src/rune/cc_loader.py",
|
|
"src/rust/cognition_core/src/broker.rs",
|
|
"src/rust/cognition_core/src/lib.rs",
|
|
"src/rust/cognition_core/src/tier_battery.rs",
|
|
"src/rust/cognition_core/src/frozen_tier_truth.json",
|
|
"src/rust/cognition_core/src/frozen_tier_methods.json",
|
|
"scripts/gen_tier_truth.py",
|
|
"scripts/check_tier_parity.py",
|
|
"scripts/close_contract_tier_manager.py",
|
|
"tests/test_tier_delegation.py",
|
|
"docs/dichotomy-rebase-honest-audit.md",
|
|
"docs/dichotomy-oracle-quirks.json",
|
|
]
|
|
|
|
iface = ConstructionInterface(builder="factory-gap-cz-db")
|
|
|
|
# ── resume-or-submit ────────────────────────────────────────────────────────
|
|
def _open_factory_gap_cz_db(d):
|
|
found = []
|
|
for ent in d.get("entities", []):
|
|
cid = ent.get("id", "")
|
|
if isinstance(cid, str) and cid.startswith("contract:BUILDER-") \
|
|
and cid.endswith("factory-gap-cz-db") \
|
|
and ent.get("phase") not in ("closed", "abandoned", "failed"):
|
|
found.append((cid[len("contract:"):], ent.get("phase")))
|
|
return sorted(found)
|
|
|
|
|
|
doc = iface.scaffold.load()
|
|
existing = _open_factory_gap_cz_db(doc)
|
|
if existing:
|
|
cid, phase = existing[-1] # latest wins
|
|
print(f"resuming contract {cid} (phase {phase}); "
|
|
f"{len(existing) - 1} duplicate(s) to abandon")
|
|
for dup_cid, _ in existing[:-1]:
|
|
r = iface.transition(dup_cid, "abandoned",
|
|
evidence_ref="duplicate submission — close walk "
|
|
"retried after a refused raw "
|
|
"closed transition (quality-gate law)")
|
|
print(f"abandoned {dup_cid}:", "ok" if r.get("success") else json.dumps(r)[:200])
|
|
if not r.get("success"):
|
|
sys.exit(1)
|
|
else:
|
|
r = iface.submit_need(NEED_TEXT, 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)
|
|
for phase in ("approved", "building", "verifying"):
|
|
t = iface.transition(cid, 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)
|
|
|
|
# ── the designed entry to `closed`: close() computes contract_quality ──────
|
|
c = iface.close(cid, observed_evidence=[{
|
|
"kind": "port_evidence",
|
|
"detail": OBSERVED_DETAIL,
|
|
}], scope_files=SCOPE_FILES)
|
|
print("close:", json.dumps(c)[:300])
|
|
if not c.get("success"):
|
|
sys.exit(1)
|
|
|
|
doc = iface.scaffold.load()
|
|
e = iface.scaffold.contract(doc, cid)
|
|
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
|
|
if not e or e.get("phase") != "closed":
|
|
sys.exit(1)
|
|
print("CLOSED", cid)
|