mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-18 20:49:28 +00:00
feat(model-grounded-detection): group 1, subtract the noise architecture
99 source modules -> 81. 832 tests -> 646. The whole learning/ package (16 modules, ~4,100 lines) and six semantic/ modules removed, with the three gates byte-identical to 2026-09-06-gate-baseline.txt at every step. The sequence is what made it safe: vocabularies ported first (1.1), importers detached second (1.2-1.3), deletion third (1.4). Every import break during the deletion was therefore a detachment miss in the importer and was fixed there -- no module was restored to satisfy one. Both misses were the same shape and were fixed as a class: operations.py and shapes.py each imported trailing_name from the deleted variants.py, so it moved to semantic/ir.py, its natural home, and both importers changed in one edit. Ported before deleting: the closed guard vocabulary (verbatim, nothing else holds it) into model/specs.py, which derives TaintSpec and DominanceSpec from the retained ruleset facts rather than copying them. Re-homed: families -> model/taxonomy, candidates -> model/candidates, endpoint -> model/endpoint, plus Region, labeled_family and labeled_spans. labeled_family no longer falls back to the LLM classifier -- an unlabeled pair is honestly unknown. Four deviations, each recorded in the spec notes with its reason. improve/ evolve.py and validator.py were stripped, not deleted: each mixes the mechanism lever (gone) with the deterministic rule-status loop `ousast improve` still runs, which has no LLM in it; a test now asserts the lever's absence by symbol so it cannot creep back. The learning CLI group became `model candidates`, because deleting it outright would have orphaned the retained enumerator by removing its only entry point. thinking moved from [learning] to [models]. A gap named rather than papered over: no retained sink fact routes by CWE to path, output_encoding, untrusted_destination or prototype -- the same hole the entailment ceiling diagnosed. The test asserts the seeded set and the gap set exactly, so task 4.2 must update it when it authors those sinks. The audit found exactly one genuine orphan: vectorstore.py, a bakeoff harness with no production caller and no CLI, alive only through its own test. The five named subsystems each carry an explicit decision. Manifest committed, with a test asserting the tree still matches it. Group 2 (the Joern go/no-go) has not started. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01T7XD7x5KonMdmGRkp63EQG
This commit is contained in:
co-authored by
Claude Opus 5
parent
fc4dab97fb
commit
9ed0e45c5f
@@ -8,11 +8,9 @@ impossible; the validator additionally enforces status/bounds/staging/resolution
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
from collections.abc import Mapping, Sequence
|
||||
from dataclasses import asdict, dataclass
|
||||
from pathlib import Path
|
||||
from collections.abc import Mapping
|
||||
from dataclasses import dataclass
|
||||
|
||||
from ..policy import CwePolicy
|
||||
from ..ruleset import PatternRule
|
||||
@@ -62,40 +60,6 @@ class PolicyConstantEdit:
|
||||
return f"policy:{self.name}:{self.from_value}->{self.to_value}"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class MechanismEdit:
|
||||
"""A `mechanisms`-lever edit (corpus-seeded-mechanisms Req 5): admit or retract one exporter record by id.
|
||||
|
||||
The loop never writes a shape; it may only move a record the exporter derived from a trusted pair into or out of
|
||||
the scan-time store. Free text is confined to ``rationale``.
|
||||
"""
|
||||
|
||||
action: str # admit | retract
|
||||
mechanism_id: str
|
||||
source: str = "loo" # loo | export
|
||||
rationale: str = ""
|
||||
lever: str = "mechanisms"
|
||||
|
||||
def key(self) -> str:
|
||||
return f"mechanisms:{self.action}:{self.mechanism_id}"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class StoreSnapshot:
|
||||
"""Bytes of the scan-time mechanism store before a round; ``restore`` is the byte-for-byte revert."""
|
||||
|
||||
path: Path
|
||||
content: bytes | None # None when the file did not exist
|
||||
|
||||
def restore(self) -> None:
|
||||
if self.content is None:
|
||||
if self.path.exists():
|
||||
self.path.unlink()
|
||||
return
|
||||
self.path.parent.mkdir(parents=True, exist_ok=True)
|
||||
self.path.write_bytes(self.content)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class EvolveBounds:
|
||||
k_range: tuple[float, float] = (20.0, 200.0)
|
||||
@@ -113,49 +77,9 @@ class EvolveValidator:
|
||||
self._validate_rule(edit, ruleset_by_id, policy)
|
||||
elif isinstance(edit, PolicyConstantEdit):
|
||||
self._validate_policy(edit)
|
||||
elif isinstance(edit, MechanismEdit):
|
||||
raise StrictValidationError("mechanism edits need the exporter candidate set: use validate_mechanism", kind="mechanism_change")
|
||||
else:
|
||||
raise StrictValidationError(f"unknown edit type {type(edit).__name__}", kind="rule_change")
|
||||
|
||||
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"
|
||||
)
|
||||
if getattr(record, "origin", "") != "corpus":
|
||||
raise StrictValidationError(
|
||||
f"{edit.mechanism_id}: origin {getattr(record, 'origin', '')!r} is not corpus (only exporter records)",
|
||||
kind="mechanism_change",
|
||||
)
|
||||
shape = getattr(record, "shape", None)
|
||||
if not isinstance(shape, dict):
|
||||
raise StrictValidationError(f"{edit.mechanism_id}: record carries no shape", kind="mechanism_change")
|
||||
if str(shape.get("guard")) not in GUARD_KINDS or str(getattr(record, "guard", "")) not in GUARD_KINDS:
|
||||
raise StrictValidationError(
|
||||
f"{edit.mechanism_id}: guard {shape.get('guard')!r} is not a closed guard kind", kind="mechanism_change"
|
||||
)
|
||||
for field_name in ("sink_name", "language", "mechanism"):
|
||||
value = str(shape.get(field_name, ""))
|
||||
if not _IDENTIFIER.match(value.replace("-", "_")):
|
||||
raise StrictValidationError(f"{edit.mechanism_id}: {field_name} {value!r} is not an identifier", kind="mechanism_change")
|
||||
kinds = shape.get("source_kinds") or []
|
||||
if not isinstance(kinds, list) or any(str(kind) not in SOURCE_KINDS for kind in kinds):
|
||||
raise StrictValidationError(f"{edit.mechanism_id}: source kinds {kinds!r} are not closed kinds", kind="mechanism_change")
|
||||
|
||||
def _validate_rule(self, edit: RuleStatusEdit, ruleset_by_id: Mapping[str, PatternRule], policy: Mapping[str, CwePolicy]) -> None:
|
||||
if edit.to_status not in VALID_STATUS:
|
||||
raise StrictValidationError(f"invalid status {edit.to_status!r} for {edit.rule_id}")
|
||||
@@ -178,25 +102,6 @@ class EvolveValidator:
|
||||
raise StrictValidationError(f"MIN_SCORE={edit.to_value} out of bounds {self._bounds.min_score_range}", kind="policy_change")
|
||||
|
||||
|
||||
def apply_mechanism_edits(edits: Sequence[MechanismEdit], candidates: object, scan_store: Path) -> StoreSnapshot:
|
||||
"""Apply admit/retract edits to the scan-time store; returns the snapshot whose ``restore`` reverts byte for byte.
|
||||
|
||||
Admission appends the exporter record unchanged; retraction appends a tombstone row (``retracted = true``) so the
|
||||
log stays append-only and ``MechanismStore.load`` folds the record away.
|
||||
"""
|
||||
snapshot = StoreSnapshot(path=scan_store, content=scan_store.read_bytes() if scan_store.exists() else None)
|
||||
by_id = {record.id: record for record in candidates.load()} # type: ignore[attr-defined]
|
||||
scan_store.parent.mkdir(parents=True, exist_ok=True)
|
||||
with scan_store.open("a") as handle:
|
||||
for edit in edits:
|
||||
record = by_id[edit.mechanism_id]
|
||||
payload = asdict(record)
|
||||
if edit.action == "retract":
|
||||
payload["retracted"] = True
|
||||
handle.write(json.dumps(payload, sort_keys=True) + "\n")
|
||||
return snapshot
|
||||
|
||||
|
||||
def edits_to_ledger(edits: list[RuleStatusEdit], base: Mapping[str, dict[str, object]]) -> dict[str, dict[str, object]]:
|
||||
"""Overlay rule-status edits onto a copy of the base ledger."""
|
||||
ledger: dict[str, dict[str, object]] = {key: dict(value) for key, value in base.items()}
|
||||
@@ -211,9 +116,6 @@ __all__ = [
|
||||
"EvolveBounds",
|
||||
"EvolveValidator",
|
||||
"MECHANISM_ACTIONS",
|
||||
"MechanismEdit",
|
||||
"StoreSnapshot",
|
||||
"apply_mechanism_edits",
|
||||
"PolicyConstantEdit",
|
||||
"RuleStatusEdit",
|
||||
"StrictValidationError",
|
||||
|
||||
Reference in New Issue
Block a user