Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

handlePublishRequest accepts only a strictly newer state of the current term, Zen1 compatibility aside

Proved
OpenSearchCoordination.handlePublishRequest_spec

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

cluster-coordinationconsensuscoordination-stateelasticsearchformal-verificationleader-electionopensearchpaxosquorumraftzen2

Let cs be a coordination state with cs.lastAcceptedTerm ≤ cs.currentTerm, and suppose cs.handlePublishRequest req = .ok (cs', resp). Then:

  • cs'.lastAcceptedState = req.acceptedState and req.acceptedState.term = cs.currentTerm;
  • cs' has the current term and the local node of cs;
  • resp carries the term and the version of req.acceptedState;
  • the accepted state is strictly newer than the old one in the lexicographic (term, version) order — cs.lastAcceptedTerm < req.acceptedState.term, or the terms are equal and cs.lastAcceptedVersion < req.acceptedState.version — or its term is ZEN1_BWC_TERM (0), about which nothing more is stated: this disjunct holds for every term-0 state (the handler accepts a term-0 state that is not newer only in its Zen1 compatibility branch, when that state names a cluster-manager and the last accepted state names none or a different one; the statement does not record this condition);
  • the join votes, electionWon, startedJoinSinceLastReboot, lastPublishedVersion, lastPublishedConfiguration and the publish votes are those of cs.

The hypothesis on cs is the first assertion of invariant(); without it, a node whose accepted term exceeds its current term would accept a state of a lower term.

Preamble
import Definitions.Def_OpenSearchCoordination
Formal statement
theorem OpenSearchCoordination.handlePublishRequest_spec {V : Type} (cs : CoordinationState V) (req : PublishRequest V) (cs' : CoordinationState V)
    (resp : PublishResponse) (hcs : cs.lastAcceptedTerm ≤ cs.currentTerm)
    (h : cs.handlePublishRequest req = .ok (cs', resp)) :
    cs'.lastAcceptedState = req.acceptedState ∧ req.acceptedState.term = cs.currentTerm ∧
    cs'.currentTerm = cs.currentTerm ∧ cs'.localNode = cs.localNode ∧
    resp = ⟨req.acceptedState.term, req.acceptedState.version⟩ ∧
    (cs.lastAcceptedTerm < req.acceptedState.term ∨
      (cs.lastAcceptedTerm = req.acceptedState.term ∧ cs.lastAcceptedVersion < req.acceptedState.version) ∨
      req.acceptedState.term = ZEN1_BWC_TERM) ∧
    cs'.joinVotes = cs.joinVotes ∧ cs'.electionWon = cs.electionWon ∧
    cs'.startedJoinSinceLastReboot = cs.startedJoinSinceLastReboot ∧
    cs'.lastPublishedVersion = cs.lastPublishedVersion ∧
    cs'.lastPublishedConfiguration = cs.lastPublishedConfiguration ∧ cs'.publishVotes = cs.publishVotes := 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.handlePublishRequest_spec

Notions used

Coordination states and cluster states. For a payload type VVV, a coordination state cscscs has nine fields:

  • cs.localNodecs.\mathrm{localNode}cs.localNode: a node;
  • cs.currentTerm∈Ncs.\mathrm{currentTerm} \in \mathbb{N}cs.currentTerm∈N;
  • cs.lastAcceptedStatecs.\mathrm{lastAcceptedState}cs.lastAcceptedState: a cluster state;
  • cs.joinVotescs.\mathrm{joinVotes}cs.joinVotes and cs.publishVotescs.\mathrm{publishVotes}cs.publishVotes: vote collections;
  • cs.startedJoinSinceLastRebootcs.\mathrm{startedJoinSinceLastReboot}cs.startedJoinSinceLastReboot and cs.electionWoncs.\mathrm{electionWon}cs.electionWon: Booleans;
  • cs.lastPublishedVersion∈Zcs.\mathrm{lastPublishedVersion} \in \mathbb{Z}cs.lastPublishedVersion∈Z;
  • cs.lastPublishedConfigurationcs.\mathrm{lastPublishedConfiguration}cs.lastPublishedConfiguration: a voting configuration.

A cluster state SSS has nine independent fields:

  • S.term∈NS.\mathrm{term} \in \mathbb{N}S.term∈N;
  • S.version∈ZS.\mathrm{version} \in \mathbb{Z}S.version∈Z and S.metadataVersion∈ZS.\mathrm{metadataVersion} \in \mathbb{Z}S.metadataVersion∈Z;
  • two voting configurations, S.lastCommittedConfigurationS.\mathrm{lastCommittedConfiguration}S.lastCommittedConfiguration and S.lastAcceptedConfigurationS.\mathrm{lastAcceptedConfiguration}S.lastAcceptedConfiguration;
  • S.clusterManagerNodeS.\mathrm{clusterManagerNode}S.clusterManagerNode, an optional natural (an ephemeral id);
  • two Booleans about the cluster UUID;
  • a payload S.value∈VS.\mathrm{value} \in VS.value∈V.

Abbreviations:

  • lat(cs)=cs.lastAcceptedState.term\mathrm{lat}(cs) = cs.\mathrm{lastAcceptedState}.\mathrm{term}lat(cs)=cs.lastAcceptedState.term (lastAcceptedTerm);
  • lav(cs)=cs.lastAcceptedState.version\mathrm{lav}(cs) = cs.\mathrm{lastAcceptedState}.\mathrm{version}lav(cs)=cs.lastAcceptedState.version (lastAcceptedVersion).

ZEN1_BWC_TERM=0\mathrm{ZEN1\_BWC\_TERM} = 0ZEN1_BWC_TERM=0.

Messages. A publish request RRR carries one cluster state R.acceptedStateR.\mathrm{acceptedState}R.acceptedState. A publish response is a pair ⟨term∈N,version∈Z⟩\langle \mathrm{term} \in \mathbb{N}, \mathrm{version} \in \mathbb{Z}\rangle⟨term∈N,version∈Z⟩.

The handler handlePublishRequest(cs,R)\mathrm{handlePublishRequest}(cs, R)handlePublishRequest(cs,R), with S=R.acceptedStateS = R.\mathrm{acceptedState}S=R.acceptedState. Let accept=ok(cs with lastAcceptedState:=S, ⟨S.term,S.version⟩)\mathit{accept} = \mathrm{ok}(cs \text{ with } \mathrm{lastAcceptedState} := S,\ \langle S.\mathrm{term}, S.\mathrm{version}\rangle)accept=ok(cs with lastAcceptedState:=S, ⟨S.term,S.version⟩). The handler proceeds as follows:

  1. If S.term≠cs.currentTermS.\mathrm{term} \ne cs.\mathrm{currentTerm}S.term=cs.currentTerm, it returns error\mathrm{error}error.
  2. Else, if S.term=lat(cs)S.\mathrm{term} = \mathrm{lat}(cs)S.term=lat(cs) and S.version≤lav(cs)S.\mathrm{version} \le \mathrm{lav}(cs)S.version≤lav(cs):
    • if S.term=0S.\mathrm{term} = 0S.term=0:
      • if S.clusterManagerNode=noneS.\mathrm{clusterManagerNode} = \mathrm{none}S.clusterManagerNode=none, it returns error\mathrm{error}error;
      • if S.clusterManagerNode=some mS.\mathrm{clusterManagerNode} = \mathrm{some}\ mS.clusterManagerNode=some m, it returns accept\mathit{accept}accept when some m≠cs.lastAcceptedState.clusterManagerNode\mathrm{some}\ m \ne cs.\mathrm{lastAcceptedState}.\mathrm{clusterManagerNode}some m=cs.lastAcceptedState.clusterManagerNode, and error\mathrm{error}error otherwise;
    • otherwise, it returns error\mathrm{error}error.
  3. Else, it returns accept\mathit{accept}accept.

1. Declaration

Binders.

  • VVV (implicit);
  • cscscs: a coordination state;
  • RRR (req): a publish request;
  • cs′cs'cs′: a coordination state;
  • resp\mathit{resp}resp: a publish response.

Write S=R.acceptedStateS = R.\mathrm{acceptedState}S=R.acceptedState.

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: handlePublishRequest(cs,R)=ok(cs′,resp)\mathrm{handlePublishRequest}(cs, R) = \mathrm{ok}(cs', \mathit{resp})handlePublishRequest(cs,R)=ok(cs′,resp).

Conclusion. The conjunction of:

  1. cs′.lastAcceptedState=Scs'.\mathrm{lastAcceptedState} = Scs′.lastAcceptedState=S;
  2. S.term=cs.currentTermS.\mathrm{term} = cs.\mathrm{currentTerm}S.term=cs.currentTerm;
  3. cs′.currentTerm=cs.currentTermcs'.\mathrm{currentTerm} = cs.\mathrm{currentTerm}cs′.currentTerm=cs.currentTerm;
  4. cs′.localNode=cs.localNodecs'.\mathrm{localNode} = cs.\mathrm{localNode}cs′.localNode=cs.localNode;
  5. resp=⟨S.term,S.version⟩\mathit{resp} = \langle S.\mathrm{term}, S.\mathrm{version}\rangleresp=⟨S.term,S.version⟩;
  6. lat(cs)<S.term  ∨  (lat(cs)=S.term∧lav(cs)<S.version)  ∨  S.term=ZEN1_BWC_TERM (=0)\mathrm{lat}(cs) < S.\mathrm{term}\ \ \vee\ \ \big(\mathrm{lat}(cs) = S.\mathrm{term} \wedge \mathrm{lav}(cs) < S.\mathrm{version}\big)\ \ \vee\ \ S.\mathrm{term} = \mathrm{ZEN1\_BWC\_TERM}\ (=0)lat(cs)<S.term  ∨  (lat(cs)=S.term∧lav(cs)<S.version)  ∨  S.term=ZEN1_BWC_TERM (=0);
  7. cs′.joinVotes=cs.joinVotescs'.\mathrm{joinVotes} = cs.\mathrm{joinVotes}cs′.joinVotes=cs.joinVotes;
  8. cs′.electionWon=cs.electionWoncs'.\mathrm{electionWon} = cs.\mathrm{electionWon}cs′.electionWon=cs.electionWon;
  9. cs′.startedJoinSinceLastReboot=cs.startedJoinSinceLastRebootcs'.\mathrm{startedJoinSinceLastReboot} = cs.\mathrm{startedJoinSinceLastReboot}cs′.startedJoinSinceLastReboot=cs.startedJoinSinceLastReboot;
  10. cs′.lastPublishedVersion=cs.lastPublishedVersioncs'.\mathrm{lastPublishedVersion} = cs.\mathrm{lastPublishedVersion}cs′.lastPublishedVersion=cs.lastPublishedVersion;
  11. cs′.lastPublishedConfiguration=cs.lastPublishedConfigurationcs'.\mathrm{lastPublishedConfiguration} = cs.\mathrm{lastPublishedConfiguration}cs′.lastPublishedConfiguration=cs.lastPublishedConfiguration;
  12. cs′.publishVotes=cs.publishVotescs'.\mathrm{publishVotes} = cs.\mathrm{publishVotes}cs′.publishVotes=cs.publishVotes.

Conjuncts 1, 3, 4 and 7–12 fix all nine fields of cs′cs'cs′: the accepted state is replaced by SSS and nothing else changes. Conjunct 5 fixes the response.

2. What is not constrained

  • Only one direction. The statement is an implication from success. It does not say that requests satisfying conjuncts 2 and 6 are accepted.
  • Conjunct 6 is weaker than the handler's real acceptance condition. Its third alternative, S.term=0S.\mathrm{term} = 0S.term=0, holds for every term-0 request. So for term-0 requests conjunct 6 constrains nothing.
    • It omits the Zen1-branch condition: an incoming cluster manager some m\mathrm{some}\ msome m that differs from the stored one.
    • It allows a term-0 state with a version lower than or equal to the current one.
  • The role of hcs\mathit{hcs}hcs. hcs\mathit{hcs}hcs is what makes conjunct 6 hold.
    • Without it, a state with lat(cs)>cs.currentTerm\mathrm{lat}(cs) > cs.\mathrm{currentTerm}lat(cs)>cs.currentTerm would accept a request with S.term=cs.currentTerm<lat(cs)S.\mathrm{term} = cs.\mathrm{currentTerm} < \mathrm{lat}(cs)S.term=cs.currentTerm<lat(cs) and S.term≠0S.\mathrm{term} \ne 0S.term=0. That request satisfies none of the three alternatives.
    • Given hcs\mathit{hcs}hcs and conjunct 2, the first alternative is equivalent to S.term≠lat(cs)S.\mathrm{term} \ne \mathrm{lat}(cs)S.term=lat(cs).
    • hcs\mathit{hcs}hcs is satisfiable, so the statement is not vacuous. For example, any state with lat(cs)<cs.currentTerm\mathrm{lat}(cs) < cs.\mathrm{currentTerm}lat(cs)<cs.currentTerm accepts any SSS with S.term=cs.currentTermS.\mathrm{term} = cs.\mathrm{currentTerm}S.term=cs.currentTerm.
  • The rest of SSS is unconstrained. Its configurations (including the committed one), metadataVersion\mathrm{metadataVersion}metadataVersion, clusterManagerNode\mathrm{clusterManagerNode}clusterManagerNode, UUID flags and payload are free. Accepting a publish may therefore replace the configurations arbitrarily.
  • electionWon\mathrm{electionWon}electionWon is carried over unchanged (conjunct 8). The election-quorum test depends on the accepted state's configurations, version and term, so the stored flag may stop matching that test. See javaInvariant_not_local.
  • cscscs's other fields are unconstrained. Only hcs\mathit{hcs}hcs is assumed.

3. Plain-language summary

Suppose a node whose last-accepted term does not exceed its current term accepts a publish request. Then:

  • the published state is in the node's current term and becomes its new last-accepted state;
  • nothing else in the node changes;
  • the response echoes that state's term and version;
  • the accepted state is strictly newer than the old one in (term, version) order, except when its term is 000 (Zen1 compatibility), where nothing is claimed.
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