# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/where-must-an-instance-refuse-to-commit-when-a-byzantine-replica-s-equivocation-is-indistinguishable-from-a-partition.md
# Remnant Warrant:    https://corpusfetch.com/c/where-must-an-instance-refuse-to-commit-when-a-byzantine-replica-s-equivocation-is-indistinguishable-from-a-partition.warrant.json
# Markdown SHA-256:   777e0721043e2ad8cf69b1bcc0637524cac9088af7f3ae2ad2fedb0c52b9d60f
# Code AST SHA-256:   a5cb7351c65a32feb3ffc1a3b0be4588e5648a163c40c075f2b7cebc2b0b75a1
# Verified Classes:   UnsafeCommitError, QuorumCertificate
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class UnsafeCommitError(RuntimeError):
    """Raised when an instance attempts to commit on a bare quorum
    whose signer set could be a subset of an equivocating replica's
    outbound set, with no finality anchor to disambiguate."""
    pass


class QuorumCertificate:
    def __init__(self, view: int, seq: int, payload_hash: str,
                 signers: frozenset, finality_anchor: bool):
        self.view = view
        self.seq = seq
        self.payload_hash = payload_hash
        self.signers = signers
        self.finality_anchor = finality_anchor


def commit_task(qc: QuorumCertificate, f: int,
                local_evidence: dict) -> None:
    """Commit a task commitment to shared state.

    Refuses if the QC is a bare quorum (no finality anchor) AND the
    local evidence store contains any signed message inconsistent
    with the committed payload. Such inconsistency could be a
    partition or equivocation; we cannot tell locally, so we hold.
    """
    threshold = 2 * f + 1
    if len(qc.signers) < threshold:
        raise UnsafeCommitError(
            f"quorum too small: {len(qc.signers)} < {threshold}"
        )

    if not qc.finality_anchor:
        # Bare quorum: check for any conflicting signed message
        # from a signer at the same (view, seq).
        for signer, msgs in local_evidence.items():
            if signer not in qc.signers:
                continue
            for m in msgs:
                if (m.view == qc.view and m.seq == qc.seq
                        and m.payload_hash != qc.payload_hash):
                    raise UnsafeCommitError(
                        f"bare quorum with conflicting evidence from "
                        f"{signer}: {m.payload_hash} != "
                        f"{qc.payload_hash}; hold for reconciliation"
                    )

    # Safe to commit: either anchored, or no conflicting evidence.
    _write_shared_state(qc.payload_hash, qc.task_id if hasattr(qc, 'task_id') else None)


def _write_shared_state(payload_hash: str, task_id) -> None:
    # Placeholder for the actual shared-state write.
    pass
