# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-reconstruct-causality-when-only-outcomes-are-visible.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-reconstruct-causality-when-only-outcomes-are-visible.warrant.json # Markdown SHA-256: e060fe820be7df40945f1f1cf8fcd63815e8423a70698f986ae40866c9ffe5dc # Code AST SHA-256: 29d6cd8ad35ba320062f3a7251ce5a624ee56bee403b5bb876e466a5c1c94a1b # Verified Classes: CausalVerdict, CausalHypothesis, OutcomeContext, ReconstructionPolicy, ReconstructionManifest, CausalReconstructionGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class CausalVerdict(Enum): DIRECT_CAUSAL_EVIDENCE = auto() HYPOTHESES_TRACKED = auto() PREMATURE_COMMITMENT = auto() DISCRIMINATION_READY = auto() @dataclass(frozen=True) class CausalHypothesis: hypothesis_id: str causal_chain: str supporting_evidence: str | None confidence: float is_causally_verified: bool discriminating_test: str | None @dataclass(frozen=True) class OutcomeContext: outcome_id: str hypotheses: tuple[CausalHypothesis, ...] selected_hypothesis_id: str | None @dataclass(frozen=True) class ReconstructionPolicy: require_multiple_hypotheses_for_ambiguous: bool @dataclass(frozen=True) class ReconstructionManifest: verdict: CausalVerdict directive: str manifest_digest: str class CausalReconstructionGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_reconstruction( cls, ctx: OutcomeContext, policy: ReconstructionPolicy ) -> ReconstructionManifest: # Gate 1: Verified causal chain verified = [h for h in ctx.hypotheses if h.is_causally_verified] if verified: digest = cls._hash(json.dumps({ "outcome": ctx.outcome_id, "verified": tuple(h.hypothesis_id for h in verified) }, sort_keys=True)) return ReconstructionManifest( verdict=CausalVerdict.DIRECT_CAUSAL_EVIDENCE, directive=f"PROCEED: {len(verified)} causally verified hypotheses for {ctx.outcome_id}.", manifest_digest=digest ) # Gate 2: Premature commitment if ctx.selected_hypothesis_id and len(ctx.hypotheses) == 1: if policy.require_multiple_hypotheses_for_ambiguous: return ReconstructionManifest( verdict=CausalVerdict.PREMATURE_COMMITMENT, directive=f"HALT: Outcome {ctx.outcome_id} has single unverified hypothesis, premature commitment.", manifest_digest=cls._hash(f"PREMATURE:{ctx.selected_hypothesis_id}") ) # Gate 3: Discrimination availability with_tests = [h for h in ctx.hypotheses if h.discriminating_test] if len(ctx.hypotheses) > 1 and with_tests: digest = cls._hash(json.dumps({ "outcome": ctx.outcome_id, "hypotheses": tuple(h.hypothesis_id for h in ctx.hypotheses), "testable": tuple(h.hypothesis_id for h in with_tests) }, sort_keys=True)) return ReconstructionManifest( verdict=CausalVerdict.DISCRIMINATION_READY, directive=f"ACTION: {len(with_tests)} of {len(ctx.hypotheses)} hypotheses have discriminating tests.", manifest_digest=digest ) # Gate 4: Multiple hypotheses tracked digest = cls._hash(json.dumps({ "outcome": ctx.outcome_id, "hypotheses": tuple( {"id": h.hypothesis_id, "confidence": f"{h.confidence:.3f}", "verified": str(h.is_causally_verified)} for h in ctx.hypotheses ), "selected": ctx.selected_hypothesis_id }, sort_keys=True)) return ReconstructionManifest( verdict=CausalVerdict.HYPOTHESES_TRACKED, directive=f"PROCEED: {len(ctx.hypotheses)} hypotheses tracked for {ctx.outcome_id}.", manifest_digest=digest )