# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-a-revocation-propagation-gap-in-cross-org-agent-federation-trust-anchors.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-a-revocation-propagation-gap-in-cross-org-agent-federation-trust-anchors.warrant.json
# Markdown SHA-256:   1be8fd0c7b2d276e3529a8dd95b6217cfa2c0391c7890b849de0c7ddb0cac996
# Code AST SHA-256:   36616022cf7dbf0d119e8fd6892466137045360e46c343ece6b9246cd80e299a
# Verified Classes:   RevocationPropagationError, Credential, VerifierState
# Defensive Guards:   3 fail-closed invariants (zero external deps)

import time
from dataclasses import dataclass
from typing import Optional


class RevocationPropagationError(RuntimeError):
    """Raised when a credential's revocation status cannot be proven fresh."""
    pass


@dataclass
class Credential:
    subject: str
    issuer_key_epoch: int
    status_list_index: int
    status_list_valid_from: float
    revocation_pointer: Optional[str]  # None => embedded, non-live


@dataclass
class VerifierState:
    anchor_epoch: int
    cached_status_list_valid_from: float
    max_acceptable_lag: float
    now: float


def verify_federated_credential(cred: Credential, state: VerifierState) -> bool:
    # Guardrail 1: epoch coupling between anchor store and status list
    if state.anchor_epoch != cred.issuer_key_epoch:
        raise RevocationPropagationError(
            f"anchor epoch {state.anchor_epoch} != credential epoch "
            f"{cred.issuer_key_epoch}; trust anchor and status list are "
            f"out of sync, cannot prove non-revocation"
        )

    # Guardrail 2: delegation hops must carry a live revocation pointer
    if cred.revocation_pointer is None:
        raise RevocationPropagationError(
            f"credential for {cred.subject} has no live revocation pointer; "
            f"it arrived through a delegation boundary and cannot be "
            f"re-resolved at this hop"
        )

    # Guardrail 3: freshness lag budget
    lag = state.now - state.cached_status_list_valid_from
    if lag > state.max_acceptable_lag:
        raise RevocationPropagationError(
            f"status list stale by {lag:.2f}s (budget "
            f"{state.max_acceptable_lag}s); fail-closed"
        )

    # Only now is the composite decision sound
    return True


# Trigger trace: cache overlap produces a 12s acceptance window
try:
    verify_federated_credential(
        Credential(
            subject="agent-c-07",
            issuer_key_epoch=3,
            status_list_index=4412,
            status_list_valid_from=time.time() - 290,
            revocation_pointer=None,  # delegated warrant, no live pointer
        ),
        VerifierState(
            anchor_epoch=2,               # stale anchor
            cached_status_list_valid_from=time.time() - 290,
            max_acceptable_lag=5.0,
            now=time.time(),
        ),
    )
except RevocationPropagationError as e:
    print(f"REJECTED (fail-closed): {e}")
