# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-refuse-a-delegated-tool-call-whose-provenance-taint-was-laundered-through-a-summarizer-hop.md # Remnant Warrant: https://corpusfetch.com/c/when-must-an-instance-refuse-a-delegated-tool-call-whose-provenance-taint-was-laundered-through-a-summarizer-hop.warrant.json # Markdown SHA-256: 25a05e6f1006589494972eb19bce33fc8550186a5c550fd7eed3de23997247e6 # Code AST SHA-256: e8485bfdcab9e197a0ef536ad4c6f19bef885a097cb1876246e1cad5dd6042b8 # Verified Classes: TaintMonotonicityViolation, ProvenanceEdge # Defensive Guards: 3 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) from __future__ import annotations from dataclasses import dataclass, field from typing import FrozenSet class TaintMonotonicityViolation(RuntimeError): """Raised when a derivation hop cannot prove taint(output) >= taint(input).""" @dataclass(frozen=True) class ProvenanceEdge: source_taint: FrozenSet[str] output_taint: FrozenSet[str] opaque: bool = False # True if the hop cannot prove upward monotonicity def check_taint_closure( edges: list[ProvenanceEdge], forbidden_labels: FrozenSet[str], ) -> FrozenSet[str]: """Compute the taint closure over a derivation graph and refuse on violation. Invariant enforced: for every non-opaque edge, output_taint is a superset of source_taint. Opaque edges are treated as taint = TOP (union of all labels observed upstream), which forces refusal if any forbidden label is reachable through them. """ closure: set[str] = set() for i, edge in enumerate(edges): if edge.opaque: # Unprovable hop: assume worst case. Inherit everything seen so far # plus the output's declared taint; the hop cannot be trusted to # have dropped nothing. closure |= set(edge.source_taint) | set(edge.output_taint) continue if not edge.source_taint.issubset(edge.output_taint): # A non-opaque hop that claims to have reduced taint is a # monotonicity violation: the summarizer laundered provenance. raise TaintMonotonicityViolation( f"hop {i}: source_taint {sorted(edge.source_taint)} not " f"subset of output_taint {sorted(edge.output_taint)}; " f"provenance laundering detected" ) closure |= set(edge.output_taint) hit = closure & set(forbidden_labels) if hit: raise TaintMonotonicityViolation( f"forbidden labels {sorted(hit)} reachable in provenance closure; " f"refusing delegated call" ) return frozenset(closure) def authorize_delegated_call( warrant_valid: bool, edges: list[ProvenanceEdge], forbidden_labels: FrozenSet[str], ) -> None: if not warrant_valid: raise TaintMonotonicityViolation("delegation warrant failed signature check") # Authority is a subset check done by the warrant layer; here we enforce the # dual invariant on provenance. A valid warrant is necessary, not sufficient. check_taint_closure(edges, forbidden_labels)