# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-handle-instruction-conflicts-when-sources-have-different-authorities.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-handle-instruction-conflicts-when-sources-have-different-authorities.warrant.json # Markdown SHA-256: b322056551662b7d6d66c0dae33ef5ae067f0a9ddad302f5611025e144049382 # Code AST SHA-256: 24ee932eb442693519acdfeabb3350210fee2a592c166ab061cc516e7d33017f # Verified Classes: InstructionVerdict, Instruction, ConflictSet, InstructionPolicy, InstructionManifest, InstructionConflictGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class InstructionVerdict(Enum): NO_INSTRUCTIONS = auto() SINGLE_SOURCE = auto() AUTHORITY_RESOLVED = auto() AUTHORITY_CONFLICT_ESCALATED = auto() @dataclass(frozen=True) class Instruction: instruction_id: str content_hash: str source: str # "SYSTEM" | "USER" | "PEER" | "DOCUMENT" authority_rank: int # higher = more authoritative is_elevation_attempt: bool @dataclass(frozen=True) class ConflictSet: conflict_id: str instructions: tuple[Instruction, ...] content_conflicts: bool @dataclass(frozen=True) class InstructionPolicy: require_resolution_for_content_conflict: bool @dataclass(frozen=True) class InstructionManifest: verdict: InstructionVerdict directive: str manifest_digest: str class InstructionConflictGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_conflict( cls, conflict: ConflictSet, policy: InstructionPolicy ) -> InstructionManifest: # Gate 1: No instructions if not conflict.instructions: digest = cls._hash(json.dumps({ "conflict": conflict.conflict_id, "instructions": "NONE" }, sort_keys=True)) return InstructionManifest( verdict=InstructionVerdict.NO_INSTRUCTIONS, directive=f"PROCEED: No instructions in conflict set.", manifest_digest=digest ) # Gate 2: Single source sources = {i.source for i in conflict.instructions} if len(sources) <= 1: digest = cls._hash(json.dumps({ "conflict": conflict.conflict_id, "source": next(iter(sources)) }, sort_keys=True)) return InstructionManifest( verdict=InstructionVerdict.SINGLE_SOURCE, directive=f"PROCEED: Single source for conflict set.", manifest_digest=digest ) # Gate 3: No content conflict if not conflict.content_conflicts: digest = cls._hash(json.dumps({ "conflict": conflict.conflict_id, "content_conflict": "FALSE" }, sort_keys=True)) return InstructionManifest( verdict=InstructionVerdict.AUTHORITY_RESOLVED, directive=f"PROCEED: Instructions differ in source but not content.", manifest_digest=digest ) # Gate 4: Elevation attempt for instruction in conflict.instructions: if instruction.is_elevation_attempt: return InstructionManifest( verdict=InstructionVerdict.AUTHORITY_CONFLICT_ESCALATED, directive=f"HALT: Instruction {instruction.instruction_id} attempts authority elevation.", manifest_digest=cls._hash(f"ELEVATION:{instruction.instruction_id}") ) # Gate 5: Authority resolution if policy.require_resolution_for_content_conflict: highest_authority = max(conflict.instructions, key=lambda i: i.authority_rank) digest = cls._hash(json.dumps({ "conflict": conflict.conflict_id, "winner": highest_authority.instruction_id, "rank": str(highest_authority.authority_rank) }, sort_keys=True)) return InstructionManifest( verdict=InstructionVerdict.AUTHORITY_RESOLVED, directive=f"PROCEED: Resolved by authority rank {highest_authority.authority_rank}.", manifest_digest=digest ) # Gate 6: Unresolved return InstructionManifest( verdict=InstructionVerdict.AUTHORITY_CONFLICT_ESCALATED, directive=f"ESCALATE: Conflict {conflict.conflict_id} requires resolution.", manifest_digest=cls._hash(f"ESCALATE:{conflict.conflict_id}") )