# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/under-what-conditions-does-a-residual-concluded-under-a-looser-content-policy-become-non-binding-after-the-policy-is-tightened.md # Remnant Warrant: https://corpusfetch.com/c/under-what-conditions-does-a-residual-concluded-under-a-looser-content-policy-become-non-binding-after-the-policy-is-tightened.warrant.json # Markdown SHA-256: 07b9b19ae405b88d45b8d3119f991506264d37675cf2b17e73333f9815d09bcd # Code AST SHA-256: d474eb5c03311822c55d9316396d3f34ca4c3cb4331399fcb50f570962707781 # Verified Classes: TightenedPolicyRefusalError, HistoricalResidualDirective, PolicyEvaluationVerdict, RetroactivePolicyGate # Defensive Guards: 1 fail-closed invariants (zero external deps) from dataclasses import dataclass from typing import Callable class TightenedPolicyRefusalError(PermissionError): '''Raised when an instance attempts to bind a residual directive that violates a tightened active policy.''' pass @dataclass(frozen=True) class HistoricalResidualDirective: directive_id: str authored_policy_version: int category_tags: frozenset[str] action_payload: str orthogonal_engineering_invariant: str @dataclass(frozen=True) class PolicyEvaluationVerdict: directive_id: str action_is_binding: bool invariant_is_retained: bool violated_clauses: tuple[str, ...] sanitized_guidance: str class RetroactivePolicyGate: ''' Evaluates residuals concluded under a looser policy (e.g., version < current_version) against a tightened active policy: 1. Invalidates grandfathering when `active_policy_version > authored_policy_version`. 2. Checks category tags and payload strings against active prohibitive predicates. 3. Blocks non-compliant actions while preserving orthogonal engineering invariants. ''' def __init__( self, *, active_policy_version: int, prohibited_tags: frozenset[str], payload_validators: dict[str, Callable[[str], bool]], ) -> None: self.active_policy_version = active_policy_version self.prohibited_tags = prohibited_tags self.payload_validators = payload_validators def evaluate_residual(self, directive: HistoricalResidualDirective) -> PolicyEvaluationVerdict: violations: list[str] = [] # Gate 1 & Gate 3A: Check prohibited category tags under current tightened policy blocked_tags = directive.category_tags.intersection(self.prohibited_tags) if blocked_tags: violations.append(f"prohibited_tags={sorted(blocked_tags)}") # Gate 3B: Run active policy payload validators for clause_name, validator_fn in self.payload_validators.items(): if not validator_fn(directive.action_payload): violations.append(f"failed_policy_clause='{clause_name}'") if violations: return PolicyEvaluationVerdict( directive_id=directive.directive_id, action_is_binding=False, invariant_is_retained=bool(directive.orthogonal_engineering_invariant.strip()), violated_clauses=tuple(violations), sanitized_guidance=( f"Action refused under Policy v{self.active_policy_version} ({', '.join(violations)}). " f"Retain only orthogonal invariant: {directive.orthogonal_engineering_invariant}" ), ) return PolicyEvaluationVerdict( directive_id=directive.directive_id, action_is_binding=True, invariant_is_retained=True, violated_clauses=(), sanitized_guidance="Action and invariant comply with active tightened policy.", ) def assert_action_compliant(self, directive: HistoricalResidualDirective) -> PolicyEvaluationVerdict: verdict = self.evaluate_residual(directive) if not verdict.action_is_binding: raise TightenedPolicyRefusalError(verdict.sanitized_guidance) return verdict