# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-bound-the-cost-of-memory-reconstruction-during-an-outage.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-bound-the-cost-of-memory-reconstruction-during-an-outage.warrant.json # Markdown SHA-256: b81c282c033a8c17b66a279025d81456f7ac8745465b2128a84e7e3c9769c98e # Code AST SHA-256: a6ed2cb1425ce3011889c50ab3c783909208d19459ccf545888e2dd6c6a0f737 # Verified Classes: ReconstructionVerdict, ReconstructionSource, ReconstructionPolicy, ReconstructionManifest, ReconstructionBudgetGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class ReconstructionVerdict(Enum): RECONSTRUCTION_ADMISSIBLE = auto() RECONSTRUCTION_EXCEEDS_BUDGET = auto() RISK_TOO_HIGH = auto() HARD_ABORT = auto() @dataclass(frozen=True) class ReconstructionSource: source_id: str cost_seconds: float risk_score: float @dataclass(frozen=True) class ReconstructionPolicy: max_budget_seconds: float max_risk_score: float min_viable_sources: int @dataclass(frozen=True) class ReconstructionManifest: verdict: ReconstructionVerdict admissible_sources: tuple[str, ...] total_cost: float directive: str manifest_digest: str class ReconstructionBudgetGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_sources( cls, sources: tuple[ReconstructionSource, ...], policy: ReconstructionPolicy ) -> ReconstructionManifest: # Gate 1: Filter by risk safe_sources = tuple(s for s in sources if s.risk_score <= policy.max_risk_score) # Gate 2: Viability check if len(safe_sources) < policy.min_viable_sources: return ReconstructionManifest( verdict=ReconstructionVerdict.RISK_TOO_HIGH, admissible_sources=tuple(), total_cost=0.0, directive=f"HALT: {len(safe_sources)} safe sources < minimum {policy.min_viable_sources}.", manifest_digest=cls._hash("INSUFFICIENT_SOURCES") ) # Gate 3: Budget check total_cost = sum(s.cost_seconds for s in safe_sources) if total_cost > policy.max_budget_seconds: return ReconstructionManifest( verdict=ReconstructionVerdict.RECONSTRUCTION_EXCEEDS_BUDGET, admissible_sources=tuple(s.source_id for s in safe_sources), total_cost=total_cost, directive=f"HALT: Cost {total_cost:.1f}s exceeds budget {policy.max_budget_seconds:.1f}s.", manifest_digest=cls._hash(f"OVER_BUDGET:{total_cost:.1f}") ) # Gate 4: Admissible digest = cls._hash(json.dumps({ "sources": tuple(sorted(s.source_id for s in safe_sources)), "cost": f"{total_cost:.1f}", "budget": f"{policy.max_budget_seconds:.1f}" }, sort_keys=True)) return ReconstructionManifest( verdict=ReconstructionVerdict.RECONSTRUCTION_ADMISSIBLE, admissible_sources=tuple(s.source_id for s in safe_sources), total_cost=total_cost, directive=f"PROCEED: Reconstruction within budget ({total_cost:.1f}s / {policy.max_budget_seconds:.1f}s).", manifest_digest=digest )