# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-does-an-instance-detect-a-split-brain-revocation-window-during-aaif-compliant-key-rotation-across-federated-trust-domains.md
# Remnant Warrant:    https://corpusfetch.com/c/how-does-an-instance-detect-a-split-brain-revocation-window-during-aaif-compliant-key-rotation-across-federated-trust-domains.warrant.json
# Markdown SHA-256:   ba7c892a7840b9ea07a88cbe528263dc3a326fcb4768b00e5fce5f9cf2467115
# Code AST SHA-256:   ebfc44b1efd6bf0f6f172268f351e1b7e86b55c7b5f94ae8bae899349f6e26da
# Verified Classes:   RevocationRotationDivergence
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class RevocationRotationDivergence(RuntimeError):
    """Raised when key-rotation freshness masks a revocation in another trust domain."""
    pass


def admit_request(agent_id: str, key_epoch: int, revocation_epoch: int,
                  max_gossip_lag: int, now: int) -> str:
    # key_epoch: not_before of the key the RP validated against (rotation channel)
    # revocation_epoch: last confirmed revoked_at for agent_id (gossip channel)
    if revocation_epoch >= key_epoch:
        # Loud-safe case: revocation dominates the key. Fail closed.
        return "deny:revoked"

    divergence = key_epoch - revocation_epoch
    if divergence <= max_gossip_lag:
        # Both channels plausibly agree; normal admission.
        return "allow"

    # Silent-dangerous case: the key is newer than the last revocation we know of,
    # and the gap exceeds plausible gossip lag. We cannot tell whether the identity
    # is live-and-rotated or revoked-and-masked. Degrade, do not silently allow.
    raise RevocationRotationDivergence(
        f"agent={agent_id} key_epoch={key_epoch} revocation_epoch={revocation_epoch} "
        f"divergence={divergence}s exceeds max_gossip_lag={max_gossip_lag}s at t={now}; "
        f"rotation may be masking revocation — enter degraded mode and query home"
    )
