Files
rune/scripts/gen_memory_selector_truth.py
Nick 6bdd28521a feat(memory_selector): close PARTIAL gaps — dichotomy wave
The audit named three unported fns (11/14 PARTIAL): add_source,
_source_store, _mse_core. All three now have Rust counterparts —
audit 14/14 FULL, missing [].

parity: add_source is the registry decision KERNEL (mse_add_source) —
registration order is execution order, re-registering replaces IN PLACE
(dict insertion order keeps position); the facade applies the kernel's
order as authoritative while carrying the caller's fn. _source_store's
persona-lane gate delegates through the already-frozen mse_persona_wanted
(lane runs iff wanted==[]) and its merge through mse_store_project; the
sqlite IO stays Python per the port law. _mse_core is the facade's
delegation probe (machinery — the pin honored inside mse_loader.core);
its CONTRACT is frozen (pin -> python floor) and the seam map is
documented in the crate header.

Freeze rig (scripts/ms_freeze_seams, the memory_consolidation pattern):
fixed-path hermetic store seeded via add_entry — raw INSERTs bypass
entries_fts and recall abstains on every row (the first freeze attempt's
empty truths were exactly that bug); embeddings off, lexical-only.
10-row truth: pin contract, source_names, 4 registry-order rows
(append/replace-in-place/solo/replace-keeps-tail), 4 _source_store E2E
rows (lane merge, persona-lane dedup by entry id, typed lane skip,
trivial abstain). Byte-identical: 2 generation runs + 2 --verify runs.

Battery 9/9 (gap truth embedded via include_str! — the ms_add_source
rows replay through the kernel; E2E rows replay in the live-parity gate).
Live parity 536/536: frozen FFI rows, 522 fuzz registry ops (seed 2479)
oracle dict vs kernel, dual-mode facade (RUNE_MSE_CORE=python vs live
core) on _source_store/add_source/select_for_task — identical outputs.
clippy --all-targets -D warnings 0. Python both pins: test_p1_03 66
passed + 2 pre-existing worktree failures (cached_recall, unrelated,
pass in main checkout — verified identical on the stashed base);
test_context_broker 18/18 both pins. ruff clean.
2026-10-13 18:31:51 +01:00

85 lines
3.6 KiB
Python

#!/usr/bin/env python3
"""gen_memory_selector_truth.py — factory wave GAP truth for memory_selector.
Freezes the oracle behavior of the 3 audit-gap functions (dichotomy wave
#2479: add_source registry, _source_store pinned recall, _mse_core probe
contract) through the SHARED harness (scripts/freeze_truth.py — one law).
Runs under the freeze rig (scripts/ms_freeze_seams/sitecustomize.py —
PYTHONPATH-imported by BOTH this generator and --verify): pinned MSE floor,
hermetic FIXED-path seeded store (FTS-populated via add_entry so recall's
BM25 gate actually fires — raw INSERTs bypass entries_fts and recall
abstains), embeddings off, and the ms_add_source seam that drives the REAL
add_source with JSON-safe shapes.
Run (from the repo root):
PYTHONHASHSEED=0 PYTHONPATH=scripts/ms_freeze_seams:src \
python3 scripts/gen_memory_selector_truth.py
Verify (byte-identical, same rig):
PYTHONHASHSEED=0 PYTHONPATH=scripts/ms_freeze_seams:src \
python3 scripts/freeze_truth.py --verify \
src/rust/memory_selector/frozen_truth.json \
--module rune.memory_selector
Case map (every gap branch):
* _mse_core — RUNE_MSE_CORE=python pin honored -> None (the probe
contract the facade's delegation gate owns).
* source_names — registry read on a bare receiver.
* ms_add_source — append (zz_custom after the six defaults),
position-preserving replace (re-registered store stays
FIRST — dict insertion order), solo, and replace-keeps-
tail (a -> a, b).
* _source_store — pinned-db typed recall E2E: untyped k8s (persona lane
runs, merges nothing new), untyped persona query (lane
overlap deduped by entry id — one row, not two), typed
self (lane skipped), trivial query (abstains -> []).
"""
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))
from freeze_truth import freeze, write # noqa: E402
import rune.memory_selector as oracle # noqa: E402
PINNED = oracle._mse_PINNED_STORE
DEFAULT_NAMES = ["store", "neurons", "graphs", "abstraction", "consolidated", "persona"]
def _recv():
return {"cls": "MemorySelector", "db_path": PINNED,
"min_score": 0.42, "_sources": {}}
cases = [
# _mse_core: the pin contract (RUNE_MSE_CORE=python -> python floor).
("_mse_core", (), {}),
# source_names on a bare receiver.
{"fn": "MemorySelector.source_names", "recv": _recv(), "args": [], "kwargs": {}},
# add_source via the seam: append / position-preserving replace / solo.
("ms_add_source", (DEFAULT_NAMES, "zz_custom"), {}),
("ms_add_source", (DEFAULT_NAMES, "store"), {}),
("ms_add_source", ([], "solo"), {}),
("ms_add_source", (["a", "b"], "a"), {}),
# _source_store E2E on the seeded pinned store.
{"fn": "MemorySelector._source_store", "recv": _recv(),
"args": ["kubernetes pods restart", [], 4, 0.42], "kwargs": {}},
{"fn": "MemorySelector._source_store", "recv": _recv(),
"args": ["voice identity speaking style", [], 4, 0.42], "kwargs": {}},
{"fn": "MemorySelector._source_store", "recv": _recv(),
"args": ["kubernetes pods restart", ["self"], 4, 0.42], "kwargs": {}},
{"fn": "MemorySelector._source_store", "recv": _recv(),
"args": ["zebraquant fibers", [], 4, 0.42], "kwargs": {}},
]
truth = freeze("rune.memory_selector", cases,
oracle_module="rune.memory_selector")
dest = REPO / "src" / "rust" / "memory_selector" / "frozen_truth.json"
write(truth, dest)
print(f"wrote {len(truth)} cases -> {dest}")