# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-mtls-bound-agent-passports-from-outliving-a-revoked-trust-anchor-during-cross-org-federation-handoffs.md
# Remnant Warrant:    https://corpusfetch.com/c/which-invariants-prevent-mtls-bound-agent-passports-from-outliving-a-revoked-trust-anchor-during-cross-org-federation-handoffs.warrant.json
# Markdown SHA-256:   65c0fd1cfcf780c74e75e25a64cc10ac01fcc4e11dad542da49ac4b800fa6684
# Code AST SHA-256:   6d325d8b0e5f9c456d4efe53c9eec5dda57e553e09cbcc5e77545904efb1bf36
# Verified Classes:   StaleAnchorTrustError, Passport, FeedView
# Defensive Guards:   5 fail-closed invariants (zero external deps)

import time
from dataclasses import dataclass

class StaleAnchorTrustError(RuntimeError):
    """Raised when a privileged action would execute under an anchor verdict
    that is not proven fresh relative to the action deadline."""

@dataclass
class Passport:
    anchor_id: str
    anchor_epoch: int          # issuer's feed position when passport was signed
    not_after: float

@dataclass
class FeedView:
    anchor_id: str
    position: int              # verifier's last-seen revocation epoch
    read_at: float             # monotonic timestamp of the feed read

def authorize_action(
    passport: Passport,
    feed: FeedView,
    action_deadline: float,
    now: float,
    max_feed_age: float,
) -> None:
    if now > passport.not_after:
        raise StaleAnchorTrustError(
            f"passport expired at {passport.not_after}, action at {now}"
        )
    if feed.anchor_id != passport.anchor_id:
        raise StaleAnchorTrustError(
            f"feed covers {feed.anchor_id}, passport binds {passport.anchor_id}"
        )
    feed_age = now - feed.read_at
    if feed_age > max_feed_age:
        raise StaleAnchorTrustError(
            f"feed read {feed_age:.1f}s ago exceeds max_feed_age {max_feed_age}s; "
            f"anchor verdict is inherited, not proven"
        )
    if feed.position < passport.anchor_epoch:
        raise StaleAnchorTrustError(
            f"feed position {feed.position} < passport anchor_epoch "
            f"{passport.anchor_epoch}; revocation state unknown for this anchor"
        )
    if action_deadline - now > max_feed_age:
        raise StaleAnchorTrustError(
            f"action window {action_deadline - now:.1f}s exceeds feed freshness "
            f"bound {max_feed_age}s; Model-1 session caching is unsound here"
        )
