# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-reject-a-delegated-warrant-whose-policy-closure-is-satisfiable-only-under-the-issuer-s-capability-set-not-the-d.md
# Remnant Warrant:    https://corpusfetch.com/c/under-what-conditions-must-an-instance-reject-a-delegated-warrant-whose-policy-closure-is-satisfiable-only-under-the-issuer-s-capability-set-not-the-d.warrant.json
# Markdown SHA-256:   1024c5efc5b32ae8f14aaa1fe20379ac64d4c6f570a300e98074137a05308561
# Code AST SHA-256:   1085e29606420dd89a1d9992bd95310043262a7a681e3005800431bd42e117be
# Verified Classes:   WarrantClosureUnsatisfiable
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class WarrantClosureUnsatisfiable(RuntimeError):
    """Raised when a delegated warrant's policy closure is satisfiable under the
    issuer's engine but unsatisfiable under the delegate's engine, even though
    every positive predicate is individually granted by the delegate."""
    def __init__(self, warrant_id: str, conflicting_constraint: str,
                 predicate_pair: tuple[str, str]):
        self.warrant_id = warrant_id
        self.conflicting_constraint = conflicting_constraint
        self.predicate_pair = predicate_pair
        super().__init__(
            f"warrant {warrant_id}: closure unsatisfiable under delegate engine; "
            f"constraint {conflicting_constraint!r} forbids simultaneous "
            f"{predicate_pair[0]!r} + {predicate_pair[1]!r}"
        )


def admit_warrant(warrant, delegate_registry, delegate_engine) -> None:
    # Per-clause check: necessary, not sufficient.
    for pred in warrant.positive_predicates:
        if not delegate_registry.grants(pred):
            raise WarrantClosureUnsatisfiable(
                warrant.id, "capability_absent", (pred, pred)
            )
    # Closure check: the part that per-clause negotiation misses.
    # Evaluate the conjunction under the delegate's engine, including
    # constraints the issuer did not carry and scope reclassifications.
    closure = delegate_engine.evaluate(
        predicates=warrant.positive_predicates,
        constraints=warrant.constraint_set,
    )
    if not closure.satisfiable:
        raise WarrantClosureUnsatisfiable(
            warrant.id,
            closure.violated_constraint,
            closure.conflicting_predicates,
        )
    # Only now may the delegate acquire capabilities or emit side effects.
    delegate_registry.acquire(warrant.positive_predicates)
