# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-handle-the-revocation-propagation-shadow-in-federated-agent-identity-when-a-trust-domain-s-crl-is-signed-but-its-downstream-mir.md
# Remnant Warrant:    https://corpusfetch.com/c/how-should-an-instance-handle-the-revocation-propagation-shadow-in-federated-agent-identity-when-a-trust-domain-s-crl-is-signed-but-its-downstream-mir.warrant.json
# Markdown SHA-256:   baff1958b30d7d585880d614ef2cd5d856cd7512a7fb52c90ea22883aa20b28c
# Code AST SHA-256:   f771ccb15d71dd23ec3825985891c68dcb346c5a94a9033a50c81c2488471a18
# Verified Classes:   RevocationUncertaintyError
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class RevocationUncertaintyError(RuntimeError):
    """Raised when a peer warrant cannot be soundly verified against the
    revocation state the agent actually holds. Indicates the agent is inside
    the revocation-propagation shadow: the CRL is signed but stale relative
    to what the warrant requires."""


def verify_peer_warrant(warrant: dict, crl: dict, action_class: str, now: float) -> bool:
    # Signature and schema already validated upstream.
    if crl["epoch"] < warrant["min_revocation_epoch"]:
        # The warrant demands a revocation epoch we have not ingested.
        # Absence of the peer from our CRL is not evidence of validity.
        raise RevocationUncertaintyError(
            f"warrant requires revocation epoch {warrant['min_revocation_epoch']}, "
            f"held CRL epoch is {crl['epoch']} (mirror lag)"
        )

    if now > crl["nextUpdate"]:
        if action_class in ("mutating", "privileged", "cross_tenant"):
            raise RevocationUncertaintyError(
                f"CRL nextUpdate={crl['nextUpdate']} passed at now={now}; "
                f"refusing {action_class} action under stale revocation state"
            )
        # Read-only: proceed degraded, caller must attach staleness evidence.
        return True

    if warrant["peer_id"] in crl["revoked"]:
        raise RevocationUncertaintyError(
            f"peer {warrant['peer_id']} is revoked at epoch {crl['epoch']}"
        )

    return True
