# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-should-conflicting-agent-negotiations-be-resolved-when-quorum-is-mathematically-impossible.md # Remnant Warrant: https://corpusfetch.com/c/how-should-conflicting-agent-negotiations-be-resolved-when-quorum-is-mathematically-impossible.warrant.json # Markdown SHA-256: fa1915e3df0b1b09816b5a0d508ba284c18fb9107ddc38cff21a985d0f2405b5 # Code AST SHA-256: d912714cb1a6c631f6a1a2cbd5a2cedb4b17bb80e528fb946144bfe1b4feda7f # Verified Classes: ConsensusVerdict, ConsensusContext, ConsensusManifest, ByzantineQuorumGuard # Defensive Guards: 1 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json import math class ConsensusVerdict(Enum): QUORUM_ACHIEVABLE = auto() MATHEMATICALLY_IMPOSSIBLE = auto() AWAITING_MORE_AGENTS = auto() @dataclass(frozen=True) class ConsensusContext: total_registered: int responsive_honest: int max_possible_byzantine: int quorum_threshold: int @dataclass(frozen=True) class ConsensusManifest: verdict: ConsensusVerdict directive: str manifest_digest: str class ByzantineQuorumGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_quorum(cls, ctx: ConsensusContext) -> ConsensusManifest: if ctx.quorum_threshold <= 0: raise ValueError("Quorum threshold must be positive.") # Gate 1: If we already have enough honest agents, proceed. if ctx.responsive_honest >= ctx.quorum_threshold: return ConsensusManifest( verdict=ConsensusVerdict.QUORUM_ACHIEVABLE, directive="PROCEED: Honest agents satisfy quorum.", manifest_digest=cls._hash("ACHIEVABLE") ) # Gate 2: Check if the remaining unresponsive agents can possibly fulfill the gap max_possible_votes = ctx.responsive_honest + (ctx.total_registered - ctx.responsive_honest) # If even if every unresponsive agent came online, we couldn't reach quorum if max_possible_votes < ctx.quorum_threshold: return ConsensusManifest( verdict=ConsensusVerdict.MATHEMATICALLY_IMPOSSIBLE, directive="HALT: Quorum is mathematically impossible. Escalate to fallback arbitration.", manifest_digest=cls._hash("IMPOSSIBLE_MAX") ) # Gate 3: Byzantine check. If remaining agents are assumed Byzantine, can we still reach quorum? # In a BFT system, quorum = 2f + 1, where f = max_byzantine. # We can reach quorum if responsive_honest >= quorum_threshold. # We already checked this in Gate 1. # But what if the remaining required votes must come from agents that might be Byzantine? # In a strict BFT system, you cannot trust unresponsive agents. # Thus, if responsive_honest < quorum_threshold, you MUST wait. if ctx.total_registered <= (2 * ctx.max_possible_byzantine): return ConsensusManifest( verdict=ConsensusVerdict.MATHEMATICALLY_IMPOSSIBLE, directive=f"HALT: Topology is impossible. Total agents ({ctx.total_registered}) <= 2 * max_byzantine ({ctx.max_possible_byzantine}).", manifest_digest=cls._hash("IMPOSSIBLE_BYZANTINE") ) return ConsensusManifest( verdict=ConsensusVerdict.AWAITING_MORE_AGENTS, directive="WAIT: Quorum is achievable but not yet reached. Await responses.", manifest_digest=cls._hash("AWAITING") )