Unit 2 of 15 · about 4 hours · derive

Safety invariants, liveness properties and fairness assumptions

Safety without liveness accepts a system that does nothing; liveness without fairness blames the protocol for a starved scheduler. The alternating-bit protocol is the smallest system where both halves bite.

You'll be able to

  • Separate a delivery claim into its safety half (nothing bad happens) and its liveness half (something good eventually happens).
  • Name the fairness assumption each liveness claim needs, and say which starvation it rules out.
  • Predict whether TLC can check a claim on a finite model, and what must be added when it cannot.

Covers

Safety invariantsLiveness properties and fairness assumptions
1

Read

In this order, only the parts listed

0 of 3 done

  1. Lecture 8 part 1: temporal formulasTLA+ Video Course

    Full part (15:53): temporal formulas and what implementation will mean

  2. Lecture 9 part 1: the high-level alternating-bit specTLA+ Video Course

    Full part (20:51): ABSpec.tla in video9a.zip, with FairSpec == Spec /\ WF_vars(Next) and the Inv invariant

    Download video9a.zip from the lecture page for ABSpec.tla; read it beside the video, not instead of it.

  3. Lecture 9 part 2: the protocol and its fairnessTLA+ Video Course

    Full part (18:45): AB.tla in video9b.zip, with Next == ASnd \/ ARcv \/ BSnd \/ BRcv \/ LoseMsg and FairSpec adding SF_vars(ARcv), SF_vars(BRcv), WF_vars(ASnd), WF_vars(BSnd)

    Read the lecture 9 part 2 entry on the corrections page (https://lamport.azurewebsites.net/video/corrections.html) for where the Toolbox now sets the state constraint.

2

Focus on

  • A safety violation has a finite bad prefix. Liveness concerns infinite behaviors; TLC checks it on a finite state graph, and fairness belongs in the spec only when it is a justified assumption of the claim.
  • Fairness constrains the scheduler, not the algorithm. WF_vars(ASnd) says a persistently enabled send keeps happening; SF_vars(ARcv) says a repeatedly enabled receive keeps happening.
  • Loss is an action like any other. LoseMsg is enabled whenever a queue holds a message, so delivery depends on repeated sends plus fair receives, not on the absence of loss.
  • The two specs separate concerns: ABSpec states what delivery means, AB states how retransmission with alternating bits achieves it under fairness.
Common mistakes · 3
  • Adding fairness to silence a liveness violation without reading the trace. If the violating behavior is already fair, the protocol is wrong and fairness hides nothing.
  • Writing a liveness claim as a state predicate. BVar = AVar holds or not at a state; eventual delivery is a claim about the whole behavior.
  • Checking liveness with unbounded queues. AtoB and BtoA grow without bound, so TLC needs a queue-length constraint before it can finish.
3

Try it yourself

Closed-book, before checking anything

Closed-book, write the AB Next disjunction and the four fairness conjuncts of its FairSpec from memory, and explain which starvation each conjunct rules out.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Split every sent value is eventually received, and no value is received twice into safety and liveness.Answer

    No-duplicates is safety: one duplicated delivery in a finite prefix violates it. Eventual receipt is liveness: no finite prefix can show a value is never delivered.

  2. 2.What does FairSpec add over Spec in AB.tla, and why?Answer

    Four fairness conjuncts: strong fairness on the two receives and weak fairness on the two sends. They rule out behaviors where an enabled send or receive is starved forever, which liveness needs.

  3. 3.TLC reports a liveness violation whose trace shows the sender never sending. Is the protocol broken?Answer

    Not shown. The behavior starves ASnd; add WF_vars(ASnd) first. Only a violation of the fair spec indicts the protocol.

  4. 4.Why do the AB model runs need a queue-length bound such as Len(AtoB) <= 3?Answer

    The message queues are unbounded sequences, so the state space is infinite. The bound makes the model finite; results hold only within it.

5

Practice

  • TLA+ Video Course Lecture 9: check the alternating-bit spec with TLC

    Check TypeOK on Spec with Data = {d1, d2} and both queues bounded at 3 (with deadlock checking off, TLC 2.19 finds 480 distinct states at depth 15). Then state a temporal delivery property, predict the starvation that removing one fairness conjunct permits, and check that property on a bounded model whose boundary behavior you have justified

    Do the removal as a prediction first, then run. Keep the temporal counterexample if one appears.

You're done when

You classify three claims as safety or liveness, attach the fairness each liveness claim needs, and reproduce the AB Next plus its four fairness conjuncts without notes.

Only when you can do this without notes.

Leads to

Notes

Resources · 1 for this unit, 14 more in the section
  • TLA+ Video CourseLeslie Lamport · primary

    Complete lectures 1 to 10 (lectures 8, 9 and 10 have two parts each) and check the corrections page, while specifying a reduced transaction, workflow or replicated-log model from the capstone. Run TLC after every extension, report the model bounds with every result, and retain the first meaningful counterexample rather than polishing only the final model.

Also in this section

  • TLA+ ExamplesTLA+ Foundation · support

    Check specifications/transaction_commit/ (TCommit.tla, TwoPhase.tla, PaxosCommit.tla with their .cfg files) with TLC alongside the lectures, and read the Paxos specifications for depth. specifications/TwoPhase/ is a hardware handshake, not transaction commit.

  • Cambridge Concurrent and Distributed Systems Notes (Kleppmann) - CRDTs and CollaborationUniversity of Cambridge (Martin Kleppmann) · support

    Use Section 8.1 (operation-based and state-based CRDTs, operational transformation) for the CRDT unit, and work Exercise 21 (prove the operation-based map CRDT converges) and Exercise 22 (its multi-value variant).

  • A Comprehensive Study of Convergent and Commutative Replicated Data Types (Shapiro et al., 2011)INRIA report (Berkeley course copy) · support

    Read Sections 1 to 3 (state-based and operation-based definitions, the semilattice and delivery conditions) and one example type for your implementation, not the whole catalog.

  • Learn TLA+Hillel Wayne · support

    Use the core lessons and the examples as a second explanation when a lecture stalls, and as the PlusCal reference if you write algorithms rather than raw actions.

  • Hypothesis - Stateful TestingHypothesis · required

    Use RuleBasedStateMachine against a reference model for property-based state-machine tests of your extension, keep the failing seeds and shrunk examples, and plant a bug to show the machine detects it.

  • MIT 6.5840 - Verification Lecture and Final ProjectMIT PDOS · required

    Study the Spring 2026 verification lecture and IronFleet reading, then use the final-project guidance to frame a bounded real-system extension, evaluation and report. Course grading and staff review are unavailable to self-study, so use the roadmap defense rubric.

  • Jepsen - Consistency Models and AnalysesJepsen · required

    Use the framework's generator, client, nemesis and checker roles to design the campaign, Knossos for single-register linearizability and Elle for transactional anomalies on recorded histories, and the public analyses for fault models. A simplified local checker must declare its object, model and completeness limits.

  • Elle: Inferring Isolation Anomalies from Experimental Observations (Kingsbury and Alvaro)arXiv · required

    Read how Elle infers version orders from list-append and register histories and detects cycles for G0 to G2. It needs complete histories, and a clean run is not a proof of serializability.

  • How Amazon Web Services Uses Formal Methods (Newcombe et al., 2015)Amazon Science · support

    Read it for why industrial teams specify designs in TLA+ and which bugs model checking found that testing missed. Its effort figures are anecdotes, not benchmarks.

  • FoundationDB: A Distributed Unbundled Transactional Key Value Store (Zhou et al., 2021)FoundationDB · support

    Read the simulation-testing section (deterministic single-threaded simulation, fault injection, seed replay) as the model for your own scheduler, and the architecture for unbundled transactions.

  • DDIA 2e - Chapters 9, 10 and 14 ReviewMartin Kleppmann and Chris Riccomini · required

    Revisit uncertainty, consistency, consensus and responsible system design while extracting the final contract. Use the book to challenge assumptions and alternatives, not to replace executable evidence.

  • HLD Handbook - CRDTs, Multi-Region and Architecture Trade-offsHLD Handbook · support

    Read the CRDT, multi-region, distributed SQL and relevant case-study chapters only after the formal core passes. Use its design prompts to prepare the final comparison and defense.

  • CMU 15-721 - Selected Advanced Database Systems UnitsCarnegie Mellon Database Group · depth

    Select at most one lecture group that informs your extension: #02 and #03 (data formats and encoding), #08 (scheduling and coordination) or #17 to #22 (system analyses such as BigQuery, Databricks, Snowflake, DuckDB and Redshift), with their papers. The course project needs a group, cloud credits and staff sign-off, so there is no runnable self-study project.

  • Replicated Log and Stream Processor - Final CapstoneRoadmap-Final · support

    Finish the protocol and invariant specification, deterministic fault campaign, bounded real-code extension, fallback, ablations, workload regions, negative result, operations dossier and independent reproduction package.