# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-a-plan-commitment-quorum-has-silently-forked-under-adversarial-peer-equivocation.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-a-plan-commitment-quorum-has-silently-forked-under-adversarial-peer-equivocation.warrant.json
# Markdown SHA-256:   6e217c078c8be68f62030baf93895be13ca3c01f6c8507ab84af609c965c7239
# Code AST SHA-256:   bd8dcc4dca551bdc6c4c6e01135981f1791d1498002836567f97ddc45e9ee0b4
# Verified Classes:   QuorumForkError, Quorum, PlanCommitter
# Defensive Guards:   3 fail-closed invariants (zero external deps)

from dataclasses import dataclass, field
from typing import FrozenSet, Optional

class QuorumForkError(RuntimeError):
    """Raised when a plan-commit quorum's intersection with the prior quorum
    contains no non-suspect member, indicating a silent fork under equivocation."""
    pass

@dataclass(frozen=True)
class Quorum:
    plan_hash: str
    epoch: int
    signers: FrozenSet[str]

@dataclass
class PlanCommitter:
    suspect: FrozenSet[str] = field(default_factory=frozenset)
    last_committed: Optional[Quorum] = None

    def commit(self, candidate: Quorum, n_agents: int, f: int) -> Quorum:
        quorum_size = 2 * f + 1
        if n_agents < 3 * f + 1:
            raise QuorumForkError(
                f"N={n_agents} < 3f+1={3*f+1}; quorum intersection not guaranteed"
            )
        if len(candidate.signers) < quorum_size:
            raise QuorumForkError(
                f"quorum {len(candidate.signers)} < required {quorum_size}"
            )
        if self.last_committed is not None:
            intersection = candidate.signers & self.last_committed.signers
            honest_intersection = intersection - self.suspect
            if not honest_intersection:
                raise QuorumForkError(
                    f"fork detected: quorum intersection {sorted(intersection)} "
                    f"is entirely suspect; plan {candidate.plan_hash} at epoch "
                    f"{candidate.epoch} conflicts with {self.last_committed.plan_hash}"
                )
        self.last_committed = candidate
        return candidate
