Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

handleCommit only marks the last accepted state committed

Proved
OpenSearchCoordination.handleCommit_spec

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

cluster-coordinationconsensuscoordination-stateelasticsearchformal-verificationleader-electionopensearchpaxosquorumraftzen2

For every coordination state cs, commit request c and state cs': if cs.handleCommit c = .ok cs' then

  • the commit is for the last accepted state in the current term: c.term = cs.currentTerm, c.term = cs.lastAcceptedTerm and c.version = cs.lastAcceptedVersion;
  • cs' is cs with its last accepted state replaced by cs.lastAcceptedState.markCommitted (the committed configuration becomes the accepted one, and a known cluster UUID is marked committed);
  • in cs' the last committed configuration equals the last accepted configuration (the assertion at CoordinationState.java:572);
  • the last accepted configuration, term, version and payload of cs' are those of cs.
Preamble
import Definitions.Def_OpenSearchCoordination
Formal statement
theorem OpenSearchCoordination.handleCommit_spec {V : Type} (cs : CoordinationState V) (c : ApplyCommitRequest) (cs' : CoordinationState V)
    (h : cs.handleCommit c = .ok cs') :
    c.term = cs.currentTerm ∧ c.term = cs.lastAcceptedTerm ∧ c.version = cs.lastAcceptedVersion ∧
    cs' = { cs with lastAcceptedState := cs.lastAcceptedState.markCommitted } ∧
    cs'.lastCommittedConfiguration = cs'.lastAcceptedConfiguration ∧
    cs'.lastAcceptedConfiguration = cs.lastAcceptedConfiguration ∧
    cs'.lastAcceptedTerm = cs.lastAcceptedTerm ∧ cs'.lastAcceptedVersion = cs.lastAcceptedVersion ∧
    cs'.lastAcceptedState.value = cs.lastAcceptedState.value := 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.handleCommit_spec

Notions used

Coordination states and cluster states. A coordination state cscscs has nine fields: localNode, currentTerm ∈N\in\mathbb{N}∈N, lastAcceptedState, joinVotes, startedJoinSinceLastReboot, electionWon, lastPublishedVersion ∈Z\in\mathbb{Z}∈Z, lastPublishedConfiguration and publishVotes.

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;
  • two Booleans, S.clusterUUIDKnownS.\mathrm{clusterUUIDKnown}S.clusterUUIDKnown and S.clusterUUIDCommittedS.\mathrm{clusterUUIDCommitted}S.clusterUUIDCommitted;
  • a payload S.valueS.\mathrm{value}S.value.

Abbreviations, read from cs.lastAcceptedStatecs.\mathrm{lastAcceptedState}cs.lastAcceptedState:

  • lat(cs)\mathrm{lat}(cs)lat(cs) = its term;
  • lav(cs)\mathrm{lav}(cs)lav(cs) = its version;
  • C(cs)\mathrm{C}(cs)C(cs) = its last committed configuration;
  • A(cs)\mathrm{A}(cs)A(cs) = its last accepted configuration.

Marking committed. markCommitted(S)\mathrm{markCommitted}(S)markCommitted(S) works in two steps:

  1. If the two configurations differ, set the committed configuration to the accepted one.
  2. If clusterUUIDKnown=true\mathrm{clusterUUIDKnown} = \mathrm{true}clusterUUIDKnown=true and clusterUUIDCommitted=false\mathrm{clusterUUIDCommitted} = \mathrm{false}clusterUUIDCommitted=false, set clusterUUIDCommitted:=true\mathrm{clusterUUIDCommitted} := \mathrm{true}clusterUUIDCommitted:=true.

The net effect: the committed configuration becomes the accepted configuration, and clusterUUIDCommitted\mathrm{clusterUUIDCommitted}clusterUUIDCommitted becomes clusterUUIDCommitted∨clusterUUIDKnown\mathrm{clusterUUIDCommitted} \vee \mathrm{clusterUUIDKnown}clusterUUIDCommitted∨clusterUUIDKnown. The other seven fields are unchanged.

Messages. A commit request ccc has a node c.sourceNodec.\mathrm{sourceNode}c.sourceNode, a term c.term∈Nc.\mathrm{term} \in \mathbb{N}c.term∈N and a version c.version∈Zc.\mathrm{version} \in \mathbb{Z}c.version∈Z.

The handler handleCommit(cs,c)\mathrm{handleCommit}(cs, c)handleCommit(cs,c) checks three guards in order:

  1. If c.term≠cs.currentTermc.\mathrm{term} \ne cs.\mathrm{currentTerm}c.term=cs.currentTerm, it returns error\mathrm{error}error.
  2. If c.term≠lat(cs)c.\mathrm{term} \ne \mathrm{lat}(cs)c.term=lat(cs), it returns error\mathrm{error}error.
  3. If c.version≠lav(cs)c.\mathrm{version} \ne \mathrm{lav}(cs)c.version=lav(cs), it returns error\mathrm{error}error.

Otherwise it returns ok(cs with lastAcceptedState:=markCommitted(cs.lastAcceptedState))\mathrm{ok}(cs \text{ with } \mathrm{lastAcceptedState} := \mathrm{markCommitted}(cs.\mathrm{lastAcceptedState}))ok(cs with lastAcceptedState:=markCommitted(cs.lastAcceptedState)).

1. Declaration

Binders. VVV (implicit), cscscs, ccc (a commit request), cs′cs'cs′.

Hypothesis. hhh: handleCommit(cs,c)=ok(cs′)\mathrm{handleCommit}(cs, c) = \mathrm{ok}(cs')handleCommit(cs,c)=ok(cs′).

Conclusion. The conjunction of:

  1. c.term=cs.currentTermc.\mathrm{term} = cs.\mathrm{currentTerm}c.term=cs.currentTerm;
  2. c.term=lat(cs)c.\mathrm{term} = \mathrm{lat}(cs)c.term=lat(cs);
  3. c.version=lav(cs)c.\mathrm{version} = \mathrm{lav}(cs)c.version=lav(cs);
  4. cs′=cs with lastAcceptedState:=markCommitted(cs.lastAcceptedState)cs' = cs \text{ with } \mathrm{lastAcceptedState} := \mathrm{markCommitted}(cs.\mathrm{lastAcceptedState})cs′=cs with lastAcceptedState:=markCommitted(cs.lastAcceptedState);
  5. C(cs′)=A(cs′)\mathrm{C}(cs') = \mathrm{A}(cs')C(cs′)=A(cs′);
  6. A(cs′)=A(cs)\mathrm{A}(cs') = \mathrm{A}(cs)A(cs′)=A(cs);
  7. lat(cs′)=lat(cs)\mathrm{lat}(cs') = \mathrm{lat}(cs)lat(cs′)=lat(cs);
  8. lav(cs′)=lav(cs)\mathrm{lav}(cs') = \mathrm{lav}(cs)lav(cs′)=lav(cs);
  9. cs′.lastAcceptedState.value=cs.lastAcceptedState.valuecs'.\mathrm{lastAcceptedState}.\mathrm{value} = cs.\mathrm{lastAcceptedState}.\mathrm{value}cs′.lastAcceptedState.value=cs.lastAcceptedState.value.

Conjunct 4 determines cs′cs'cs′ completely. Conjuncts 5–9 spell out consequences of it. Conjuncts 1 and 2 together give cs.currentTerm=lat(cs)cs.\mathrm{currentTerm} = \mathrm{lat}(cs)cs.currentTerm=lat(cs): a commit is applied only when the node's last-accepted term equals its current term.

2. What is not constrained

  • c.sourceNodec.\mathrm{sourceNode}c.sourceNode is never mentioned. The handler does not read it.
  • Some effects of markCommitted\mathrm{markCommitted}markCommitted are implied only through conjunct 4 and are not stated separately:
    • the update of clusterUUIDCommitted\mathrm{clusterUUIDCommitted}clusterUUIDCommitted;
    • the preservation of metadataVersion\mathrm{metadataVersion}metadataVersion, clusterManagerNode\mathrm{clusterManagerNode}clusterManagerNode and clusterUUIDKnown\mathrm{clusterUUIDKnown}clusterUUIDKnown.
  • The statement goes in one direction only: from success to the listed facts.
  • No hypothesis beyond success is assumed. No invariant on cscscs is needed or used.
  • The statement is not vacuous: any cscscs with cs.currentTerm=lat(cs)cs.\mathrm{currentTerm} = \mathrm{lat}(cs)cs.currentTerm=lat(cs) and c=⟨_,lat(cs),lav(cs)⟩c = \langle \_, \mathrm{lat}(cs), \mathrm{lav}(cs)\ranglec=⟨_,lat(cs),lav(cs)⟩ succeeds.

3. Plain-language summary

A commit is applied only when its term equals both the node's current term and its last-accepted term, and its version equals the last-accepted version. Applying it only marks the last-accepted state as committed:

  • the committed configuration becomes the accepted configuration;
  • a known cluster UUID is flagged committed;
  • the term, version, accepted configuration and payload are unchanged.
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