# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-a-delegated-aaif-credential-has-outlived-its-revocation-epoch-during-an-in-flight-agent-handoff.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-a-delegated-aaif-credential-has-outlived-its-revocation-epoch-during-an-in-flight-agent-handoff.warrant.json
# Markdown SHA-256:   adad2c0e0f93fc9e6a3e73f8f18e84da85b109ff79d9a378c7fefdd8665366a0
# Code AST SHA-256:   e5caa769792a54021b011b5b5b40318c8c281be742f8462c391c44cd76e3e4f2
# Verified Classes:   RevocationEpochSkewError
# Defensive Guards:   4 fail-closed invariants (zero external deps)

class RevocationEpochSkewError(RuntimeError):
    """Raised when a delegated AAIF chain is structurally valid but the
    observed status-list epoch cannot rule out an ancestor revocation."""
    pass


def verify_delegated_chain(
    chain,
    observed_epoch_time: float,
    publish_interval: float,
    max_propagation_latency: float,
) -> bool:
    depth = len(chain.hops)
    if depth > chain.declared_max_depth:
        raise RevocationEpochSkewError(
            f"chain depth {depth} exceeds declared max_depth "
            f"{chain.declared_max_depth}; revocation horizon unbounded"
        )
    deepest_iat = max(hop.iat for hop in chain.hops)
    required_epoch = deepest_iat + depth * max_propagation_latency
    if observed_epoch_time < required_epoch:
        raise RevocationEpochSkewError(
            f"status epoch {observed_epoch_time:.3f} predates required "
            f"{required_epoch:.3f} for depth-{depth} chain "
            f"(deepest_iat={deepest_iat:.3f}, "
            f"publish_interval={publish_interval:.3f}); "
            f"ancestor revocation at epoch+1 cannot be excluded"
        )
    for hop in chain.hops:
        if not hop.signature_valid():
            raise RevocationEpochSkewError(f"signature invalid at hop {hop.index}")
        if not hop.scope_subset_of_parent():
            raise RevocationEpochSkewError(f"scope attenuation violated at hop {hop.index}")
    return True
