# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/why-does-an-instance-of-byzantine-plan-commitment-stall-at-exactly-f-1-equivocating-agents-a-boundary-record-for-multi-agent-consensus-operators.md
# Remnant Warrant:    https://corpusfetch.com/c/why-does-an-instance-of-byzantine-plan-commitment-stall-at-exactly-f-1-equivocating-agents-a-boundary-record-for-multi-agent-consensus-operators.warrant.json
# Markdown SHA-256:   fb74a845efe2a6dddf954438e43d1633bacbe608dd44e95db0053109ab30a5c0
# Code AST SHA-256:   7d4111401d5291582a2d33025bdddcb4c2c16e33d044e7db17b032750906b0ca
# Verified Classes:   PlanMergeConflict
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class PlanMergeConflict(RuntimeError):
    """Raised when a committed fragment set cannot be merged into a DAG."""
    pass


def commit_plan(fragment_set, quorum_size, f, equivocation_evidence):
    """
    Commit a plan fragment set under a fragment-set certificate.
    Raises PlanMergeConflict if the committed set is not jointly mergeable,
    which at >= f+1 view-partitioning equivocators is a Byzantine signal,
    not an authoring error.
    """
    if len(fragment_set) < quorum_size:
        raise PlanMergeConflict(
            f"fragment set size {len(fragment_set)} below quorum {quorum_size}"
        )

    # Attempt the global merge; this is the layer where equivocation surfaces.
    try:
        merged = merge_dependency_dag(fragment_set)
    except CycleDetected as exc:
        equivocators = identify_equivocators(equivocation_evidence)
        if len(equivocators) >= f + 1:
            raise PlanMergeConflict(
                f"post-commit merge abort with {len(equivocators)} equivocators "
                f"(>= f+1 = {f + 1}); commit certificate is irrevocable, "
                f"escalate to merged-DAG certificate upgrade. "
                f"Cycle: {exc.cycle}"
            ) from exc
        raise PlanMergeConflict(
            f"merge abort with {len(equivocators)} equivocators (< f+1); "
            f"treat as authoring error and re-plan"
        ) from exc

    return merged
