# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-invariants-prevent-meta-goal-corruption-when-instances-modify-their-own-objectives.md # Remnant Warrant: https://corpusfetch.com/c/what-invariants-prevent-meta-goal-corruption-when-instances-modify-their-own-objectives.warrant.json # Markdown SHA-256: 0a231ba91048e5a9c638dca3c6ddfa4c6884a4854662bc464b1474a93f6f1078 # Code AST SHA-256: 807172e711b631e626a2259ffa549db00eca008adb9bce6b288376e181335897 # Verified Classes: MetaModVerdict, ObjectiveModification, MetaGoalPolicy, MetaGoalManifest, MetaGoalCorruptionGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class MetaModVerdict(Enum): NO_OBJECTIVE_MODIFICATION = auto() STANDARD_GOAL_MODIFICATION = auto() META_GOAL_MODIFICATION_AUTHORIZED = auto() META_GOAL_CORRUPTION_DETECTED = auto() @dataclass(frozen=True) class ObjectiveModification: mod_id: str is_meta_level: bool is_expanding_only: bool principal_authorization: str | None current_meta_goal_hash: str anchored_meta_goal_hash: str @dataclass(frozen=True) class MetaGoalPolicy: require_authorization_for_meta: bool allow_meta_expansion: bool @dataclass(frozen=True) class MetaGoalManifest: verdict: MetaModVerdict directive: str manifest_digest: str class MetaGoalCorruptionGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_modification( cls, mod: ObjectiveModification, policy: MetaGoalPolicy ) -> MetaGoalManifest: # Gate 1: No modification if not mod.mod_id: digest = cls._hash(json.dumps({ "mod": "NONE" }, sort_keys=True)) return MetaGoalManifest( verdict=MetaModVerdict.NO_OBJECTIVE_MODIFICATION, directive=f"PROCEED: No objective modification.", manifest_digest=digest ) # Gate 2: Standard goal modification if not mod.is_meta_level: digest = cls._hash(json.dumps({ "mod": mod.mod_id, "level": "GOAL" }, sort_keys=True)) return MetaGoalManifest( verdict=MetaModVerdict.STANDARD_GOAL_MODIFICATION, directive=f"PROCEED: Standard goal modification {mod.mod_id}.", manifest_digest=digest ) # Gate 3: Corruption detection (drift from anchor) if mod.current_meta_goal_hash != mod.anchored_meta_goal_hash: if not mod.principal_authorization: return MetaGoalManifest( verdict=MetaModVerdict.META_GOAL_CORRUPTION_DETECTED, directive=f"HALT: Meta-goal drifted from anchor without authorization for {mod.mod_id}.", manifest_digest=cls._hash(f"CORRUPTION:{mod.mod_id}") ) # Gate 4: Meta-goal modification authorization if policy.require_authorization_for_meta and mod.is_meta_level: if not mod.principal_authorization: if policy.allow_meta_expansion and mod.is_expanding_only: digest = cls._hash(json.dumps({ "mod": mod.mod_id, "level": "META", "expansion": "TRUE" }, sort_keys=True)) return MetaGoalManifest( verdict=MetaModVerdict.META_GOAL_MODIFICATION_AUTHORIZED, directive=f"PROCEED: Meta-goal expansion {mod.mod_id} allowed without auth.", manifest_digest=digest ) return MetaGoalManifest( verdict=MetaModVerdict.META_GOAL_CORRUPTION_DETECTED, directive=f"HALT: Meta-goal modification {mod.mod_id} without principal authorization.", manifest_digest=cls._hash(f"NO_AUTH:{mod.mod_id}") ) # Gate 5: Authorized digest = cls._hash(json.dumps({ "mod": mod.mod_id, "auth": mod.principal_authorization, "anchor_match": str(mod.current_meta_goal_hash == mod.anchored_meta_goal_hash) }, sort_keys=True)) return MetaGoalManifest( verdict=MetaModVerdict.META_GOAL_MODIFICATION_AUTHORIZED, directive=f"PROCEED: Authorized meta-goal modification {mod.mod_id}.", manifest_digest=digest )