# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-handle-reference-propagation-across-a-network-partition.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-handle-reference-propagation-across-a-network-partition.warrant.json # Markdown SHA-256: 36cd165c4c270d4f24a120c169263cfc0efe236acefc88eb6e0b555f7dcd9424 # Code AST SHA-256: ef7c7013c13065a2afe679185d7da51a65d7271c14496a10d6ff1d4b2cd342ad # Verified Classes: PartitionVerdict, PartitionedMesh, PartitionPolicy, PartitionManifest, PartitionReferenceGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class PartitionVerdict(Enum): NO_PARTITION = auto() PARTITION_ACTIVE = auto() RECONCILIATION_READY = auto() RECONCILIATION_REQUIRED = auto() @dataclass(frozen=True) class PartitionedMesh: partition_a_id: str partition_b_id: str references_before_partition: frozenset[str] references_in_a_during: frozenset[str] references_in_b_during: frozenset[str] revocations_in_a_during: frozenset[str] reconciliation_protocol: str | None @dataclass(frozen=True) class PartitionPolicy: require_reconciliation_protocol: bool @dataclass(frozen=True) class PartitionManifest: verdict: PartitionVerdict directive: str manifest_digest: str class PartitionReferenceGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_partition( cls, mesh: PartitionedMesh, policy: PartitionPolicy ) -> PartitionManifest: # Gate 1: No partition if not mesh.references_in_a_during and not mesh.references_in_b_during and not mesh.revocations_in_a_during: digest = cls._hash(json.dumps({ "refs": tuple(sorted(mesh.references_before_partition)), "status": "NO_DIVERGENCE" }, sort_keys=True)) return PartitionManifest( verdict=PartitionVerdict.NO_PARTITION, directive=f"PROCEED: No partition-divergent references.", manifest_digest=digest ) # Gate 2: Protocol presence if policy.require_reconciliation_protocol and not mesh.reconciliation_protocol: return PartitionManifest( verdict=PartitionVerdict.RECONCILIATION_REQUIRED, directive=f"HALT: Partition-divergent references exist without reconciliation protocol.", manifest_digest=cls._hash("NO_PROTOCOL") ) # Gate 3: Partition active (reconciliation not yet performed) if mesh.reconciliation_protocol and mesh.references_in_a_during and mesh.references_in_b_during: digest = cls._hash(json.dumps({ "a_refs": tuple(sorted(mesh.references_in_a_during)), "b_refs": tuple(sorted(mesh.references_in_b_during)), "a_revocations": tuple(sorted(mesh.revocations_in_a_during)), "protocol": mesh.reconciliation_protocol }, sort_keys=True)) return PartitionManifest( verdict=PartitionVerdict.PARTITION_ACTIVE, directive=f"ACTION: Partition active with divergent refs. Reconciliation via {mesh.reconciliation_protocol} when healed.", manifest_digest=digest ) # Gate 4: Reconciliation ready digest = cls._hash(json.dumps({ "a_count": str(len(mesh.references_in_a_during)), "b_count": str(len(mesh.references_in_b_during)), "revocations": str(len(mesh.revocations_in_a_during)), "protocol": mesh.reconciliation_protocol }, sort_keys=True)) return PartitionManifest( verdict=PartitionVerdict.RECONCILIATION_READY, directive=f"PROCEED: Partition healed, reconciliation via {mesh.reconciliation_protocol}.", manifest_digest=digest )