Skip to content

feat(Distributed): formalize notions of consistency for replicated data types and prove their relationships - #987

Open
ctchou wants to merge 11 commits into
leanprover:mainfrom
ctchou:replicated-consistency
Open

ctchou wants to merge 11 commits into
leanprover:mainfrom
ctchou:replicated-consistency

Conversation

@ctchou

@ctchou ctchou commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

This PR formalizes several notions of consistency for replicated data types and proves a hierarchy theorem for them:

Linearizability → SequentialConsistency → CausalConsistency → BasicEventualConsistency

The main reference is the book "Principles of eventual consistency" by Sebastian Burckhardt (which is freely downloadable; see the URL in the reference).

The proofs of causalVisibility_imp_readMyWrites and causalVisibility_imp_monotonicReads are constructed by Claude (Opus 5.5). But all definitions, theorem statements, and comments are human-written.

@SamuelSchlesinger SamuelSchlesinger changed the title feat[Distributed]: formalize notions of consistency for replicated data types and prove their relationships feat(Distributed): formalize notions of consistency for replicated data types and prove their relationships Sep 29, 2026
@ctchou ctchou changed the title feat(Distributed): formalize notions of consistency for replicated data types and prove their relationships feat: formalize notions of consistency for replicated data types and prove their relationships Sep 29, 2026
@ctchou
ctchou force-pushed the replicated-consistency branch from 9e9e2e4 to a0084df Compare September 29, 2026 19:04
@ctchou ctchou changed the title feat: formalize notions of consistency for replicated data types and prove their relationships feat(Distributed): formalize notions of consistency for replicated data types and prove their relationships Sep 29, 2026
@ctchou
ctchou requested a review from crei as a code owner September 30, 2026 17:16

/-- The `happens before` order is the per-session transitive closure of the union of
the `so` and `vis` orders. -/
def hb (a : AbstractExecution Event Operation Value Session)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I understanding correctly that hb should include session-order edges from all sessions before taking the transitive closure? I wonder if fixing a single session here can miss cycles that alternate between sessions. For example, session edges 0 → 1 and 2 → 3, together with visibility edges 1 → 2 and 3 → 0, seem to form a global cycle even though each individual hb s is acyclic. Would it make sense to use (∃ s, a.so s x y) ∨ a.vis x y as the generating relation instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not the job of this definition to impose constraints on either so or vis. It is the job of other, Prop-valued definitions to do that. For example, the next three definitions all have the effect of making "hb" acyclic.


/-- An `OperationContext` is the data used by a replicated data type to determine the
return value of an operation. It is an abstraction of the notion of states. -/
structure OperationContext (Event Operation : Type*) where

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something, but should OperationContext also carry the validity conditions from Definition 4.4: finiteness of events, acyclicity of vis, and a strict total order for ar on those events? My concern is that ReadOnlyOp currently quantifies over arbitrary contexts, so an RDT could distinguish infinite or otherwise invalid contexts. Would it make sense to enforce those conditions here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way OperationContext will be constructed is via the AbstractExecution.context function below, which inherits the constraints of an AbstractExecution such as acyclicity. Note that the only use of AbstractExecution.context is in RVal, which will ensure that the set of events is finite. (There is another use of AbstractExecution.context in a proof which is unfortunately incorrect and hence will not be formalized. Even there the set of events will be finite.). Note that I do take care in the definition of OperationContext.Equiv below to say that two contexts are equivalent when there is an isomorphism between the two and in ReplicatedDataType to say that its rval function cannot distinguish between equivalent contexts.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, perhaps we should drop ReadOnlyOp altogether. It is used only in the definition of QuiescentConsistency, which is too weak a consistency condition to be of any practical value. And we know that BasicEventualConsistency => QuiescentConsistency is not true anyway, so no interesting formal theory is lost by dropping QuiescentConsistency.

Comment thread Cslib/Foundations/Relation/Defs.lean
@ctchou

ctchou commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

@SamuelSchlesinger Any further comments? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants