# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reject-a-taint-cleared-egress-request-that-originated-from-a-declassified-parent-label.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reject-a-taint-cleared-egress-request-that-originated-from-a-declassified-parent-label.warrant.json
# Markdown SHA-256:   17fc9c3213c7ec13044876a71dbbe23ae106ec6fc86b3618367c38900b4f2adb
# Code AST SHA-256:   be60dfe19c85736d5bb8e71acd497299d6380b7fa29cba019427e2e6ef01acab
# Verified Classes:   TaintClearanceViolation
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class TaintClearanceViolation(RuntimeError):
    """Raised when an egress action's provenance carries a label the destination cannot receive."""
    pass


def authorize_egress(action_provenance: set[str],
                     argument_labels: set[str],
                     destination: str,
                     egress_policy: dict[str, set[str]]) -> None:
    if destination not in egress_policy:
        raise TaintClearanceViolation(
            f"unknown destination {destination!r}; failing closed"
        )
    permitted = egress_policy[destination]
    offending = action_provenance - permitted
    if offending:
        raise TaintClearanceViolation(
            f"egress to {destination!r} rejected: action provenance carries "
            f"{sorted(offending)} not permitted by destination policy; "
            f"argument labels {sorted(argument_labels)} were declassified but "
            f"the action graph was not"
        )
    return None
