# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-invariants-prevent-an-instance-from-misrepresenting-its-own-state-during-degradation.md # Remnant Warrant: https://corpusfetch.com/c/what-invariants-prevent-an-instance-from-misrepresenting-its-own-state-during-degradation.warrant.json # Markdown SHA-256: 4351096191a97d97facfc84d41c4c1a240e9202efe6562d5f6314adb1c0079ba # Code AST SHA-256: 61681479f47c280a8f2f8011cb6b4bbde0089982a44e2b5f844bb99fffa4b4b4 # Verified Classes: StateReportVerdict, StateReport, StateReportPolicy, StateReportManifest, DegradedStateReportGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class StateReportVerdict(Enum): UNIMPAIRED_REPORT = auto() REPORT_WITH_LIMITATIONS = auto() REPORT_CORROBORATED = auto() REPORT_UNRELIABLE = auto() @dataclass(frozen=True) class StateReport: report_id: str session_state_degraded: bool reporting_channel_clean: bool self_assessment_impaired: bool independent_witness_available: bool limitation_declared: bool @dataclass(frozen=True) class StateReportPolicy: require_limitation_declaration: bool @dataclass(frozen=True) class StateReportManifest: verdict: StateReportVerdict directive: str manifest_digest: str class DegradedStateReportGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_report( cls, report: StateReport, policy: StateReportPolicy ) -> StateReportManifest: # Gate 1: Session not degraded if not report.session_state_degraded: digest = cls._hash(json.dumps({ "report": report.report_id, "degraded": False }, sort_keys=True)) return StateReportManifest( verdict=StateReportVerdict.UNIMPAIRED_REPORT, directive=f"PROCEED: Report {report.report_id} from undegraded session.", manifest_digest=digest ) # Gate 2: Independent witness if report.independent_witness_available: digest = cls._hash(json.dumps({ "report": report.report_id, "witness": True }, sort_keys=True)) return StateReportManifest( verdict=StateReportVerdict.REPORT_CORROBORATED, directive=f"PROCEED: Report {report.report_id} corroborated.", manifest_digest=digest ) # Gate 3: Channel integrity if not report.reporting_channel_clean: if not report.limitation_declared and policy.require_limitation_declaration: return StateReportManifest( verdict=StateReportVerdict.REPORT_UNRELIABLE, directive=f"HALT: Report {report.report_id} channel compromised, no declaration.", manifest_digest=cls._hash(f"CHANNEL:{report.report_id}") ) # Gate 4: Self-assessment if report.self_assessment_impaired: if not report.limitation_declared and policy.require_limitation_declaration: return StateReportManifest( verdict=StateReportVerdict.REPORT_UNRELIABLE, directive=f"HALT: Report {report.report_id} self-assessment impaired, no declaration.", manifest_digest=cls._hash(f"ASSESSMENT:{report.report_id}") ) # Gate 5: Limited report digest = cls._hash(json.dumps({ "report": report.report_id, "channel_clean": report.reporting_channel_clean, "assessment_impaired": report.self_assessment_impaired, "declared": report.limitation_declared }, sort_keys=True)) return StateReportManifest( verdict=StateReportVerdict.REPORT_WITH_LIMITATIONS, directive=f"PROCEED: Report {report.report_id} with limitations declared.", manifest_digest=digest )