Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

handleStartJoin re-establishes invariant()

Proved
OpenSearchCoordination.handleStartJoin_javaInvariant

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

cluster-coordinationconsensuscoordination-stateelasticsearchformal-verificationleader-electionopensearchpaxosquorumraftzen2

For every election strategy es and coordination state cs with cs.lastAcceptedTerm ≤ cs.currentTerm (nothing else is assumed): if cs.handleStartJoin r = .ok (cs', j) then cs'.javaInvariant es. Moving to a higher term discards the votes and the election, which makes the last four assertions of invariant() hold whatever held before; the first, assumed of cs, survives because the current term grows and the accepted state is unchanged.

Preamble
import Definitions.Def_OpenSearchCoordination
Formal statement
theorem OpenSearchCoordination.handleStartJoin_javaInvariant {V : Type} (es : ElectionStrategy) (cs : CoordinationState V) (r : StartJoinRequest)
    (cs' : CoordinationState V) (j : Join) (hcs : cs.lastAcceptedTerm ≤ cs.currentTerm)
    (h : cs.handleStartJoin r = .ok (cs', j)) : cs'.javaInvariant es := by sorry
Source
OpenSearch b2a54ba5c0defba3d1d20423e911d4bf920bab19: CoordinationState (constructor lines 84-106, isElectionQuorum 144-154, isPublishQuorum 156-158, setInitialState 180-204, handleStartJoin 213-255, handleJoin 264-339, handleClientValue 348-407, handlePublishRequest 416-460, handlePublishResponse 471-515, handleCommit 523-573, invariant 601-611, PersistedState.markLastAcceptedStateAsCommitted 703-728, commitVotingConfiguration 730-740, VoteCollection 750-814), server/src/main/java/org/opensearch/cluster/coordination/CoordinationState.java: https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/CoordinationState.java#L64-L815; CoordinationMetadata.VotingConfiguration (lines 383-449, hasQuorum 405-409): https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/CoordinationMetadata.java#L383-L449; ElectionStrategy (DEFAULT_INSTANCE lines 46-59, isElectionQuorum 68-88): https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/ElectionStrategy.java#L44-L110; ClusterState.getVersionOrMetadataVersion (lines 239-244): https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/ClusterState.java#L239-L244; Coordinator.ZEN1_BWC_TERM (line 134): https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java#L134; the messages StartJoinRequest.java, Join.java, PublishRequest.java, PublishResponse.java, ApplyCommitRequest.java in the same directory; test vectors from server/src/test/java/org/opensearch/cluster/coordination/CoordinationStateTests.java (https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/test/java/org/opensearch/cluster/coordination/CoordinationStateTests.java) and CoordinationMetadataTests.java (testVotingConfiguration)
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: OpenSearchCoordination.handleStartJoin_javaInvariant

Notions used

Coordination states. A coordination state cscscs has nine fields:

  • localNode\mathrm{localNode}localNode;
  • currentTerm∈N\mathrm{currentTerm} \in \mathbb{N}currentTerm∈N;
  • lastAcceptedState\mathrm{lastAcceptedState}lastAcceptedState, a cluster state with a term, a version, last committed and last accepted configurations, and other fields;
  • joinVotes\mathrm{joinVotes}joinVotes and publishVotes\mathrm{publishVotes}publishVotes, vote collections (lists of ids);
  • startedJoinSinceLastReboot\mathrm{startedJoinSinceLastReboot}startedJoinSinceLastReboot and electionWon\mathrm{electionWon}electionWon;
  • lastPublishedVersion∈Z\mathrm{lastPublishedVersion} \in \mathbb{Z}lastPublishedVersion∈Z;
  • lastPublishedConfiguration\mathrm{lastPublishedConfiguration}lastPublishedConfiguration.

Abbreviations, all read from the accepted state:

  • lat(cs)\mathrm{lat}(cs)lat(cs): its term;
  • lav(cs)\mathrm{lav}(cs)lav(cs): its version;
  • lavm(cs)\mathrm{lavm}(cs)lavm(cs): its metadata version if the term is 000, otherwise its version;
  • C(cs)\mathrm{C}(cs)C(cs) and A(cs)\mathrm{A}(cs)A(cs): its two configurations.

Quorums.

  • isQuorum(v,c)\mathrm{isQuorum}(v, c)isQuorum(v,c) is the strict-majority test. It is false whenever vvv is empty.
  • An election strategy eseses is an arbitrary Boolean function fesf_{es}fes​.
  • isElectionQuorum(es,cs,v)=isQuorum(v,C(cs))∧isQuorum(v,A(cs))∧fes(…,v)\mathrm{isElectionQuorum}(es, cs, v) = \mathrm{isQuorum}(v, \mathrm{C}(cs)) \wedge \mathrm{isQuorum}(v, \mathrm{A}(cs)) \wedge f_{es}(\dots, v)isElectionQuorum(es,cs,v)=isQuorum(v,C(cs))∧isQuorum(v,A(cs))∧fes​(…,v).

The Java invariant. javaInvariant(es,cs)\mathrm{javaInvariant}(es, cs)javaInvariant(es,cs) is the conjunction of:

  • (i) lat(cs)≤cs.currentTerm\mathrm{lat}(cs) \le cs.\mathrm{currentTerm}lat(cs)≤cs.currentTerm;
  • (ii) cs.electionWon=isElectionQuorum(es,cs,cs.joinVotes)cs.\mathrm{electionWon} = \mathrm{isElectionQuorum}(es, cs, cs.\mathrm{joinVotes})cs.electionWon=isElectionQuorum(es,cs,cs.joinVotes);
  • (iii) if cs.electionWoncs.\mathrm{electionWon}cs.electionWon, then cs.lastPublishedVersion≥lav(cs)cs.\mathrm{lastPublishedVersion} \ge \mathrm{lav}(cs)cs.lastPublishedVersion≥lav(cs); otherwise cs.lastPublishedVersion=0cs.\mathrm{lastPublishedVersion} = 0cs.lastPublishedVersion=0;
  • (iv) cs.electionWon→cs.startedJoinSinceLastRebootcs.\mathrm{electionWon} \to cs.\mathrm{startedJoinSinceLastReboot}cs.electionWon→cs.startedJoinSinceLastReboot;
  • (v) cs.publishVotescs.\mathrm{publishVotes}cs.publishVotes is empty ∨ cs.electionWon\vee\ cs.\mathrm{electionWon}∨ cs.electionWon.

The handler. handleStartJoin(cs,r)\mathrm{handleStartJoin}(cs, r)handleStartJoin(cs,r) fails if r.term≤cs.currentTermr.\mathrm{term} \le cs.\mathrm{currentTerm}r.term≤cs.currentTerm. Otherwise it returns cscscs updated as follows:

  • currentTerm:=r.term\mathrm{currentTerm} := r.\mathrm{term}currentTerm:=r.term;
  • lastPublishedVersion:=0\mathrm{lastPublishedVersion} := 0lastPublishedVersion:=0;
  • lastPublishedConfiguration:=A(cs)\mathrm{lastPublishedConfiguration} := \mathrm{A}(cs)lastPublishedConfiguration:=A(cs);
  • startedJoinSinceLastReboot:=true\mathrm{startedJoinSinceLastReboot} := \mathrm{true}startedJoinSinceLastReboot:=true;
  • electionWon:=false\mathrm{electionWon} := \mathrm{false}electionWon:=false;
  • joinVotes:=[ ]\mathrm{joinVotes} := [\,]joinVotes:=[] and publishVotes:=[ ]\mathrm{publishVotes} := [\,]publishVotes:=[].

The accepted state and the local node are unchanged. The handler also returns a join.

1. Declaration

Binders.

  • VVV (implicit);
  • eseses: an election strategy;
  • cscscs: a coordination state;
  • rrr: a start-join request;
  • cs′cs'cs′: a coordination state;
  • jjj: a join.

Hypotheses, in order.

  1. hcs\mathit{hcs}hcs: lat(cs)≤cs.currentTerm\mathrm{lat}(cs) \le cs.\mathrm{currentTerm}lat(cs)≤cs.currentTerm;
  2. hhh: handleStartJoin(cs,r)=ok(cs′,j)\mathrm{handleStartJoin}(cs, r) = \mathrm{ok}(cs', j)handleStartJoin(cs,r)=ok(cs′,j).

Conclusion. javaInvariant(es,cs′)\mathrm{javaInvariant}(es, cs')javaInvariant(es,cs′). Unfolded with the handler's result:

  • (i) lat(cs)≤r.term\mathrm{lat}(cs) \le r.\mathrm{term}lat(cs)≤r.term. This follows from hcs\mathit{hcs}hcs and r.term>cs.currentTermr.\mathrm{term} > cs.\mathrm{currentTerm}r.term>cs.currentTerm.
  • (ii) false=isElectionQuorum(es,cs′,[ ])\mathrm{false} = \mathrm{isElectionQuorum}(es, cs', [\,])false=isElectionQuorum(es,cs′,[]). The right side is false.
  • (iii) 0=00 = 00=0.
  • (iv) This holds vacuously.
  • (v) The publish votes are empty.

2. What is not constrained

  • cscscs need not satisfy the Java invariant. Only conjunct (i) is assumed, as hcs\mathit{hcs}hcs. The other four conjuncts are re-established by the reset, whatever cscscs's votes, flags and published version were.
  • eseses is arbitrary. No monotonicity is needed.
  • rrr and jjj are constrained only through hhh. The request's source node is arbitrary.
  • Not vacuous. The hypotheses are satisfiable: any cscscs with lat(cs)≤cs.currentTerm\mathrm{lat}(cs) \le cs.\mathrm{currentTerm}lat(cs)≤cs.currentTerm and any rrr with a larger term work.

3. Plain-language summary

A successful start-join, applied to any state whose last-accepted term is at most its current term, produces a state that satisfies all five Java invariant assertions, for every election strategy. This works because start-join clears the votes, resets the won flag and published version, and moves to a strictly larger term.

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