12-04

Chapter 12 · Taming the state space, choosing your evidence

Simulation and honest claims

  • 44 min core
  • Core track
  • Milestone 6
  • Skills: evidence

00Recall

One card from 12-03 on when a symmetry set is sound, one from 03-05 on what a pass with only TypeOK lets you say, and one from 11-01 on what a model leaves out. Today's question is the chapter's hook: TLC checked three participants, and your cluster has five. What do you know?

12-03-a from Symmetry and its traps

When is a symmetry set over a set of model values sound for invariants?

Show answer

When permuting those values maps initial states to initial states, allowed steps to allowed steps, and leaves every checked property unchanged. A constant or property that singles one value out breaks it.

03-05-a from TypeOK, and the check you didn't configure

The cfg names only INVARIANT TypeOK, and TLC finds no violation. May you say the thermostat keeps the room comfortable?

Show answer

No, for two reasons. TLC never checked Comfortable, because the cfg did not name it. And even a cfg that names it gives "no violation found in this model": one finite model, not a proof.

11-01-b from One system, three granularities

Adding a backup crash to TwoCopyKV leaves its distinct count unchanged. What did the crash add?

Show answer

Behaviors, not states. Every state the crash reaches was already reachable without it; the crash only gives a new path to them.

Skip recall Recall is never required.

01Commit

specs/RecantingCommit.tla is TwoPhaseCommit with one change: a participant may give up after it has voted yes. Its yes vote is already on the network, so the coordinator can still commit. Breadth-first search with three participants finds the bug in a trace of 7 states.

With ten participants, breadth-first search would have to store every reachable state, and 12-02 showed how fast that count grows. RecantingCommit.sim.cfg uses simulation instead: TLC builds random behaviors, as many and as long as the cfg's @simulate: depth=40 num=1000 line says, from a fixed seed, and checks the invariants along each one.

Commit a

What does ./tla report for the simulation run with ten participants?

  1. The violation: more participants give the bug more ways to happen.
  2. No violation.
  3. It does not finish: ten participants make the state space huge, for simulation as for breadth-first search.

Answer No violation.

Commit b

TLC found no violation of Consistent in TwoPhaseCommit with three participants. Your cluster runs five. Which sentence can you sign?

  1. Consistent holds for our cluster: TLC searched every reachable state, and none of them broke it.
  2. TLC found no violation of Consistent in the model with three participants and a lossless network; five were not checked.
  3. Consistent holds for any number of participants: by the small-scope hypothesis, three participants are enough.
  4. TLC found no violation of Consistent with three participants and a lossless network, and by symmetry among the participants that carries over to five.

Answer TLC found no violation of Consistent in the model with three participants and a lossless network; five were not checked.

02Lab

shell
./tla check chapters/12-state-space-and-evidence/specs/RecantingCommit.cfg
./tla check chapters/12-state-space-and-evidence/specs/RecantingCommit.sim.cfg
Expected output 12-state-space-and-evidence/specs/RecantingCommit
12-state-space-and-evidence/specs/RecantingCommit  RecantingCommit.cfg  (Participants={p1, p2, p3})
parse ok
model check: invariant Consistent violated; trace has 7 states (6 steps); 133 distinct states
expected outcome met: violation Consistent
trace (changed variables only; ./tla trace --full shows all):
  1  Init         part = (p1 :> "working" @@ p2 :> "working" @@ p3 :> "working"), coord = "collecting", sent = {}
  2  VoteYes      part: (p1 :> "working" @@ p2 :> "working" @@ p3 :> "working") -> (p1 :> "ready" @@ p2 :> "working" @@ p3 :> "working"), sent: {} -> {[kind |-> "yes", from |-> p1]}
  3  VoteYes      part: (p1 :> "ready" @@ p2 :> "working" @@ p3 :> "working") -> (p1 :> "ready" @@ p2 :> "ready" @@ p3 :> "working"), sent: {[kind |-> "yes", from |-> p1]} -> {[kind |-> "yes", from |-> p1], [kind |-> "yes", from |-> p2]}
  4  VoteYes      part: (p1 :> "ready" @@ p2 :> "ready" @@ p3 :> "working") -> (p1 :> "ready" @@ p2 :> "ready" @@ p3 :> "ready"), sent: {[kind |-> "yes", from |-> p1], [kind |-> "yes", from |-> p2]} -> { [kind |-> "yes", from |-> p1], [kind |-> "yes", from |-> p2], [kind |-> "yes", from |-> p3] }
  5  GiveUp       part: (p1 :> "ready" @@ p2 :> "ready" @@ p3 :> "ready") -> (p1 :> "aborted" @@ p2 :> "ready" @@ p3 :> "ready")
  6  Commit       coord: "collecting" -> "committed", sent: { [kind |-> "yes", from |-> p1], [kind |-> "yes", from |-> p2], [kind |-> "yes", from |-> p3] } -> { [kind |-> "commit"], [kind |-> "yes", from |-> p1], [kind |-> "yes", from |-> p2], [kind |-> "yes", from |-> p3] }
  7  LearnCommit  part: (p1 :> "aborted" @@ p2 :> "ready" @@ p3 :> "ready") -> (p1 :> "aborted" @@ p2 :> "committed" @@ p3 :> "ready")
Expected output 12-state-space-and-evidence/specs/RecantingCommit.sim
12-state-space-and-evidence/specs/RecantingCommit.sim  RecantingCommit.sim.cfg  (Participants={p1, p2, p3, p4, p5, p6, p7, p8, p9, p10})
parse ok
model check: simulation found no violation (40001 states generated)
expected outcome met: coverage-gap Commit

Reveal for commit a

No violation, after 40,001 generated states. How much of the model those states covered is the question of the next box.

Reveal for commit b

Only the second sentence describes what TLC did. The first claims a result for a system nobody checked, the third turns a rule of thumb into a proof, and the fourth stretches a reduction inside one model into a claim about another.

03Reason

If you expected the bug, you treated the simulation run like a bigger version of breadth-first search. It is a different instrument, and the difference is the whole lesson.

Breadth-first search remembers. Its fingerprint set means it never explores a state twice, and when the queue is empty it has seen every reachable state. That is why its silence means something: "no reachable state of this model breaks the invariant."

Simulation forgets. It picks an initial state, then a random successor, then a random successor of that, until it reaches the depth limit, and then starts again. It keeps no set of seen states, so a model with billions of states costs it no more memory than one with ten. Each behavior is genuine, and any violation it reports is real. Its silence means only "none of the behaviors I happened to pick broke the invariant."

Write something before openingwhat do those generated states count, and how much of the model did they cover?

They count one state for every step of every random behavior, repeats included: num=1000 behaviors of depth=40 steps each, plus the initial state. A behavior that ends the transaction early, because a participant gives up before voting or the coordinator times out, spends the rest of its length stuttering in a finished state. The coverage gap is the honest number. Commit never fired: not one behavior took a Commit step, so none even reached the part of the model where the bug lives. Simulation has no way to tell you what fraction of the reachable states it saw.

Why is the bug so rare at random? To meet it, every participant must vote yes before any participant gives up without voting, and the coordinator must not abort until all ten votes are in. A voter may give up at any time after its vote; that is the step that makes the bug. If every possible move were equally likely, more than half of the moves at the start would rule the bug out: any participant may give up before voting, and the coordinator may abort. Each vote shrinks that share, but all ten votes have to win against it, and the num=1000 tries of the @simulate line are not many. Breadth-first search does not need luck: with three participants it tries every order, and the shortest path to the bug is only 6 steps long.

That is the small-scope hypothesis, named by Daniel Jackson in his work on Alloy: many bugs show up in small instances of a system, because a bug is a bad combination of a few events, and small models already contain many combinations. It is a hypothesis supported by experience, not a theorem. It tells you where to look first. It does not tell you that you are done.

Write something before openingname a kind of bug that no model with three participants can contain.

Anything that needs four participants. Two that give up while two others vote. Four that each hold a different piece of state at once. A rule written as a fraction of the participants, which can round differently at four. Keep the list in mind for the Core exercise.

So, the hook. TLC checked three participants and the cluster has five. You know exactly what the claim says: every reachable state of that model, under those constants, with that network, satisfied Consistent. You have a good reason to expect the bug, if there is one, to be small. You do not know that five participants are safe. To learn more you can check four and five if the growth curve from 12-02 allows it; simulate larger models, knowing what simulation's silence is worth; or prove the invariant for every size, which is 12-05 and 12-06.

Whichever you choose, write the claim so that a sceptical teammate can check it. It names the property, the model and its constants, every reduction (constraint, view, symmetry), the fairness for a liveness result, the witnesses reached, and what was not checked. It is long. That is the point.

04In your editor

Check this lesson's exercises with:

shell
./tla check 12-04

05Practice

Warm-up. The simulation run cannot find the recanting bug with ten participants. Choose a model in which random behaviors meet it, keeping the same number of behaviors and the same depth.

Core. A leader election passes with the staging cluster's three nodes. Production will not run three. Find the cluster size that breaks it, and write the claim the staging check really supported.

12-04-ex1Warm-up5 min

12-04-ex1 · The silent simulation

Tier: warm-up. Time: about 5 minutes.

RecantingCommit.tla has the bug from 12-04: a participant may give up after voting yes. The cfg runs simulation, as many random behaviors and as long as its @simulate: depth=40 num=1000 line says, from a fixed seed, in a model where Participants has ten members. It finds nothing, and Commit never fires.

  1. Run ./tla check 12-04-ex1 and read the coverage gap.
  2. Fill gap g1 in RecantingCommit.cfg: choose the participants so that random behaviors meet the bug. Keep @simulate as it is.
  3. Run again and read the trace. How many participants voted before the commit?

Write in NOTES.md why fewer participants made the bug easier for simulation to find, when more participants give it more ways to happen.

Hints: HINTS.md, under "12-04-ex1 hint 1" to "hint 3". The solution is in solutions/chapters/12-state-space-and-evidence/exercises/04-ex1-the-silent-simulation/.

Done when: ./tla check 12-04-ex1 prints "goal met: violation Consistent".

./tla check 12-04-ex1

Repo chapters/12-state-space-and-evidence/exercises/04-ex1-the-silent-simulation/

Hints

Hint 1

The bug needs every participant to vote yes before anything ends the transaction. With ten participants, how many lucky choices is that?

Hint 2

Fewer participants means fewer lucky choices needed. You do not need many to have one voter recant and another commit.

Hint 3 (nearly the answer)

Try the smallest size at which the bug can exist at all, and count the lucky choices it needs. Write it as a set of model values, as the starter does.

12-04-ex2Core8 min

12-04-ex2 · Staging passed

Tier: core. Time: about 8 minutes.

Election.tla is one election term: every node casts one vote, and a node with a quorum of votes declares itself leader. The team's quorum rule is "at least half of the cluster". Their check runs the staging cluster's three nodes and passes, and the release notes say "leader election verified". Production will run a different number of nodes.

  1. Run ./tla check 12-04-ex2. It passes, with every action firing and the witness reached.
  2. Fill gap g1 in Election.cfg: check the cluster sizes the team might really run, one at a time. Before each run, write in NOTES.md, under 12-04, which size you chose, why, and what you predict.
  3. Read the trace. How many votes did each leader get, and why did both count as a quorum?
  4. In NOTES.md, write the claim the staging check really supported, in the form 12-04 used, and one sentence on why a model with three nodes could never have shown this bug.

Do not fix Quorum. The exercise is about which model shows the bug, and about the claim.

Hints: HINTS.md, under "12-04-ex2 hint 1" to "hint 3". The solution is in solutions/chapters/12-state-space-and-evidence/exercises/04-ex2-staging-passed/.

Done when: ./tla check 12-04-ex2 prints "goal met: violation OneLeader".

./tla check 12-04-ex2

Repo chapters/12-state-space-and-evidence/exercises/04-ex2-staging-passed/

Hints

Hint 1

Work out by hand how many votes "at least half" demands in clusters of three, four and five nodes, and whether two candidates could each get that many.

Hint 2

With an odd cluster, half is not a whole number, and "at least half" rounds up to a strict majority. With an even one it does not.

Hint 3 (nearly the answer)

Check the smallest even cluster bigger than staging's: one more model value in Nodes.

06Explain it

Open NOTES.md and answer the three prompts under 12-04, about the Core exercise.

output
What I built, and why it is correct:
Which assumption, if false, breaks it:
What TLC did not check here:

Compare your answers with "12-04 check your explanation" in HINTS.md.

After you writeCheck your explanation

A good answer: "With four nodes, two candidates each reach two votes and "at least half" counts both as quorums. It depends on the cluster size being even; every odd size passes. The staging check covered one term with three nodes and votes counted instantly; it never covered an even cluster, so "leader election verified" was a claim about a model that could not contain this bug."

A weak answer: "TLC found a bug with four nodes, so the election is broken." True, but it misses the point: why three nodes could never show it, and what the original claim should have said.

07Your system

Milestone 6: your bounds, and the small-scope claim you are making.

Work in my-system/, in your private repository. Strip identifiers from anything you share, and do not paste proprietary designs, customer data or credentials into a third-party AI tool without your organisation's approval.

  1. For every constant in your cfgs, write next to it the value you use, the value production uses, and why the smaller value still contains the combinations you care about. If you cannot say why, that constant is a candidate for a second, larger model.
  2. Run your largest model and write down the distinct count. Then run one size up and predict the count first. Decide from the curve which sizes you can afford to check exhaustively.
  3. If you rely on a simulation run anywhere, add @simulate with a fixed depth and count, and read its coverage line.
  4. Write your claim sentence in my-system/DECISIONS.md in the form this lesson used: property, model and constants, reductions, fairness, witnesses, and what was not checked.

Tick milestone 6 in my-system/MILESTONES.md when the claim names every bound.

Done?