Files
rune/scripts/close_contract_memory_store_retrieval.py
T

153 lines
7.1 KiB
Python

#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave memory_store RETRIEVAL family gap contract
(GO port, builder factory-heavy-ms-rtrv). Full lifecycle walk in ONE process
(shared-store clobber hazard). 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.
Carries the already-pushed parity SHAs as evidence:
feat a4930cdb close retrieval-family audit gaps — dichotomy wave
refactor 3759ade2 Phase B language-advantage pass — retrieval family
Usage: close_contract_memory_store_retrieval.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 = "a4930cdb"
PHASEB_SHA = "3759ade2"
EVIDENCE = f"parity {PARITY_SHA}, phase B {PHASEB_SHA}"
NEED = (
"memory_store retrieval-family dichotomy gap-close (GO): "
"name-preserving port of the 12 audit-missing retrieval/ranking fns "
"into src/go/memory-store-deep/gaps_retrieval.go (NEW family file, "
"siblings untouched) — cached_recall, mr_rank_fusion, _fts_delete, "
"chunk_recall, fused_recall, recall_with_associations, "
"_merge_association_rows, curiosity_probe, tier_demotion_sweep (+the "
"TierGet ladder), _mr_core, _df_word, _df. SQLite row-fetch, embedding, "
"cache/shard/drift IO stay facade-side per the landed crate's seams; "
"every kernel is a pure transform over pre-fetched rows or injectable "
"seams. Deterministic-kernel authority is the Rust memory_retrieval "
"crate (banker's rounding, stable sorts, char-based slicing, "
"null-preserving projection) — mirrored, not re-derived. Frozen truth "
"43 rows (truth_retrieval_gaps.json): pure fns via the shared "
"freeze_truth harness, db-bound fns via fixture stores under rigs "
"(_embed off, fake cache/shard recorders, frozen clocks on "
"memory_store+tier_manager, drift_core._now_iso pinned, "
"RUNE_COGNITION_CORE=python, memory_retrieval+memory_scoring built "
"in-tree) — byte-identical across 5 regenerations. Battery "
"gaps_retrieval_test.go replays canonically with GAPS_TRUTH_PATH "
"override; live parity 43/43 (fresh live-oracle capture -> Go battery) "
"via scripts/check_memory_store_retrieval_parity.py; gofmt/vet/build/"
"test clean; Python suite failure sets BYTE-IDENTICAL to the stashed "
"base in BOTH pins (RUNE_RETRIEVAL_CORE live + python); ruff clean. "
"Documented divergences: (1) landed sibling FuseResults substitutes "
"'fact'/'research' for EMPTY topics where the Rust authority keeps '' "
"(FusedRecall implements the authority in-family; sibling left "
"untouched, follow-up recommended); (2) tier_demotion_sweep "
"structurally never demotes (demotion_sweep IS get_tier) — ported "
"honestly with the comparison, pinned by sweep_never_demotes; (3) "
"curiosity_probe self-match is the norm; (4) put-value serialization "
"stays facade-side. Audit: memory_store 30/68 -> 44/68; the retrieval "
"family's missing list is now EMPTY (_embed/linked_entries counters "
"also flip on prose mentions in doc comments — NOT ports, reported as "
"such). Delivered on gitea/master: feat " + PARITY_SHA + ", phase B "
+ PHASEB_SHA + "."
)
iface = ConstructionInterface(builder="factory-heavy-ms-rtrv")
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": "memory_store retrieval-family dichotomy completion — "
f"parity {PARITY_SHA} feat(memory_store): close "
"retrieval-family audit gaps — dichotomy wave; pushed "
"gitea/master after fetch+rebase (ancestor-verified). "
"Go kernels at src/go/memory-store-deep/gaps_retrieval.go "
"close the family's audit gaps name-preserving (12 fns; "
"family missing list EMPTY). Generator scripts/"
"gen_memory_store_retrieval_truth.py: 43-row frozen truth "
"(shared freeze_truth harness for the pure kernels + "
"fixture-store rigs for the db-bound fns: _embed off, "
"fake cache/shard recorders, frozen clocks, "
"RUNE_COGNITION_CORE=python, memory_retrieval + "
"memory_scoring .so built in-tree) regenerates "
"byte-identical (--check green twice post-rebase). "
"Battery gaps_retrieval_test.go replays the truth "
"canonically (key-order-safe); live parity scripts/"
"check_memory_store_retrieval_parity.py 43/43 (fresh "
"live-oracle capture through the Go battery via "
"GAPS_TRUTH_PATH); gofmt/vet/build/go test clean; Python "
"suite both pins: failure sets byte-identical to the "
"stashed base; ruff clean. Divergences documented in "
"verification/msr-summary.md: sibling FuseResults "
"empty-topic substitution (authority implemented "
"in-family, sibling untouched); tier_demotion_sweep "
"structurally never demotes (pinned); curiosity "
"self-match; put-value serialization facade-side. Phase "
f"B {PHASEB_SHA}: MergeAssociationRows base-rel fold "
"O(n^2)->running max, numerically identical to the "
"authority (chained-boost truth rows pin it) — battery + "
"parity re-green.",
}],
scope_files=[
"src/go/memory-store-deep/gaps_retrieval.go",
"src/go/memory-store-deep/gaps_retrieval_test.go",
"src/go/memory-store-deep/truth_retrieval_gaps.json",
"scripts/gen_memory_store_retrieval_truth.py",
"scripts/check_memory_store_retrieval_parity.py",
"verification/msr-summary.md",
],
)
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)