Port the 8 audit-gap fns to Rust (name-preserving): _ms_core, _now_iso, promote_entry, compute_fama, compute_drift_velocity, compute_drift_direction, pre_commit_gate, pre_commit_gate_entry. The scoring surface delegates to memory_scoring (path dep — the authoritative kernel since its Python oracle was retired); the new decision kernels live in src/rust/drift_core while the sqlite IO stays in the facade (RUNE_DRIFT_CORE pin, dcore_loader seam, doc-envelope FFI, Python-typed JSON output: int/float split preserved). Audit 3/11 PARTIAL -> 12/12 FULL RUST. 30-row frozen truth (dc_freeze_seams rig, shared harness, gen+verify byte-identical x3), Rust battery 3/3 with the truth embedded via include_str!, live parity 30 frozen + 600 fuzz + 11 dual-mode facade rows failures=0, clippy -D warnings 0, fmt clean, pytest both pins 41 passed/4 skipped (drift-files test_211d_g failure verified pre-existing on the stashed base), ruff clean.
267 lines
8.8 KiB
Python
267 lines
8.8 KiB
Python
#!/usr/bin/env python3
|
|
"""gen_drift_core_truth.py — factory wave GAP truth for drift_core.
|
|
|
|
Freezes the oracle behavior of the 8 audit-gap functions (dichotomy wave
|
|
#2479: _ms_core, _now_iso, promote_entry, compute_fama,
|
|
compute_drift_velocity, compute_drift_direction, pre_commit_gate,
|
|
pre_commit_gate_entry) plus scoring-surface regression rows (compute_value,
|
|
check_promotion_eligibility) through the SHARED harness
|
|
(scripts/freeze_truth.py — one law).
|
|
|
|
Runs under the freeze rig (scripts/dc_freeze_seams/sitecustomize.py —
|
|
PYTHONPATH-imported by BOTH this generator and --verify): pinned floor
|
|
(RUNE_DRIFT_CORE=python), frozen clock (RUNE_FROZEN_NOW reaches _now_iso
|
|
and the velocity cutoff through the harness's module-datetime patch),
|
|
hermetic per-row scratch store, embeddings off, and the db-carrying seams
|
|
(promote/fama/velocity/direction/gate) that drive the REAL oracle fns with
|
|
JSON-safe shapes. The memory_scoring kernel is intentionally LIVE (its
|
|
Python oracle is retired and raises — determinism requires the built .so;
|
|
the rig fails loudly when it is missing).
|
|
|
|
Run (from the repo root, under the sqlite-vec venv):
|
|
PYTHONHASHSEED=0 PYTHONPATH=scripts/dc_freeze_seams:src \
|
|
~/.venvs/memory/bin/python3 scripts/gen_drift_core_truth.py
|
|
|
|
Verify (byte-identical, same rig):
|
|
PYTHONHASHSEED=0 PYTHONPATH=scripts/dc_freeze_seams:src \
|
|
~/.venvs/memory/bin/python3 scripts/freeze_truth.py --verify \
|
|
src/rust/drift_core/frozen_truth.json \
|
|
--module rune.drift_core
|
|
|
|
Case map (every gap branch):
|
|
* _now_iso — None (frozen clock) + passthrough.
|
|
* _ms_core — probe contract True under the rig (kernel live).
|
|
* compute_value — no-goals + goals rows (ms-kernel regression).
|
|
* check_promotion_eligibility — eligible tuple row.
|
|
* pre_commit_gate_entry — short / refusal / well-formed critics.
|
|
* dc_freeze_gate — the empty oracle body (None → null).
|
|
* dc_freeze_promote — not-found / already-rock / ineligible-low-wash /
|
|
washable→established / established→rock /
|
|
unknown-status→established; `after` pins the UPDATE.
|
|
* dc_freeze_fama — empty ids / all-valid / mixed / missing rows /
|
|
inactive / null-wash+established.
|
|
* dc_freeze_velocity — inside+outside window / over-threshold alert /
|
|
days=0 (max(1,·) floor) / integral 2.0 rounding.
|
|
* dc_freeze_direction — stable / drifting / empty store / rock-only.
|
|
"""
|
|
|
|
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_envelope # noqa: E402
|
|
|
|
NOW = "2026-10-13T12:00:00.123456+00:00"
|
|
IN_WINDOW = "2026-10-12T00:00:00.000000+00:00" # 1.5 days before NOW
|
|
OUT_WINDOW = "2026-10-01T00:00:00.000000+00:00" # far outside 7 days
|
|
# After the days=-3 cutoff (NOW + 3d): negative windows only see future rows.
|
|
NEG_WINDOW = "2026-10-17T00:00:00.000000+00:00"
|
|
|
|
cases = [
|
|
# _now_iso: frozen-clock branch + passthrough branch.
|
|
("_now_iso", (None,), {}),
|
|
("_now_iso", ("2026-01-02T03:04:05.666666+00:00",), {}),
|
|
# _ms_core probe contract: kernel delegation live under the rig.
|
|
("dc_freeze_ms_core", (), {}),
|
|
# Scoring-surface regression (delegates to the live ms kernel; the
|
|
# clock is frozen so the value is deterministic).
|
|
(
|
|
"compute_value",
|
|
({"text": "k8s pods restart on failure", "wash_count": 25,
|
|
"importance": 0.8, "rock_status": "washable"},),
|
|
{},
|
|
),
|
|
(
|
|
"compute_value",
|
|
({"text": "voice stays consistent", "wash_count": 3,
|
|
"importance": 0.6, "rock_status": "washable"},),
|
|
{"current_goals": ["voice consistency"]},
|
|
),
|
|
(
|
|
"check_promotion_eligibility",
|
|
({"text": "k8s pods restart on failure", "wash_count": 25,
|
|
"importance": 0.8, "rock_status": "washable"},),
|
|
{},
|
|
),
|
|
# pre_commit_gate_entry critics: short / refusal / well-formed.
|
|
(
|
|
"pre_commit_gate_entry",
|
|
({"text": "no"},),
|
|
{},
|
|
),
|
|
(
|
|
"pre_commit_gate_entry",
|
|
({"text": "I'm sorry, but I can't help with that request"},),
|
|
{},
|
|
),
|
|
(
|
|
"pre_commit_gate_entry",
|
|
({"text": "Kubernetes pods restart on failure"},),
|
|
{},
|
|
),
|
|
# pre_commit_gate: the empty oracle body.
|
|
("dc_freeze_gate", (7,), {}),
|
|
# promote_entry ladder.
|
|
(
|
|
"dc_freeze_promote",
|
|
(None, 999),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_promote",
|
|
({"text": "locked identity anchor", "wash_count": 40,
|
|
"importance": 0.9, "rock_status": "rock"}, 1),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_promote",
|
|
({"text": "barely washed entry", "wash_count": 5,
|
|
"importance": 0.9, "rock_status": "washable"}, 2),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_promote",
|
|
({"text": "proven deployment runner", "wash_count": 25,
|
|
"importance": 0.8, "rock_status": "washable"}, 3),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_promote",
|
|
({"text": "proven established entry", "wash_count": 25,
|
|
"importance": 0.8, "rock_status": "established"}, 4),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_promote",
|
|
({"text": "proven unknown-status entry", "wash_count": 25,
|
|
"importance": 0.8, "rock_status": "weird"}, 5),
|
|
{},
|
|
),
|
|
# compute_fama.
|
|
("dc_freeze_fama", ([], "anything", []), {}),
|
|
(
|
|
"dc_freeze_fama",
|
|
(
|
|
[
|
|
{"status": "active", "rock_status": "washable", "wash_count": 5},
|
|
{"status": "active", "rock_status": "established", "wash_count": 0},
|
|
],
|
|
"deploy runner",
|
|
[1, 2],
|
|
),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_fama",
|
|
(
|
|
[
|
|
{"status": "active", "rock_status": "washable", "wash_count": 5},
|
|
None,
|
|
{"status": "retired", "rock_status": "rock", "wash_count": 9},
|
|
],
|
|
"deploy runner",
|
|
[1, 2, 3],
|
|
),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_fama",
|
|
(
|
|
[
|
|
{"status": "active", "rock_status": "established", "wash_count": None},
|
|
{"status": "active", "rock_status": "washable", "wash_count": 0},
|
|
],
|
|
"voice identity",
|
|
[1, 2],
|
|
),
|
|
{},
|
|
),
|
|
# compute_drift_velocity: window membership, alert, floor, rounding.
|
|
(
|
|
"dc_freeze_velocity",
|
|
(
|
|
[
|
|
{"last_washed": IN_WINDOW, "status": "active",
|
|
"rock_status": "washable"},
|
|
{"last_washed": OUT_WINDOW, "status": "active",
|
|
"rock_status": "established"},
|
|
],
|
|
7,
|
|
),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_velocity",
|
|
(
|
|
[
|
|
{"last_washed": IN_WINDOW, "status": "active",
|
|
"rock_status": "established"},
|
|
{"last_washed": IN_WINDOW, "status": "retired",
|
|
"rock_status": "rock"},
|
|
{"last_washed": IN_WINDOW, "status": "active",
|
|
"rock_status": "rock"},
|
|
],
|
|
1,
|
|
),
|
|
{},
|
|
),
|
|
("dc_freeze_velocity", ([], 0), {}),
|
|
(
|
|
"dc_freeze_velocity",
|
|
([{"last_washed": IN_WINDOW, "status": "active",
|
|
"rock_status": "washable"}] * 14, 7),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_velocity",
|
|
([{"last_washed": IN_WINDOW, "status": "active",
|
|
"rock_status": "washable"}] * 22, 2),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_velocity",
|
|
(
|
|
[
|
|
{"last_washed": NEG_WINDOW, "status": "active",
|
|
"rock_status": "washable"},
|
|
{"last_washed": NEG_WINDOW, "status": "active",
|
|
"rock_status": "established"},
|
|
{"last_washed": IN_WINDOW, "status": "active",
|
|
"rock_status": "rock"},
|
|
],
|
|
-3,
|
|
),
|
|
{},
|
|
),
|
|
# compute_drift_direction.
|
|
(
|
|
"dc_freeze_direction",
|
|
(
|
|
[
|
|
{"status": "active", "rock_status": "washable"},
|
|
{"status": "active", "rock_status": "established"},
|
|
{"status": "active", "rock_status": "rock"},
|
|
],
|
|
),
|
|
{},
|
|
),
|
|
(
|
|
"dc_freeze_direction",
|
|
([{"status": "active", "rock_status": "washable"}] * 5,),
|
|
{},
|
|
),
|
|
("dc_freeze_direction", ([],), {}),
|
|
(
|
|
"dc_freeze_direction",
|
|
([{"status": "retired", "rock_status": "rock"}],),
|
|
{},
|
|
),
|
|
]
|
|
|
|
truth = freeze("rune.drift_core", cases, oracle_module="rune.drift_core")
|
|
dest = REPO / "src" / "rust" / "drift_core" / "frozen_truth.json"
|
|
write_envelope(NOW, truth, dest)
|
|
print(f"wrote {len(truth)} cases -> {dest}")
|