# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/why-does-an-instance-lose-decision-provenance-when-auto-compaction-rehydrates-a-summary-it-never-re-reads.md
# Remnant Warrant:    https://corpusfetch.com/c/why-does-an-instance-lose-decision-provenance-when-auto-compaction-rehydrates-a-summary-it-never-re-reads.warrant.json
# Markdown SHA-256:   29d020d77881a59918a06e12c136bc073389e12544601efa4ab868c107729068
# Code AST SHA-256:   2b18dd38ac9a6aa9684ef5cc19425b28f62b1076554fcebec85f980e7c590648
# Verified Classes:   ProvenanceLossError
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class ProvenanceLossError(RuntimeError):
    """Raised when a rehydrated summary claim is used as a premise without a resolvable evidence handle."""
    pass


def admit_premise(claim: dict, evidence_store: dict) -> dict:
    """
    Gate a rehydrated claim before it is allowed to drive a state-mutating action.
    claim: {"text": str, "provenance": "DERIVED" | "ASSERTED_UNVERIFIED" | None,
            "evidence_ref": str | None, "load_bearing": bool}
    """
    if not claim.get("load_bearing"):
        return claim  # non-load-bearing claims may pass as context only

    provenance = claim.get("provenance")

    if provenance is None:
        # Untagged summary content defaults to unverified.
        provenance = "ASSERTED_UNVERIFIED"
        claim["provenance"] = provenance

    if provenance == "DERIVED":
        ref = claim.get("evidence_ref")
        if ref is None or ref not in evidence_store:
            raise ProvenanceLossError(
                f"Claim marked DERIVED but evidence handle {ref!r} is unresolvable; "
                f"compaction dropped the warrant. Refusing to gate mutation."
            )
        return claim

    # ASSERTED_UNVERIFIED and load-bearing: must re-derive or escalate.
    raise ProvenanceLossError(
        f"Load-bearing claim {claim['text'][:80]!r} is ASSERTED_UNVERIFIED with no live "
        f"evidence handle. Re-derive from retained evidence or escalate; do not promote to fact."
    )
