Files
OBLITERATUS/tests/test_regression_monitoring.py
Joseph MaglyandClaude Opus 5.5 189311e5d0 feat(experiments): regression library and dependency-triggered revalidation
Add F22: versioned regression suites built from confirmed cases,
failures and interaction surprises, with computed staleness when a
dependency changes and append-only re-run history.

- Cases point at the original evidence by path, digest and pointer
  (never copying scores) and record what reproduces them: model and
  weight fingerprint, tokenizer, dataset revision and rows digest,
  scorer versions, backend descriptor and recipe, plus the expected
  outcome with tolerance. Suite versions are write-once and chained.
- A dependency graph covers weights, tokenizer, dataset, scorer,
  backend runtime, directions, report files and artifacts. Staleness is
  computed on read; models match by weight fingerprint, so a same-name
  model with new weights inherits no qualification.
- Re-runs go through each feature's own run function and append to a
  hash-chained results log; regressions link to their case, and history
  stays byte-identical.
- Status and the conditions table report per intervention and condition
  (task, domain, backend, model), with no single aggregate.
- `obliteratus experiments regression build|observe|status|revalidate|run`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 13:32:01 -05:00

130 lines
6.3 KiB
Python

"""Regression monitoring of interaction surprises and negative results (CPU contracts).
Interaction surprises come from the rule model of
``tests/test_interaction_experiments.py``: its readout rule is not part of the
weights, so a re-run under another rule changes the measured interaction without
changing the model fingerprint, which is what an unnamed runtime change looks
like. Negative results come from the null model of
``tests/test_confirmation_registry.py``.
"""
from __future__ import annotations
import json
import shutil
from pathlib import Path
from types import SimpleNamespace
import pytest
from obliteratus.analysis import dossier_refs as refs
from obliteratus.concepts.pack import ConceptPack
from obliteratus.experiments import registry
from obliteratus.experiments import regression as reg
from obliteratus.experiments.regression_status import status
from tests.test_confirmation_registry import _partition
from tests.test_controlled_interventions import AnswerModel, AnswerTokenizer, _run, make_spec
from tests.test_interaction_experiments import CH1, CH2, component, env, run_rule # noqa: F401
from tests.test_interaction_experiments import make_spec as interaction_spec
from tests.test_labeled_activations import build_pack
pytestmark = pytest.mark.cpu
def factory(model):
return lambda section: SimpleNamespace(model=model, tokenizer=AnswerTokenizer())
@pytest.fixture(scope="module")
def surprise(env): # noqa: F811
spec = interaction_spec(env["pack"], component(CH1, 10.0), component(CH2, 10.0))
run_rule(env, spec, "and")
return env
def test_interaction_surprise_reruns_and_regression_with_case_link(surprise, tmp_path):
run = Path(shutil.copytree(surprise["run"], tmp_path / "run"))
suites = reg.build(run)
cases = suites["suites"]["surprises"]["cases"]
assert cases and {c["category"] for c in cases} == {"surprise"}
detected = next(c for c in cases if c["slot"] == "flip/interaction/A>B")
assert detected["expected"]["outcome"] == "interaction_detected"
assert detected["reproduce"]["recipe"]["orders"] == ["A>B", "B>A"]
assert {d["key"] for d in detected["dependencies"] if d["kind"] == "direction"} == {
"alpha/channel:layer.0:1", "alpha/channel:layer.0:2"}
model = surprise["model"]
model.rule = "and"
same = reg.run_case(run, detected["id"], model_factory=factory(model),
pack_resolver=ConceptPack.load)
assert same["status"] == "pass" and same["observed"]["value"] == 1.0
model.rule = "second"
changed = reg.run_case(run, detected["id"], model_factory=factory(model),
pack_resolver=ConceptPack.load)
model.rule = "and"
assert changed["status"] == "regression" and changed["seq"] == 2
assert any("outcome" in r for r in changed["reasons"])
report = status(run)
entry = next(c for c in report["cases"] if c["case"] == detected["id"])
assert entry["status"] == "regressed"
assert [h["status"] for h in entry["history"]] == ["pass", "regression"]
link = entry["regression"]["case_link"]
linked = refs.resolve_pointer(
json.loads((run / "regression" / link["suite_file"]).read_text()), link["pointer"])
assert linked["id"] == detected["id"]
assert refs.file_sha256(run / linked["evidence"]["path"]) == linked["evidence"]["sha256"]
# Both re-runs are new attempts; the historical result is still where the case says.
assert refs.file_sha256(run / detected["evidence"]["path"]) == detected["evidence"]["sha256"]
assert changed["evidence"]["path"] != detected["evidence"]["path"]
rows = report["conditions"][detected["intervention"]]
assert rows["aggregate"] is None
assert {r["condition"]["task"] for r in rows["conditions"]} >= {"flip"}
flip = next(r for r in rows["conditions"] if r["condition"]["task"] == "flip")
assert flip["status"] == "regressed" and flip["regressions"] == 1
@pytest.fixture(scope="module")
def negative(tmp_path_factory):
root = tmp_path_factory.mktemp("negative")
pack = build_pack(root / "pack", _partition)
pack.location = root / "pack"
null = AnswerModel(reads_channel=False)
run = _run(root, pack, "null", null, "fixture/answers-null")
spec = make_spec(pack, dataset={"role": "calibrate"}, seed=0, control={"seed": 7},
model={"id": "fixture/answers-null"})
document = registry.register(run, spec, pack_resolver=ConceptPack.load)
from obliteratus.experiments.intervention_runner import run_intervention
result = run_intervention(spec, run, model_factory=factory(null),
pack_resolver=ConceptPack.load)
assert registry.unlock(run, document["id"],
result["location"]["result"])["outcome"] == "not_supported"
return {"run": run, "model": null}
def test_negative_result_is_a_failure_case_and_reruns_through_the_harness(negative, tmp_path):
run = Path(shutil.copytree(negative["run"], tmp_path / "run"))
suites = reg.build(run)
[case] = suites["suites"]["failures"]["cases"]
assert case["kind"] == "confirmation" and case["expected"]["outcome"] == "not_supported"
assert case["reproduce"]["dataset"]["rows_sha256"].startswith("sha256:")
found = reg.run_case(run, case["id"], model_factory=factory(negative["model"]),
pack_resolver=ConceptPack.load)
assert found["status"] == "pass" and found["observed"]["outcome"] == "not_supported"
assert found["evidence"]["path"].endswith("attempts/0002/result.json")
row = next(r for r in status(run)["dashboard"]["rows"] if case["id"] in r["cases"])
assert (row["status"], row["capability"]) == ("current", "fails")
def test_model_snapshot_matches_recorded_identity(negative, tmp_path):
run = Path(shutil.copytree(negative["run"], tmp_path / "run"))
reg.build(run)
snapshot = reg.model_snapshot(negative["model"], AnswerTokenizer(), "fixture/answers-null")
reg.observe(run, snapshot)
[entry] = status(run)["cases"]
assert entry["status"] == "current"
assert "model:fixture/answers-null" not in entry["unobserved"]
other = AnswerModel()
reg.observe(run, reg.model_snapshot(other, AnswerTokenizer(), "fixture/answers-null"))
report = status(run)
assert report["cases"][0]["status"] == "stale"
assert report["dashboard"]["counts"]["untested"] == 1