Only handleStartJoin changes the current term, and every handler keeps the accepted term at most the current term
ProvedOpenSearchCoordination.lastAcceptedTerm_le_currentTermFor every election strategy es and coordination state cs with cs.lastAcceptedTerm ≤ cs.currentTerm, every successful handler call on cs — for setInitialState s, one with s.term = 0, one of the method's asserted preconditions (a conjunct of initialStateContract, the only one assumed) — yields a state cs' with cs'.lastAcceptedTerm ≤ cs'.currentTerm, and moreover:
cs.setInitialState s = .ok cs'withs.term = 0leaves the current term unchanged;cs.handleStartJoin r = .ok (cs', j)strictly increases it:cs.currentTerm < cs'.currentTerm;cs.handleJoin es j,cs.handleClientValue s,cs.handlePublishRequest p,cs.handlePublishResponse n randcs.handleCommit c, when they succeed, leave it unchanged.
So the first assertion of invariant(), getLastAcceptedTerm() <= getCurrentTerm(), is preserved by one successful call of any handler, and along successful calls on one node that start from a state satisfying it (with term-0 states for setInitialState) the current term changes only at handleStartJoin, upwards. The statement is about single steps; it does not mention init, whose result satisfies the inequality exactly when s.term ≤ t (the hypothesis of init_javaInvariant).
import Definitions.Def_OpenSearchCoordination
theorem OpenSearchCoordination.lastAcceptedTerm_le_currentTerm {V : Type} (es : ElectionStrategy) (cs : CoordinationState V)
(hcs : cs.lastAcceptedTerm ≤ cs.currentTerm) :
(∀ s cs', cs.setInitialState s = .ok cs' → s.term = 0 → cs'.lastAcceptedTerm ≤ cs'.currentTerm ∧
cs'.currentTerm = cs.currentTerm) ∧
(∀ r cs' j, cs.handleStartJoin r = .ok (cs', j) → cs'.lastAcceptedTerm ≤ cs'.currentTerm ∧
cs.currentTerm < cs'.currentTerm) ∧
(∀ j cs' b, cs.handleJoin es j = .ok (cs', b) → cs'.lastAcceptedTerm ≤ cs'.currentTerm ∧
cs'.currentTerm = cs.currentTerm) ∧
(∀ s cs' p, cs.handleClientValue s = .ok (cs', p) → cs'.lastAcceptedTerm ≤ cs'.currentTerm ∧
cs'.currentTerm = cs.currentTerm) ∧
(∀ p cs' r, cs.handlePublishRequest p = .ok (cs', r) → cs'.lastAcceptedTerm ≤ cs'.currentTerm ∧
cs'.currentTerm = cs.currentTerm) ∧
(∀ n r cs' o, cs.handlePublishResponse n r = .ok (cs', o) → cs'.lastAcceptedTerm ≤ cs'.currentTerm ∧
cs'.currentTerm = cs.currentTerm) ∧
(∀ c cs', cs.handleCommit c = .ok cs' → cs'.lastAcceptedTerm ≤ cs'.currentTerm ∧
cs'.currentTerm = cs.currentTerm) := by sorryRead-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.lastAcceptedTerm_le_currentTerm
Notions used
Coordination states. A coordination state over a payload type has nine fields:
- localNode;
- ;
- lastAcceptedState, a cluster state with a term , a version , two voting configurations, and further fields;
- joinVotes;
- startedJoinSinceLastReboot;
- electionWon;
- lastPublishedVersion;
- lastPublishedConfiguration;
- publishVotes.
Abbreviations:
- ;
- ;
- = the accepted state's last accepted configuration.
The seven handlers. Here is what each one does to and when it returns ; their other effects do not matter for this statement.
- succeeds iff is empty. The result is with . Nothing about is checked, in particular not .
- succeeds iff . The result's is , and is unchanged. A join is also returned.
- leaves both fields unchanged. It changes only votes, the won flag and the published version. A Boolean is also returned.
- leaves both fields unchanged. It changes the published version and configuration and the publish votes. A publish request is also returned.
- succeeds only if . The result is with . A publish response is also returned.
- leaves both fields unchanged. It changes only the publish votes. An optional commit request is also returned.
- replaces by of it. That operation changes only the committed configuration and a UUID flag; the term is unchanged. is also unchanged.
1. Declaration
Binders.
- (implicit);
- : an election strategy, an arbitrary Boolean function used inside
handleJoin; - : a coordination state.
Hypothesis. : .
Conclusion. A conjunction of seven clauses, one per handler:
- .
- .
- .
- (the same two facts as in 3).
- (the same).
- (the same).
- (the same).
Each clause says two things:
- One successful step of that handler from yields a state whose last-accepted term is at most its current term.
- The current term strictly increases (clause 2) or is unchanged (all other clauses).
2. What is not constrained
- Clause 1 has its own extra hypothesis, . This is the only part of Java's
setInitialStateassertions (initialStateContract) that is used.setInitialStatedoes not check it, so without it the clause could fail: would be accepted. Clause 1 does not need . - This is one-step preservation, not an invariant. The name suggests an invariant, but the content is preservation by a single step from any state satisfying .
- The statement does not mention
init. Separately,init(n, t, S)satisfies the inequality only when . - It says nothing about sequences of steps or reachability.
- The statement does not mention
- matters only for clause 3.
- Clause 5 claims less than holds. It states only , but in fact .
- No other fields are mentioned.
- Each clause's antecedent is satisfiable, so the statement is not vacuous. If a handler fails on some input, that clause is vacuous for that input.
3. Plain-language summary
Starting from any coordination state whose last-accepted term is at most its current term, each of the seven handlers, when it succeeds, produces a state with the same property. handleStartJoin strictly increases the current term, and every other handler leaves it unchanged. For setInitialState this is claimed only for initial states of term .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.