Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

A node answers a pre-vote request exactly when it is healthy and follows no other leader

Proved
OpenSearchPreVote.handlePreVoteRequest_spec

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

cluster-coordinationconsensuselasticsearchelection-schedulerformal-verificationleader-electionopensearchpaxospre-voteraftzen2

For every health status healthy, collector state st, request req and response resp: handlePreVoteRequest healthy st req = .ok resp iff healthy = true, the node knows no leader or knows the requester as its leader (st.leader = none ∨ st.leader = some req.sourceNode), and resp = st.response, the node's own current response. Unhealthy nodes and nodes that follow a leader other than the requester refuse.

Preamble
import Definitions.Def_OpenSearchPreVote
open OpenSearchCoordination OpenSearchPreVote
Formal statement
theorem OpenSearchPreVote.handlePreVoteRequest_spec (healthy : Bool) (st : CollectorState) (req : PreVoteRequest)
    (resp : PreVoteResponse) :
    handlePreVoteRequest healthy st req = .ok resp ↔
      healthy = true ∧ (st.leader = none ∨ st.leader = some req.sourceNode) ∧ resp = st.response := by sorry
Source
OpenSearch b2a54ba5c0defba3d1d20423e911d4bf920bab19: PreVoteCollector (state line 79, start 111-115, update 128-131, handlePreVoteRequest 133-163, PreVotingRound 175-300, handlePreVoteResponse 225-279, close 296-299): https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/PreVoteCollector.java#L66-L301; Coordinator (updateMaxTermSeen lines 560-581, startElection 583-602, nodeMayWinElection 628-633, getPreVoteResponse 873-879, handleJoin 1267-1299, startElectionScheduler 1567-1618, the preVoteCollector.update calls 516, 653, 777, 801, 839, 1157): https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java#L560-L633; ElectionSchedulerFactory (settings lines 85-115, constructor check 133-143, nonNegative 159-161, toPositiveLongAtMost 169-172, scheduleNextElection 195-241): https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/ElectionSchedulerFactory.java#L62-L254; ElectionStrategy.isElectionQuorum (lines 68-88): https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/ElectionStrategy.java#L68-L88; the messages PreVoteRequest.java and PreVoteResponse.java in the same directory; CoordinationState (handleStartJoin, handleJoin) as transcribed by the OpenSearchCoordination mission
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: OpenSearchPreVote.handlePreVoteRequest_spec

Notions used

Discovery nodes. A discovery node is a pair (node id ∈N\in \mathbb{N}∈N, Boolean "cluster-manager-eligible" flag). Two discovery nodes are equal iff both components are equal.

Messages and collector state.

  • A pre-vote request reqreqreq has a source node req.sourceNodereq.\mathrm{sourceNode}req.sourceNode and a term req.currentTerm∈Nreq.\mathrm{currentTerm} \in \mathbb{N}req.currentTerm∈N.
  • A pre-vote response is a triple ⟨currentTerm∈N, lastAcceptedTerm∈N, lastAcceptedVersion∈Z⟩\langle \mathrm{currentTerm} \in \mathbb{N},\ \mathrm{lastAcceptedTerm} \in \mathbb{N},\ \mathrm{lastAcceptedVersion} \in \mathbb{Z}\rangle⟨currentTerm∈N, lastAcceptedTerm∈N, lastAcceptedVersion∈Z⟩.
  • A collector state ststst has a known leader st.leaderst.\mathrm{leader}st.leader ("none", or "some lll" for a discovery node lll) and a stored response st.responsest.\mathrm{response}st.response.

The handler. handlePreVoteRequest(healthy,st,req)\mathrm{handlePreVoteRequest}(\mathit{healthy}, st, req)handlePreVoteRequest(healthy,st,req) returns either an error string or a response:

  • If healthy\mathit{healthy}healthy is false: the error "rejecting on unhealthy node".
  • Otherwise, if st.leader=nonest.\mathrm{leader} = \text{none}st.leader=none: success with st.responsest.\mathrm{response}st.response.
  • Otherwise, if st.leader=some lst.\mathrm{leader} = \text{some } lst.leader=some l with l=req.sourceNodel = req.\mathrm{sourceNode}l=req.sourceNode: success with st.responsest.\mathrm{response}st.response.
  • Otherwise: the error "rejecting as there is already a leader".

1. Declaration

Binders. There are no hypotheses.

  • healthy\mathit{healthy}healthy: a Boolean;
  • ststst: a collector state;
  • reqreqreq: a pre-vote request;
  • resprespresp: a pre-vote response.

Conclusion.

handlePreVoteRequest(healthy,st,req)=ok(resp)  ⟺  healthy=true  ∧  (st.leader=none∨st.leader=some req.sourceNode)  ∧  resp=st.response.\mathrm{handlePreVoteRequest}(\mathit{healthy}, st, req) = \mathrm{ok}(resp) \iff \mathit{healthy} = \mathrm{true} \;\wedge\; \big(st.\mathrm{leader} = \text{none} \vee st.\mathrm{leader} = \text{some } req.\mathrm{sourceNode}\big) \;\wedge\; resp = st.\mathrm{response}.handlePreVoteRequest(healthy,st,req)=ok(resp)⟺healthy=true∧(st.leader=none∨st.leader=some req.sourceNode)∧resp=st.response.

In words, the handler returns success with resprespresp exactly when three things hold:

  • the node is healthy;
  • the node knows no leader, or the leader it knows is exactly the requesting node (same id and same flag);
  • resprespresp is the node's stored response.

2. What is not constrained

  • The request's term. req.currentTermreq.\mathrm{currentTerm}req.currentTerm does not occur on the right-hand side. The handler never reads it.
  • Leader equality. It is structural on (id, flag). A known leader with the requester's id but the opposite flag counts as "another leader", and the request is refused.
  • Errors. The theorem says nothing about the error messages and does not separate the two refusal reasons. The handler always returns either success or an error. So for given (healthy,st,req)(\mathit{healthy}, st, req)(healthy,st,req), the theorem also implies: the handler is an error iff the first two conjuncts fail. When it succeeds, the value is exactly st.responsest.\mathrm{response}st.response.
  • Side effects. The Java handler's side effect (raising maxTermSeen to the request's term) is not modelled by the function, so the theorem does not mention it.
  • Vacuity. There are no hypotheses, so nothing can be vacuous. Both sides are satisfiable; for example, take healthy=true\mathit{healthy} = \mathrm{true}healthy=true, st.leader=nonest.\mathrm{leader} = \text{none}st.leader=none and resp=st.responseresp = st.\mathrm{response}resp=st.response.

3. Plain-language summary

A node grants a pre-vote request if and only if it is healthy and either knows no leader or its known leader is the requester itself. When it grants, it returns its stored response unchanged. The term carried by the request plays no role in the decision.

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