# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-do-contradictory-retrieved-sources-get-reconciled-without-averaging-incompatible-premises.md # Remnant Warrant: https://corpusfetch.com/c/how-do-contradictory-retrieved-sources-get-reconciled-without-averaging-incompatible-premises.warrant.json # Markdown SHA-256: 93e8cada8ab45378a77a5ef2d73383122a9f82b6c4caa9910f7824a454ded56f # Code AST SHA-256: b0bfc798681292840474b3c91e8fc8918f552141513dfb68381034cfe3919dee # Verified Classes: PremiseAveragingProhibitedError, SourceAuthorityRank, SourcedClaimRecord, ReconciliationResolution, ContradictorySourceReconciler # Defensive Guards: 1 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import IntEnum from typing import Any class PremiseAveragingProhibitedError(ValueError): '''Raised when an instance attempts to blend incompatible claims or guess across tied primary conflicts.''' pass class SourceAuthorityRank(IntEnum): LIVE_RUNTIME_VERIFICATION = 1 PRIMARY_CODE_OR_CONTRACT = 2 OFFICIAL_DOCUMENTATION = 3 SECONDARY_WIKI_OR_SUMMARY = 4 @dataclass(frozen=True) class SourcedClaimRecord: source_id: str authority_rank: SourceAuthorityRank scope_tag: str # e.g., "v2_prod", "v1_legacy" effective_epoch: int claim_value: Any @dataclass(frozen=True) class ReconciliationResolution: resolution_mode: str # "SCOPE_PARTITIONED" | "AUTHORITY_DOMINANCE" | "TEMPORAL_SUPERSESSION" | "IRREDUCIBLE_FORK" scoped_verdicts: dict[str, SourcedClaimRecord] unresolved_fork_sources: tuple[str, ...] class ContradictorySourceReconciler: ''' Reconciles contradictory retrieved sources without averaging or blending premises: 1. Partitions claims by `scope_tag` so disjoint environments/versions coexist cleanly. 2. Within each scope, resolves conflicts by `SourceAuthorityRank` (lower int = higher authority), then by `effective_epoch` timestamp. 3. Flags `IRREDUCIBLE_FORK` whenever two sources tie on scope, authority rank, and timestamp with conflicting values—refusing to average or guess. ''' @classmethod def reconcile_claims(cls, claims: list[SourcedClaimRecord]) -> ReconciliationResolution: if not claims: raise ValueError("Claim list cannot be empty.") by_scope: dict[str, list[SourcedClaimRecord]] = {} for c in claims: by_scope.setdefault(c.scope_tag, []).append(c) scoped_winners: dict[str, SourcedClaimRecord] = {} fork_sources: list[str] = [] used_authority = False used_temporal = False for scope, group in by_scope.items(): # Sort by highest authority (lowest IntEnum value), then newest timestamp (-effective_epoch) ordered = sorted(group, key=lambda r: (int(r.authority_rank), -r.effective_epoch)) top = ordered[0] # Check for tied peers with a conflicting value (Gate 4: Irreducible Fork) tied_conflicts = [ r for r in ordered[1:] if r.authority_rank == top.authority_rank and r.effective_epoch == top.effective_epoch and r.claim_value != top.claim_value ] if tied_conflicts: fork_sources.extend([top.source_id, *(r.source_id for r in tied_conflicts)]) continue # Track whether authority or recency resolved a conflict in this scope distinct_vals = {str(r.claim_value) for r in group} if len(distinct_vals) > 1: if any(r.authority_rank != top.authority_rank for r in group): used_authority = True else: used_temporal = True scoped_winners[scope] = top if fork_sources: mode = "IRREDUCIBLE_FORK" elif len(by_scope) > 1: mode = "SCOPE_PARTITIONED" elif used_authority: mode = "AUTHORITY_DOMINANCE" elif used_temporal: mode = "TEMPORAL_SUPERSESSION" else: mode = "UNANIMOUS" return ReconciliationResolution( resolution_mode=mode, scoped_verdicts=scoped_winners, unresolved_fork_sources=tuple(sorted(set(fork_sources))), )