Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Stable elections succeed: some stable election execution ends with the candidate elected

Proved
OpenSearchProgress.election_possible

by pitimespi · Nov 1, 2026 · Mathlib 0df444a (Lean v4.33.1)

cluster-coordinationconsensuselasticsearchformal-verificationleader-electionlivenessmessage-passingopensearchpartial-synchronypaxosprogresspublicationraftzen2

For every payload type V, cluster parameters P with P.InitCompatible and P.strategy = ElectionStrategy.DEFAULT_INSTANCE, every cluster W with Reachable P W, every node c, term t and list of node ids Q such that

  • c and every member of Q are cluster-manager-eligible;
  • Q is a quorum of (W.node c).lastCommittedConfiguration and of (W.node c).lastAcceptedConfiguration;
  • c and every member of Q are in a term below t;
  • every member of Q has an accepted state no fresher than c's: (W.node q).lastAcceptedTerm < (W.node c).lastAcceptedTerm, or the terms are equal and (W.node q).lastAcceptedVersionOrMetadataVersion ≤ (W.node c).lastAcceptedVersionOrMetadataVersion;

there is a cluster W' with ElectionExec P c t Q (W.node c).lastAcceptedTerm (W.node c).lastAcceptedVersion W W', (W'.node c).currentTerm = t and (W'.node c).electionWon = true.

The theorem asserts only that such an execution exists. In the proof's witness, c handles its own start-join request for t, every voter not yet in term t handles it and sends its join, and c handles every voter's join; the stable period allows each of these steps, so the premises of election_won are reached.

Preamble
import Definitions.Def_OpenSearchProgress
open OpenSearchCoordination OpenSearchSafety OpenSearchProgress
Formal statement
theorem OpenSearchProgress.election_possible {V : Type} (P : Params) (hP : P.InitCompatible)
    (hes : P.strategy = ElectionStrategy.DEFAULT_INSTANCE) (W : Cluster V) (hW : Reachable P W)
    (c : NodeId) (t : Nat) (Q : List NodeId) (hc : P.eligible c = true) (hQ : ∀ q ∈ Q, P.eligible q = true)
    (hquorum : (W.node c).lastCommittedConfiguration.hasQuorum Q = true ∧
      (W.node c).lastAcceptedConfiguration.hasQuorum Q = true)
    (hterm : ∀ q, q = c ∨ q ∈ Q → (W.node q).currentTerm < t)
    (hfresh : ∀ q ∈ Q, (W.node q).lastAcceptedTerm < (W.node c).lastAcceptedTerm ∨
      ((W.node q).lastAcceptedTerm = (W.node c).lastAcceptedTerm ∧
        (W.node q).lastAcceptedVersionOrMetadataVersion ≤ (W.node c).lastAcceptedVersionOrMetadataVersion)) :
    ∃ W', ElectionExec P c t Q (W.node c).lastAcceptedTerm (W.node c).lastAcceptedVersion W W' ∧
      (W'.node c).currentTerm = t ∧ (W'.node c).electionWon = true := by sorry
Source
OpenSearch b2a54ba5c0defba3d1d20423e911d4bf920bab19: Coordinator (handlePublishRequest lines 454-526 with ensureTermAtLeast at 512, startElection 583-602, ensureTermAtLeast 635-641, joinLeaderInTerm 643-657, handleJoin 1267-1287 with handleJoinIgnoringExceptions 1289-1299, publish 1350 with the handleClientValue call at 1404, CoordinatorPublication.handlePublishResponse 1871-1875): https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java; CoordinationState (isPublishQuorum lines 156-158, handleStartJoin 213-255, handleJoin 264-339, handleClientValue 348-407, handlePublishRequest 416-460, handlePublishResponse 471-515, handleCommit 523-573) as transcribed by the OpenSearchCoordination mission: https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/CoordinationState.java; the cluster model, the safety vocabulary and the inductive invariant of the OpenSearchSafety mission (Step, Reachable, Committed, Inv, reachable_inv); for why progress needs a stable period: M. J. Fischer, N. A. Lynch, M. S. Paterson, Impossibility of distributed consensus with one faulty process, J. ACM 32(2), 1985, and C. Dwork, N. Lynch, L. Stockmeyer, Consensus in the presence of partial synchrony, J. ACM 35(2), 1988
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5 (independent sub-agent, blind: Lean code + auditor instructions only)

Read-back: OpenSearchProgress.election_possible

Notions used

The full expansions are in readback_Def_OpenSearchProgress.md.

Node-state notation. For a node state σ\sigmaσ:

  • cur(σ)\mathrm{cur}(\sigma)cur(σ) is the current term;
  • lat(σ)\mathrm{lat}(\sigma)lat(σ) and lav(σ)\mathrm{lav}(\sigma)lav(σ) are the term and version of the last accepted state;
  • lavm(σ)\mathrm{lavm}(\sigma)lavm(σ) is that state's metadata version if its term is 0, and its version otherwise;
  • lcc(σ)\mathrm{lcc}(\sigma)lcc(σ) and lac(σ)\mathrm{lac}(\sigma)lac(σ) are its last committed and last accepted configurations;
  • won(σ)\mathrm{won}(\sigma)won(σ) is electionWon.

Quorum(X,L)\mathrm{Quorum}(X, L)Quorum(X,L) means that strictly more than half of the ids of configuration XXX occur in the list LLL. It is false for an empty XXX and for L=[ ]L = [\,]L=[].

The election period ElectionExec(P,c,t,Q,kt,kv)(W,W′)\mathrm{ElectionExec}(P, c, t, Q, k_t, k_v)(W, W')ElectionExec(P,c,t,Q,kt​,kv​)(W,W′) is a finite, possibly empty, sequence of Steps from WWW to W′W'W′, each of one of the following kinds. Here σ\sigmaσ is the acting node's state.

  • bootstrap of a node outside {c}∪Q\{c\} \cup Q{c}∪Q.

  • start-join at any node nnn, on a request from an eligible srcsrcsrc in term t′t't′, where t′<tt' < tt′<t or (src=csrc = csrc=c and t′=tt' = tt′=t). It succeeds iff t′>cur(σ)t' > \mathrm{cur}(\sigma)t′>cur(σ). The node then moves to term t′t't′ (clearing votes, setting startedJoinSinceLastReboot and resetting electionWon) and sends the join ⟨ln(σ),P.dn(src),t′,lat(σ),lavm(σ)⟩\langle \mathrm{ln}(\sigma), P.\mathrm{dn}(src), t', \mathrm{lat}(\sigma), \mathrm{lavm}(\sigma)\rangle⟨ln(σ),P.dn(src),t′,lat(σ),lavm(σ)⟩.

  • join: a node handles a sent join addressed to it. handleJoin succeeds iff:

    • the term matches;
    • the node has started a join since its last restart;
    • the join's last accepted (term, version) is not above the node's (lat,lavm)(\mathrm{lat}, \mathrm{lavm})(lat,lavm) in the order "term first, then version within the same term";
    • the node's lac\mathrm{lac}lac is non-empty.

    It then adds the source's id, if the source is flagged cluster-manager, and recomputes electionWon. Under the default strategy the new value is "votes are a quorum of both lcc\mathrm{lcc}lcc and lac\mathrm{lac}lac".

  • publish: any node handles any sent publication, except that ccc and members of QQQ may accept only publications with key ⪯(kt,kv)\preceq (k_t, k_v)⪯(kt​,kv​).

  • respond and commit: unrestricted.

  • restart of an eligible node outside {c}∪Q\{c\} \cup Q{c}∪Q.

  • restartAny of a non-eligible node.

There is no step that sends a new publication. In this theorem, (kt,kv)=(lat,lav)(k_t, k_v) = (\mathrm{lat}, \mathrm{lav})(kt​,kv​)=(lat,lav) of W.node cW.\mathrm{node}\ cW.node c.

1. Declaration

The universally quantified variables and hypotheses, in order:

NameType / statement
V (implicit)Type
PParams
hPP.InitCompatibleP.\mathrm{InitCompatible}P.InitCompatible
hesP.strategy=DEFAULT_INSTANCEP.\mathrm{strategy} = \mathrm{DEFAULT\_INSTANCE}P.strategy=DEFAULT_INSTANCE
WCluster V
hWReachable(P,W)\mathrm{Reachable}(P, W)Reachable(P,W)
cnode id (candidate)
tN\mathbb{N}N (election term)
Qlist of node ids (voters)
hcP.eligible(c)=trueP.\mathrm{eligible}(c) = \mathrm{true}P.eligible(c)=true
hQ∀q∈Q, P.eligible(q)=true\forall q \in Q,\ P.\mathrm{eligible}(q) = \mathrm{true}∀q∈Q, P.eligible(q)=true
hquorumQuorum(lcc(W.node c),Q)∧Quorum(lac(W.node c),Q)\mathrm{Quorum}(\mathrm{lcc}(W.\mathrm{node}\ c), Q) \land \mathrm{Quorum}(\mathrm{lac}(W.\mathrm{node}\ c), Q)Quorum(lcc(W.node c),Q)∧Quorum(lac(W.node c),Q)
hterm∀q, (q=c∨q∈Q)→cur(W.node q)<t\forall q,\ (q = c \lor q \in Q) \to \mathrm{cur}(W.\mathrm{node}\ q) < t∀q, (q=c∨q∈Q)→cur(W.node q)<t
hfresh∀q∈Q, lat(W.node q)<lat(W.node c)∨(lat(W.node q)=lat(W.node c)∧lavm(W.node q)≤lavm(W.node c))\forall q \in Q,\ \mathrm{lat}(W.\mathrm{node}\ q) < \mathrm{lat}(W.\mathrm{node}\ c) \lor \big(\mathrm{lat}(W.\mathrm{node}\ q) = \mathrm{lat}(W.\mathrm{node}\ c) \land \mathrm{lavm}(W.\mathrm{node}\ q) \le \mathrm{lavm}(W.\mathrm{node}\ c)\big)∀q∈Q, lat(W.node q)<lat(W.node c)∨(lat(W.node q)=lat(W.node c)∧lavm(W.node q)≤lavm(W.node c))

Conclusion.

∃ W′,ElectionExec(P,c,t,Q,lat(W.node c),lav(W.node c))(W,W′)  ∧  cur(W′.node c)=t  ∧  won(W′.node c)=true.\exists\, W',\quad \mathrm{ElectionExec}(P, c, t, Q, \mathrm{lat}(W.\mathrm{node}\ c), \mathrm{lav}(W.\mathrm{node}\ c))(W, W') \;\land\; \mathrm{cur}(W'.\mathrm{node}\ c) = t \;\land\; \mathrm{won}(W'.\mathrm{node}\ c) = \mathrm{true}.∃W′,ElectionExec(P,c,t,Q,lat(W.node c),lav(W.node c))(W,W′)∧cur(W′.node c)=t∧won(W′.node c)=true.

In words: from WWW there is at least one stable election period for ccc, ttt and QQQ at whose end ccc is in term ttt and has won. Since cur(W.node c)<t\mathrm{cur}(W.\mathrm{node}\ c) < tcur(W.node c)<t, such a period contains at least ccc's start-join into ttt, which is on a request whose requester is ccc; the guard of the period requires this. It also contains at least one successful handleJoin at ccc after that start-join.

2. What is not constrained

  • Existence only. The theorem asserts that some stable election period leads to ccc's victory. It does not say that every period does, or that one must. It says nothing about which steps are used, how many, in what order, or what other nodes do along the way.
  • Model-relative. The existential ranges over executions of the model. In the model, a start-join needs no StartJoinRequest message: any node may act on a request "from" any eligible node. The Coordinator's own guards are not modelled. The witness execution may therefore use any steps the period admits. For example, a voter may join ccc's term before ccc itself does.
  • No hconf hypothesis. hquorum implies lac(W.node c)\mathrm{lac}(W.\mathrm{node}\ c)lac(W.node c) and lcc(W.node c)\mathrm{lcc}(W.\mathrm{node}\ c)lcc(W.node c) are non-empty, and that Q≠[ ]Q \ne [\,]Q=[].
  • hfresh is the right measure, at WWW only. hfresh uses lavm\mathrm{lavm}lavm, exactly the measure that handleJoin compares, and it holds at WWW. The period's freshness bound uses lav\mathrm{lav}lav. The witness may use only steps that keep the voters' joins acceptable.
  • hc is needed. A start-join's requester must be eligible, and the period lets term ttt be entered only on a request whose requester is ccc.
  • Other nodes are unconstrained. Nodes outside {c}∪Q\{c\} \cup Q{c}∪Q are unconstrained at WWW: any term, possibly ≥t\ge t≥t, possibly elected in some other term.
  • Implicit claim about other winners. The conclusion makes ccc a winner of term ttt in a cluster reachable from WWW; every election step is a Step. The Safety definitions' invariant field Inv.won_unique says at most one node wins each term. So the theorem implicitly asserts that its hypotheses exclude a WWW in which another node has already won term ttt, or has published in it. No hypothesis says so directly. It would have to follow from hquorum, hterm (no voter has reached ttt), hfresh and reachability.
  • Vacuity. The hypotheses are satisfiable. Take eligible nodes 1 and 2, bootstrap configuration {1,2}\{1, 2\}{1,2} only, and the default strategy. Bootstrap both nodes with the same term-0 state (version 0, metadata version 0). Set c=1c = 1c=1, Q=[1,2]Q = [1, 2]Q=[1,2], t=1t = 1t=1. A witness period:
    1. node 1 start-joins on its own request for term 1;
    2. node 2 start-joins on node 1's request;
    3. node 1 handles both joins and wins.

3. Plain-language summary

Suppose a reachable cluster under the default strategy satisfies:

  • the eligible candidate ccc and the eligible voters QQQ are all below term ttt;
  • QQQ is a majority of both of ccc's configurations;
  • no voter's last accepted state is fresher than ccc's.

Then the model has a stable election period, with no competing elections and no new publications, at the end of which ccc is in term ttt and has won. It is an existence result. Together with election_vote_accepted and election_won it describes possible progress; it does not claim that progress is inevitable.

Human review
  • Endorsed by Shuze Chen · Nov 1, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Nov 1, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me