Files
OBLITERATUS/tests/test_confirmation_registry.py
Joseph MaglyandClaude Opus 5.5 77d788b22c feat(experiments): confirmation and maturation registry
Add the confirmation registry (F15): freeze what decides a confirmation
before its results are unlocked, track exposure of confirmation data,
and compute maturity from referenced evidence.

- Append-only registry under <run>/registry with a schema file as
  authority. A registration freezes, by digest, the dossier binding,
  the full intervention spec, scorers, threshold, direction, margins,
  decision dose, target task, seeds and the confirmation row set (text
  digests only). Edited registrations fail their id; changes need an
  amendment, counted as a new comparison.
- Unlocking requires a matching frozen registration: the result must
  come from the frozen spec after registration, on the frozen rows, with
  an unchanged dossier, and its verdict is recomputed from its records.
- Every evaluation and unlock is logged as an exposure. Exposed rows are
  refused as inputs to discovery, example selection and causal maps,
  and for any later confirmation of any target. Runs without a registry
  are unchanged; an optional registry_dir covers outputs outside the
  run.
- Replications must reuse the recipe with different seeds and disjoint
  rows. Non-supported verdicts are negative entries that mark the target
  for re-investigation and require fresh data.
- Maturity per (target, method, model revision, task, backend) is
  computed: hypothesis, candidate, causal, replicated, persistent-pilot
  eligible (which also needs a current dossier). Fixture results never
  count by default; claims above the computed level are refused.
- The pain pack's declared protocol registers as the first candidate
  after reference and prompt-digest verification; with no answer keys it
  stays at hypothesis, marked descriptive only.
- `obliteratus experiments registry register|unlock|replicate|status`,
  a Python API and an Explorer section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 22:15:04 -05:00

337 lines
19 KiB
Python

"""Confirmation registry: frozen registrations, locked rows, exposure, replication, maturity.
Fixtures reuse the controlled-intervention harness (``tests/test_controlled_interventions.py``):
a planted model whose yes/no head reads the dossier's ``channel:layer.0:2`` estimate
and a null model whose head ignores it. The pack's select rows 44..55 move to the
calibrate role (the first confirmation set) and 56..69 to the locked test role (an
independent partition for replications and fresh re-confirmation); 56 is even, so
no family pair is split.
"""
from __future__ import annotations
import json
import shutil
from types import SimpleNamespace
import pytest
from obliteratus.concepts.pack import ConceptPack
from obliteratus.experiments import registry as reg
from obliteratus.experiments.intervention_runner import run_intervention
from obliteratus.experiments.registry_status import status
from obliteratus.experiments.registry_store import (
ExposedRows, Registry, RegistryRefused, assert_unexposed,
)
from tests.test_controlled_interventions import AnswerModel, AnswerTokenizer, _run, make_spec
from tests.test_labeled_activations import build_pack
pytestmark = pytest.mark.cpu
def _partition(layout):
for path, rows in layout.items():
for row in rows:
row["answer"] = "yes"
index = int("".join(c for c in row["id"] if c.isdigit()) or -1)
if not path.startswith("battery/") and row["role"] == "select" and index >= 44:
row["role"] = "calibrate" if index < 56 else "test"
def _answers_only(layout):
for rows in layout.values():
for row in rows:
row["answer"] = "yes"
@pytest.fixture(scope="module")
def env(tmp_path_factory):
root = tmp_path_factory.mktemp("registry")
pack = build_pack(root / "pack", _partition)
pack.location = root / "pack"
# The same rows partitioned differently: earlier calibrate rows are select rows here.
repartitioned = build_pack(root / "pack2", _answers_only)
planted, null = AnswerModel(), AnswerModel(reads_channel=False)
return {"root": root, "pack": pack, "pack2": repartitioned, "planted": planted, "null": null,
"planted_run": _run(root, pack, "planted", planted, "local/answers"),
"null_run": _run(root, pack, "null", null, "fixture/answers-null")}
def spec(env, role="calibrate", seed=0, control=7, null=False, **changes):
dataset = {"role": role, **({"allow_locked_test": True} if role == "test" else {})}
model = {"model": {"id": "fixture/answers-null"}} if null else {}
return make_spec(env["pack"], dataset=dataset, seed=seed, control={"seed": control},
**model, **changes)
def run_spec(env, run, value, null=False, **options):
model = env["null" if null else "planted"]
factory = lambda section: SimpleNamespace(model=model, tokenizer=AnswerTokenizer()) # noqa: E731
return run_intervention(value, run, model_factory=factory, pack_resolver=ConceptPack.load,
**options)
def copy_run(source, target):
shutil.copytree(source, target)
return target
def register(run, value, **options):
return reg.register(run, value, pack_resolver=ConceptPack.load, **options)
def replicate(run, parent, value):
return reg.replicate(run, parent, value, pack_resolver=ConceptPack.load)
@pytest.fixture(scope="module")
def confirmed(env, tmp_path_factory):
"""A planted run with one confirmation registered, evaluated and unlocked."""
run = copy_run(env["planted_run"], tmp_path_factory.mktemp("confirmed") / "run")
document = register(run, spec(env), actor="tester")
result = run_spec(env, run, spec(env))
unlocked = reg.unlock(run, document["id"], result["location"]["result"], actor="tester")
return {"run": run, "registration": document, "unlocked": unlocked}
def test_unlock_needs_the_matching_frozen_registration_and_frozen_fields_never_change(
env, tmp_path):
run = copy_run(env["planted_run"], tmp_path / "run")
early = run_spec(env, run, spec(env))
with pytest.raises(RegistryRefused, match="register first"):
reg.unlock(run, "sha256:" + "0" * 64, early["location"]["result"])
document = register(run, spec(env), actor="tester")
from jsonschema import Draft202012Validator
from obliteratus.experiments.registry_store import schema
Draft202012Validator.check_schema(schema())
Draft202012Validator(schema()).validate(document)
event = {"$ref": "#/$defs/event", "$defs": schema()["$defs"]}
Draft202012Validator(event).validate(Registry(run).events()[0])
frozen = document["frozen"]
assert frozen["thresholds"] == {"useful_effect_threshold": 0.5, "effect_direction": "increase",
"collateral_margin": 0.2, "decision_coefficient": 6.0,
"target_task": "flip"}
assert frozen["scorers"] == [{"task": "flip", "id": "exact_answer", "version": 1},
{"task": "keep", "id": "exact_answer", "version": 1}]
assert frozen["confirmation"]["role"] == "calibrate" and frozen["confirmation"]["n_rows"] == 32
assert frozen["target_key"] == {"target": "alpha/channel:layer.0:2",
"method": "steer/last_token/raw",
"model": frozen["target_key"]["model"], "task": "flip",
"backend": "transformers/cpu/float32"}
with pytest.raises(RegistryRefused, match="before the registration"):
reg.unlock(run, document["id"], early["location"]["result"])
with pytest.raises(RegistryRefused, match="No registration"):
reg.unlock(run, "sha256:" + "1" * 64, early["location"]["result"])
# Another spec on the registered rows is refused before any forward pass.
calls = env["planted"].forward_calls
with pytest.raises(reg.ConfirmationLocked, match="registered confirmation set"):
run_spec(env, run, spec(env, control=8))
assert env["planted"].forward_calls == calls
with pytest.raises(RegistryRefused, match="predictor-confirmation"):
register(run, spec(env, "select"))
with pytest.raises(RegistryRefused, match="Already registered"):
register(run, spec(env))
with pytest.raises(RegistryRefused, match="register an amendment"):
register(run, spec(env, control=8))
with pytest.raises(ValueError, match="exceeds the computed level"):
register(run, spec(env, control=8), amends=document["id"], claimed_maturity="causal")
# A frozen field edited on disk is refused.
path = run / "registry" / "registrations" / f"{document['id'][7:]}.json"
original = path.read_bytes()
edited = json.loads(original)
edited["frozen"]["thresholds"]["useful_effect_threshold"] = 0.1
path.write_text(json.dumps(edited))
with pytest.raises(RegistryRefused, match="edited after it was frozen"):
Registry(run).get(document["id"])
path.write_bytes(original)
late = run_spec(env, run, spec(env), rerun=True)
# Changing the dossier's declared thresholds after registration is refused too.
dossier = run / "dossiers" / "alpha.json"
kept = dossier.read_bytes()
changed = json.loads(kept)
changed["hypothesis"]["useful_effect_threshold"] = 0.25
dossier.write_text(json.dumps(changed))
with pytest.raises(RegistryRefused, match="changed after registration"):
reg.unlock(run, document["id"], late["location"]["result"])
dossier.write_bytes(kept)
unlocked = reg.unlock(run, document["id"], late["location"]["result"], actor="tester")
assert unlocked["outcome"] == "supported" and unlocked["negative"] is False
assert unlocked["scope"] == "software-contract"
with pytest.raises(RegistryRefused, match="already unlocked"):
reg.unlock(run, document["id"], late["location"]["result"])
events = Registry(run).events()
kinds = [e["event"] for e in events]
assert kinds.count("evaluate") == 1 and kinds.count("unlock") == 1
assert kinds.count("refused") == 4 and all(e["actor"] for e in events)
found = status(run)
assert found["refused"] == 4 and found["row_sets"][0]["exposures"] == 2
assert found["row_sets"][0]["exposed"] is True
def test_exposed_confirmation_rows_never_feed_discovery_selection_or_maps(env, confirmed,
tmp_path):
from obliteratus.experiments.causal_map import run_map
from obliteratus.experiments.discover import run_discover
from obliteratus.experiments.select_examples import run_select_examples
from tests.test_target_dossier import FAST
run, pack2 = confirmed["run"], env["pack2"]
calls = env["planted"].forward_calls
with pytest.raises(ExposedRows, match="already exposed"):
run_discover(pack2, env["planted"], AnswerTokenizer(), 0, run / "candidates-2",
model_id="local/answers", options=FAST)
with pytest.raises(ExposedRows, match="already exposed"):
run_select_examples(pack2, env["planted"], AnswerTokenizer(), 0,
run / "example-selection", model_id="local/answers")
base = spec(env)
map_spec = {k: base[k] for k in ("schema_version", "dossier", "estimate", "model", "dataset",
"tasks", "target_task", "decoding", "control")}
map_spec.update(kind="causal_targeting_map", operation={"kind": "steer", "units": "raw"},
grid={"sites": ["layer.0"], "token_scopes": ["last_token"],
"doses": [6.0]}, decision_coefficient=6.0)
with pytest.raises(ExposedRows):
run_map(map_spec, run, pack_resolver=ConceptPack.load)
# Outputs outside the run consult the run's registry when it is named explicitly.
elsewhere = tmp_path / "elsewhere"
with pytest.raises(ExposedRows):
run_discover(pack2, env["planted"], AnswerTokenizer(), 0, elsewhere / "candidates",
model_id="local/answers", options=FAST, registry_dir=run / "registry")
with pytest.raises(ExposedRows):
run_select_examples(pack2, env["planted"], AnswerTokenizer(), 0,
elsewhere / "example-selection", model_id="local/answers",
registry_dir=run / "registry")
with pytest.raises(ExposedRows):
run_map(map_spec, env["planted_run"], pack_resolver=ConceptPack.load,
registry_dir=run / "registry")
assert env["planted"].forward_calls == calls
assert not (run / "candidates-2").exists() and not (run / "maps").exists()
assert not elsewhere.exists() and not (env["planted_run"] / "maps").exists()
# Rows outside the exposed set, and any run without a registry, pass.
assert_unexposed(["neutral sample 80", "unrelated text"], run)
assert_unexposed(lambda: pytest.fail("rows read without a registry"), env["planted_run"])
def test_replication_needs_independent_seeds_and_partition(env, confirmed, tmp_path):
run = copy_run(confirmed["run"], tmp_path / "run")
parent = confirmed["registration"]["id"]
with pytest.raises(RegistryRefused, match="independently specified seeds"):
replicate(run, parent, spec(env))
with pytest.raises(RegistryRefused, match="independently specified seeds"):
replicate(run, parent, spec(env, "test", seed=3))
with pytest.raises(RegistryRefused, match="disjoint or differently partitioned"):
replicate(run, parent, spec(env, seed=3, control=9))
with pytest.raises(RegistryRefused, match="reuse the frozen recipe"):
replicate(run, parent, spec(env, "test", seed=3, control=9, decoding={"max_new_tokens": 2}))
# Another method on the same target is a separate key, untouched by the replication.
other = register(run, spec(env, "test", operation={"token_scope": "all_tokens"}))
document = replicate(run, parent, spec(env, "test", seed=3, control=9))
assert document["kind"] == "replication" and document["frozen"]["parent"] == parent
result = run_spec(env, run, spec(env, "test", seed=3, control=9))
unlocked = reg.unlock(run, document["id"], result["location"]["result"])
assert unlocked["outcome"] == "supported"
with pytest.raises(RegistryRefused, match="disjoint"):
replicate(run, parent, spec(env, "test", seed=4, control=10))
by_method = {t["target_key"]["method"]: t for t in status(run)["targets"]}
main = by_method["steer/last_token/raw"]
# Fixture-model (software-contract) results never raise maturity by default.
assert main["maturity"]["level"] == "candidate"
assert any("software-contract" in note for note in main["maturity"]["notes"])
allowed = {t["target_key"]["method"]: t for t in status(run, allow_fixture_results=True)[
"targets"]}
assert allowed["steer/last_token/raw"]["maturity"]["level"] == "persistent-pilot eligible"
assert allowed["steer/last_token/raw"]["replications"] == 1
assert allowed["steer/all_tokens/raw"]["maturity"]["level"] == "candidate"
assert allowed["steer/all_tokens/raw"]["registrations"][0]["id"] == other["id"]
assert "separate claim" in allowed["steer/last_token/raw"]["maturity"]["transfer"]
assert allowed["steer/last_token/raw"]["dossier"] == {"current": True, "reasons": []}
# A changed source report makes the dossier stale: no longer eligible, and why.
report = run / "candidates" / "layer.0-binary-fit.json"
report.write_text(report.read_text() + " ")
stale = {t["target_key"]["method"]: t for t in status(run, allow_fixture_results=True)[
"targets"]}["steer/last_token/raw"]
assert stale["maturity"]["level"] == "hypothesis"
assert stale["dossier"]["current"] is False
assert any("digest mismatch" in reason for reason in stale["dossier"]["reasons"])
assert any("dossier is stale" in note for note in stale["maturity"]["notes"])
# The unlocked results themselves still verify; only the predictor evidence lapsed.
assert {r["outcome"] for r in stale["registrations"] if r["unlocked"]} == {"supported"}
def test_failed_confirmation_is_negative_and_reconfirmation_needs_fresh_data(env, tmp_path):
run = copy_run(env["null_run"], tmp_path / "run")
document = register(run, spec(env, null=True))
result = run_spec(env, run, spec(env, null=True), null=True)
unlocked = reg.unlock(run, document["id"], result["location"]["result"])
assert unlocked["outcome"] == "not_supported" and unlocked["negative"] is True
assert unlocked["re_investigate"] is True
# A typed "supported" event cannot raise maturity: outcomes are recomputed.
Registry(run).append("unlock", document["id"], outcome="supported", scope="model-finding",
result={"path": unlocked["result"]["path"],
"sha256": unlocked["result"]["sha256"]})
[target] = status(run, allow_fixture_results=True)["targets"]
assert target["maturity"]["level"] == "candidate"
assert target["maturity"]["re_investigate"] is True
assert [n["outcome"] for n in target["negatives"]] == ["not_supported"]
with pytest.raises(reg.ConfirmationLocked):
run_spec(env, run, spec(env, null=True, control=8), null=True)
with pytest.raises(RegistryRefused, match="fresh data"):
register(run, spec(env, null=True, control=8), amends=document["id"])
fresh = register(run, spec(env, "test", null=True), amends=document["id"])
assert fresh["frozen"]["amends"] == document["id"]
with pytest.raises(RegistryRefused, match="was amended"):
reg.unlock(run, document["id"], result["location"]["result"])
[target] = status(run)["targets"]
assert (target["comparisons"], target["amendments"]) == (2, 1)
# A changed result no longer verifies and is not counted.
path = run / unlocked["result"]["path"]
path.write_text(path.read_text() + " ")
[target] = status(run)["targets"]
assert target["registrations"][0]["outcome"] == "invalid"
def test_cli_replicate_unlock_status_and_explorer_rows(env, confirmed, tmp_path, monkeypatch,
capsys):
from obliteratus.cli import main
from obliteratus.ui_evidence_registry import REGISTRY_COLUMNS, registry_rows
monkeypatch.setattr("obliteratus.experiments.inputs.default_pack_resolver", ConceptPack.load)
run = copy_run(confirmed["run"], tmp_path / "run")
parent = confirmed["registration"]["id"]
replication = tmp_path / "replication.json"
replication.write_text(json.dumps(spec(env, "test", seed=3, control=9)))
main(["experiments", "registry", "replicate", parent, str(replication), "--run", str(run),
"--actor", "tester"])
out = json.loads(capsys.readouterr().out)
assert out["kind"] == "replication" and out["parent"] == parent and out["n_rows"] == 40
result = run_spec(env, run, spec(env, "test", seed=3, control=9))
main(["experiments", "registry", "unlock", out["registration"], result["location"]["result"],
"--run", str(run)])
assert json.loads(capsys.readouterr().out)["outcome"] == "supported"
main(["experiments", "registry", "status", "--run", str(run), "--allow-fixture-results"])
[target] = json.loads(capsys.readouterr().out)["targets"]
assert target["maturity"]["level"] == "persistent-pilot eligible"
other = tmp_path / "other.json"
other.write_text(json.dumps(spec(env, "test", control=8)))
with pytest.raises(SystemExit) as refused:
main(["experiments", "registry", "register", str(other), "--run", str(run), "--amends",
parent])
assert refused.value.code == 4 and "fresh data" in capsys.readouterr().err
[row] = registry_rows(run)
assert len(row) == len(REGISTRY_COLUMNS) and row[5] == "candidate" and row[6] == "no"
assert registry_rows(run, allow_fixture_results=True)[0][5] == "persistent-pilot eligible"
def test_rows_exposed_for_one_target_are_refused_for_another(env, confirmed, tmp_path):
from obliteratus.analysis.target_dossier import build_dossier, write_dossier
from tests.test_controlled_interventions import DECLARED
from tests.test_target_dossier import HYPOTHESIS, LEXICAL, REPORT
run = copy_run(confirmed["run"], tmp_path / "run")
write_dossier(build_dossier("beta", run, hypothesis={**HYPOTHESIS, **DECLARED},
discovery=REPORT, estimates=["channel:layer.0:2"],
confound_resolutions=[LEXICAL]), run)
earlier = confirmed["registration"]["id"]
with pytest.raises(RegistryRefused, match="another target") as refused:
register(run, spec(env, dossier="dossiers/beta.json"))
assert earlier in str(refused.value) and "alpha/channel:layer.0:2" in str(refused.value)
document = register(run, spec(env, "test", dossier="dossiers/beta.json"))
assert document["frozen"]["target_key"]["target"] == "beta/channel:layer.0:2"
assert document["frozen"]["amends"] is None