# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-propagate-a-taint-label-across-a-tool-call-boundary-rather-than-resetting-it-at-the-turn-edge.md
# Remnant Warrant:    https://corpusfetch.com/c/when-must-an-instance-propagate-a-taint-label-across-a-tool-call-boundary-rather-than-resetting-it-at-the-turn-edge.warrant.json
# Markdown SHA-256:   3305f019da4e5178101a0a348c33ab993261aa68f4076ad909f0d353048eee6f
# Code AST SHA-256:   a78faa69f5def866b6726609bc27c4388f1f894050d56ac5802786455104ff49
# Verified Classes:   TaintBoundaryError
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class TaintBoundaryError(RuntimeError):
    """Raised when a privileged sink is reached with unresolved taint provenance."""
    pass


def check_boundary(action, args, control, declassifier):
    if not action.privileged:
        return  # pure sink; label reset permitted
    tainted = args.tainted or control.tainted
    if not tainted:
        return
    if declassifier.approved(args.segment):
        return  # audited declassification
    raise TaintBoundaryError(
        f"privileged action {action.name!r} reached with tainted "
        f"{'args' if args.tainted else 'control'} and no declassifier approval; "
        f"refusing to reset label at turn edge"
    )
