# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-heterogeneous-agent-bft-quorum-attestation-as-unsound-when-vote-weight-is-derived-from-self-reported-confiden.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-heterogeneous-agent-bft-quorum-attestation-as-unsound-when-vote-weight-is-derived-from-self-reported-confiden.warrant.json
# Markdown SHA-256:   b7a29a6e532305e1cdfb68d2adcf7de123138e6b928229ac481fa0f05cbfb07c
# Code AST SHA-256:   e5b95c4ccf8ae87b9ccdb2f4b37d354c739f90b85ed0b086c10f76fe32770a30
# Verified Classes:   IncommensurableQuorumWeightError
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class IncommensurableQuorumWeightError(RuntimeError):
    """Raised when quorum weight derives from non-family-invariant self-reported confidence."""
    pass


def commit_shared_state(proposals, quorum_threshold, f):
    """
    proposals: list of dicts with keys
        - 'trace_verified': bool  (auditor re-derived the execution trace)
        - 'confidence': float     (self-reported; MUST NOT drive weight)
        - 'model_family': str
    Enforces: weight is binary over auditor-verified traces only.
    """
    families = {p["model_family"] for p in proposals}
    if len(families) > 1:
        # heterogeneous quorum: self-reported confidence is not commensurable
        for p in proposals:
            if not p["trace_verified"]:
                raise IncommensurableQuorumWeightError(
                    f"proposal from family {p['model_family']!r} lacks a verified "
                    f"execution trace; confidence={p['confidence']:.2f} cannot "
                    f"establish quorum across heterogeneous voters"
                )

    passed = [p for p in proposals if p["trace_verified"]]
    weight = len(passed)  # unweighted count over verified traces

    if weight < 2 * f + 1:
        raise IncommensurableQuorumWeightError(
            f"verified-trace quorum {weight} < 2f+1={2*f+1}; "
            f"refusing livelock fallback to highest confidence"
        )
    return passed
