feat(corpus-seeded-mechanisms): the mechanisms lever runs from ousast improve

Review rounds 3-5 remediations (Req 5, 7).

- ousast improve resolves candidates from the target's calibration dir,
  then the working directory's (where `mechanisms export` writes), and
  admits into <target>/.openultrasast/calibration/mechanisms.jsonl,
  where a scan of that target reads; --mechanism-candidates,
  --mechanism-store, --no-mechanisms; --dry-run redirects the store to
  scratch; accepted rounds print admit/retract <id>.
- run_improvement threads the store paths; RoundOutcome carries the
  mechanism edits; reverted mechanism keys are blocked outright; a
  no-gain admission is rejected as mechanism_no_gain; a retraction may
  name an admitted record that left the candidate set.
- leave-one-out forwards variant-search degradations and pins the
  containment and label rules; mechanisms export defaults to the
  candidates file so it never re-admits a tombstone.
- design §Lever rewritten to the implemented gate; README and docs show
  export -> improve -> scan.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01T7XD7x5KonMdmGRkp63EQG
This commit is contained in:
Marius Ciepluch
2026-09-05 15:35:08 +02:00
co-authored by Claude Fable 5.1
parent 624024e72a
commit b3b47ad757
11 changed files with 338 additions and 15 deletions
+10 -2
View File
@@ -292,10 +292,13 @@ def run_round(
try:
for edit in edits:
validator.validate(edit, ruleset_by_id, policy)
if mechanism_edits and candidates_store is not None:
if mechanism_edits and candidates_store is not None and mechanism_store is not None:
from ..semantic.mechanisms import MechanismStore
by_id = {record.id: record for record in candidates_store.load()}
admitted_by_id = {record.id: record for record in MechanismStore(mechanism_store).load()}
for mechanism_edit in mechanism_edits:
validator.validate_mechanism(mechanism_edit, by_id)
validator.validate_mechanism(mechanism_edit, by_id, admitted=admitted_by_id)
except StrictValidationError as exc:
_record(journal_path, round_index, edits, "rejected", before, before, str(exc), mechanism_edits=mechanism_edits)
return _outcome(
@@ -416,6 +419,8 @@ def run_improvement(
pair_cases: Sequence[object] | None = None,
profile_tolerance: float = 0.0,
min_holdout_pairs: int = 5,
mechanism_candidates: Path | None = None,
mechanism_store: Path | None = None,
) -> list[RoundOutcome]:
"""Run improvement rounds until convergence (no new proposals) or ``max_rounds``."""
outcomes: list[RoundOutcome] = []
@@ -432,6 +437,8 @@ def run_improvement(
pair_cases=pair_cases,
profile_tolerance=profile_tolerance,
min_holdout_pairs=min_holdout_pairs,
mechanism_candidates=mechanism_candidates,
mechanism_store=mechanism_store,
)
outcomes.append(outcome)
if outcome.reason == "no_proposals":
@@ -507,6 +514,7 @@ def _outcome(
accepted=accepted,
reason=reason,
edits=edits,
mechanism_edits=list(mechanism_edits or []),
recall_before=before.recall,
recall_after=after.recall,
fp_before=before.fp_rate,
+3 -1
View File
@@ -31,7 +31,9 @@ def reverted_edit_keys(rounds: list[dict[str, object]]) -> set[str]:
continue
for edit in _edits(entry):
key = edit.get("key")
if isinstance(key, str) and not edit.get("rationale"):
# Rule edits are blocked only without a new rationale; mechanism edits are blocked outright (the loop
# always writes a rationale for them, and a reverted store edit must not be re-proposed every round).
if isinstance(key, str) and (not edit.get("rationale") or edit.get("lever") == "mechanisms"):
keys.add(key)
return keys
+9 -2
View File
@@ -118,13 +118,20 @@ class EvolveValidator:
else:
raise StrictValidationError(f"unknown edit type {type(edit).__name__}", kind="rule_change")
def validate_mechanism(self, edit: MechanismEdit, candidates: Mapping[str, object]) -> None:
"""Req 5.2: only records the exporter derived from trusted pairs, with a closed guard and identifier-only shape text."""
def validate_mechanism(
self, edit: MechanismEdit, candidates: Mapping[str, object], admitted: Mapping[str, object] | None = None
) -> None:
"""Req 5.2: only records the exporter derived from trusted pairs, with a closed guard and identifier-only shape text.
A retraction may also name a record that is admitted in the scan store but no longer in the candidate set.
"""
from ..semantic.variants import GUARD_KINDS, SOURCE_KINDS
if edit.action not in MECHANISM_ACTIONS:
raise StrictValidationError(f"mechanism edit action {edit.action!r} is not admit or retract", kind="mechanism_change")
record = candidates.get(edit.mechanism_id)
if record is None and edit.action == "retract" and admitted is not None:
record = admitted.get(edit.mechanism_id)
if record is None:
raise StrictValidationError(
f"unknown mechanism {edit.mechanism_id!r}: not in the exporter candidate set", kind="mechanism_change"