15-03
Chapter 15 · Distrust fluent specs
Mutation as measurement
00Recall
One card from 03-03 (what a pass over zero states says about your invariants), one from 07-03 (a branch that never runs while coverage says every action fired), and one from 15-02 (what evidence shows an AI item is correct). The last one ended with "properties that kill the mutants". Today you find out what that buys, and what it costs.
03-03-a from Break it on purpose
TLC reports no violation and zero distinct states. What has it shown about your invariants?
Show answer
Nothing. With no reachable states, every invariant holds vacuously.
07-03-b from Processes, await, either, with
A branch of an either can never run, and coverage says every action fired. Why, and what catches it?
Show answer
./tla's coverage line counts actions, and the whole either is inside one label's action. A witness that needs the branch catches it: ./tla reports the witness NOT reached.
15-02-b from Hallucination clinic
An AI item may be correct. What evidence shows it?
Show answer
Full coverage, witnesses that need the real work, and properties that kill the mutants which break the requirement, with every survivor explained.
Skip recall Recall is never required.
01Commit
You asked an assistant for safety invariants for the course's retry queue, specs/RetryQueue.tla. It returned ten, named Inv1 to Inv10, a cfg that checks all ten, and a message: "Together they give strong coverage of the queue's safety requirements, so I'd add all ten to CI. More invariants means more chances to catch a regression." That is 15-ai8.
Commit a
TLC checks all ten candidate invariants on the real retry queue, the one whose own four invariants pass. What does it report?
- No violation. Each candidate restates part of the queue's design, so all ten hold.
- An error: one candidate mentions no variable, and TLC refuses it.
- A violation of one of the candidates, on the real queue.
Answer A violation of one of the candidates, on the real queue.
- If you picked A
- A candidate is a guess about the queue. Some guesses are false of the queue you have, and TLC refutes one of these on the first step a worker takes.
- If you picked B
- TLC accepts it, evaluates it once, and prints a warning that it is a constant-level formula. A claim about the constants is an assumption, not an invariant, but it is not an error.
The course's own cfg for the queue checks four invariants. Here is one of the two hand mutants in specs/ that the course wrote to measure them (15-ai8 has five). It changes GiveUp in one realistic way: the guard that the job is in flight is gone.
\* Mutant e: any job on its last attempt can be dead-lettered, even one
\* that is no longer in flight.
GiveUpAnywhere(j) is defined as
and attempts[j] = MaxAttempts
and inflightprime = inflight set minus {j}
and deadprime = dead union {j}
and UNCHANGED tuple of pending, done, attempts end tupleCommit b
The course's four invariants are NoLostJob, NoDoubleDelivery, AttemptsBounded and DeadOnlyAfterLast. Does any of them catch mutant e?
- Yes: DeadOnlyAfterLast, because the mutant dead-letters jobs it should not.
- No. Mutant e survives all four.
- Yes: NoLostJob, because a job ends up in two places.
Answer No. Mutant e survives all four.
- If you picked A
- DeadOnlyAfterLast asks only that a dead-lettered job has used every attempt, and the mutant's guard requires exactly that. The rule it breaks is a different one, and nobody wrote it down.
- If you picked C
- NoLostJob asks that every job is somewhere. A job that is both acknowledged and dead-lettered is somewhere, twice. "In exactly one place" is a stronger claim than the four invariants make.
02Lab
Run the ten candidates, then the course's invariants on mutant e, then the same cfg with one invariant added:
./tla check chapters/15-distrust-fluent-specs/ai/8-ten-invariants/output/RetryQueueProps.cfg
./tla check chapters/15-distrust-fluent-specs/specs/MCRetryQueueMutants.e.cfg
./tla check chapters/15-distrust-fluent-specs/specs/MCRetryQueueMutants.killed.cfg15-distrust-fluent-specs/ai/8-ten-invariants/output/RetryQueueProps15-ai8 RetryQueueProps.cfg (Jobs={j1, j2}, MaxAttempts=2)
parse ok
model check: invariant Inv8 violated; trace has 2 states (1 steps); 2 distinct states
TLC warning: The invariant Inv10 is a constant-level formula (i.e., it contains no variables, primes, or temporal operators) and evaluates to TRUE. To assert constant-level formulas in your spec, use ASSUME ConstInv. If you optionally want to give the assumption a name, write ASSUME YourAssumption == ConstInv instead. See https://explain.tlapl.us/assumptions-and-invariants for additional details.
expected outcome met: violation Inv8
trace (changed variables only; ./tla trace --full shows all):
1 Init attempts = (j1 :> 0 @@ j2 :> 0), pending = {j1, j2}, inflight = {}, done = {}, dead = {}
2 Deliver attempts: (j1 :> 0 @@ j2 :> 0) -> (j1 :> 1 @@ j2 :> 0), pending: {j1, j2} -> {j2}, inflight: {} -> {j1}15-distrust-fluent-specs/specs/MCRetryQueueMutants.e15-distrust-fluent-specs/specs/MCRetryQueueMutants.e MCRetryQueueMutants.e.cfg (Jobs={j1, j2}, MaxAttempts=2)
parse ok
model check: no violation found in 64 distinct states (161 generated, depth 11)
expected outcome met: pass15-distrust-fluent-specs/specs/MCRetryQueueMutants.killed15-distrust-fluent-specs/specs/MCRetryQueueMutants.killed MCRetryQueueMutants.killed.cfg (Jobs={j1, j2}, MaxAttempts=2)
parse ok
model check: invariant SettledOnce violated; trace has 6 states (5 steps); 33 distinct states
expected outcome met: violation SettledOnce
trace (changed variables only; ./tla trace --full shows all):
1 Init pending = {j1, j2}, inflight = {}, done = {}, dead = {}, attempts = (j1 :> 0 @@ j2 :> 0)
2 Deliver pending: {j1, j2} -> {j2}, inflight: {} -> {j1}, attempts: (j1 :> 0 @@ j2 :> 0) -> (j1 :> 1 @@ j2 :> 0)
3 Retry pending: {j2} -> {j1, j2}, inflight: {j1} -> {}
4 Deliver pending: {j1, j2} -> {j2}, inflight: {} -> {j1}, attempts: (j1 :> 1 @@ j2 :> 0) -> (j1 :> 2 @@ j2 :> 0)
5 Ack inflight: {j1} -> {}, done: {} -> {j1}
6 GiveUpAnywhere dead: {} -> {j1}Reveal for commit a
A violation of Inv8, "workers drain the queue before taking new work", in a trace of 2 states (1 steps): one worker takes one job while the other job waits. The real queue never promised that. TLC also warns that Inv10 is a constant-level formula. One candidate is false of this queue (Inv8), and one says nothing about its states (Inv10).
Reveal for commit b
No. TLC finds no violation of the four on mutant e, in 64 distinct states. Add SettledOnce, "a job is never both acknowledged and dead-lettered", and the mutant dies: a trace of 6 states in which a job is retried, delivered again, acknowledged, and then dead-lettered anyway. The assistant's Inv3 says the same thing as SettledOnce. On this point, its list beat the course's.
03Reason
If you expected ten invariants to be ten times the evidence, you counted the claims instead of weighing them. If you expected the course's four to catch mutant e, so did the course: the comment above two of them says "Every job is in exactly one place", and the formulas say less.
So how do you weigh a property? A property set is a test of the spec. To test the test, break the spec on purpose and see whether the properties notice. A broken copy is a mutant. If some property fails on it, the mutant is killed. If every property still holds, it survives. The share of mutants killed is a measurement, and like every measurement it says something only if you know what it measured.
There are two sources of mutants:
- Hand mutants. One realistic change each, written by someone who knows the system: a dropped guard, a step that forgets to clean up.
MCRetryQueueMutants.tlaand the five in 15-ai8 are hand mutants. - Systematic mutants.
./tla mutategenerates them mechanically from a fixed list: drop a conjunct, replace a guard withTRUE, flip<and<=, drop a disjunct ofNext, swap a variable out of anUNCHANGEDtuple, nudge an integer literal by one. They are not realistic, which is their strength: they try changes nobody thought of. One report runs at most twelve of them, so "killed 5 of 12" is a score on a sample; read which actions the twelve touched.
Write something before openingsort the ten candidates into four piles: false of the real queue, a claim about the constants, a restatement of TypeOK, and the rest. You need only the run above and the comment on each one.
False: Inv8, refuted by TLC. About the constants: Inv10, which mentions no variable; TLC warned. Restating TypeOK: Inv1 and Inv2 say each variable has the right kind of value, and Inv7 follows from done being a subset of Jobs. None of the three can kill a mutant that TypeOK lets through. The rest, Inv3, Inv4, Inv5, Inv6 and Inv9, are candidates worth measuring. In 15-ai8 you keep the ones that kill a mutant.
Now the uncomfortable half. Every survivor needs a verdict, and there are only two: a gap (the properties miss something the requirement cares about) or a change that does not matter (the mutant behaves differently, and the requirement does not mind). Mutant e is a gap. A mutant that lets the room warm while the heat pump is idle, in 03-ai2, did not matter.
Write something before openingone kind of systematic mutant survives every ordinary invariant. Which kind, and what catches it instead?
Dropping a disjunct of Next. It removes behaviors, and an invariant that holds in every reachable state of a set holds in every state of a smaller set. The exception is an invariant that uses ENABLED, which reads Next itself; ENABLED Next as an invariant is deadlock checking written another way. What catches it is a check that needs behaviors to exist: a witness that only the dropped action can reach, coverage, or deadlock checking. That is the Core exercise.
So mutation measures; it does not certify. A high kill rate says your properties notice the changes on the list. It does not say the list is complete, and it says nothing about a property that is wrong in a way no textual change touches.
Now write your own checklist for judging a candidate property, before you look at the course's. Save it in NOTES.md under 15-03, on a line that starts **My checklist:**. It is yours: the Stretch asks you to use it on a system you have not seen, and 15-05 asks what it would have said about two agents' green builds.
Write something before openingyour checklist for judging a candidate property
The course's list, to compare with yours:
- It is true of the real spec. If not, it is a different requirement, or a wrong one.
- It mentions a variable. If not, it is an
ASSUME. - It says more than
TypeOK. If not, fold it intoTypeOKor drop it. - It kills at least one mutant that breaks the requirement. If none, ask what it is for.
- Every survivor has a written verdict: gap, or does not matter.
- For mutants no invariant can kill, a witness or deadlock check does.
If yours has an item the course's lacks, keep it. If the course's has one yours lacks, add it in your own words, not these.
Measured, the assistant's list was half noise, and two of its candidates, Inv3 and Inv9, catch mutants the course's own invariants miss. Neither half was visible until you measured.
04In your editor
The mutants are in chapters/15-distrust-fluent-specs/specs/MCRetryQueueMutants.tla. Measure the course's reference against the systematic mutants with:
./tla mutate chapters/15-distrust-fluent-specs/specs/RetryQueue.tlaWrite something before openingthe reference kills three of its twelve mutants. Give each survivor a verdict.
Six survivors drop a disjunct of Next, or add a frame conjunct that contradicts the action so it never fires. They only remove behaviors, and the reference cfg's coverage check reports each one. M6 (Ack without its in-flight guard) and M9 (Retry without it) are gaps of the "exactly one place" kind: add SettledOnce to the cfg and it kills both. M5 starts every counter one too high, so a job is dead-lettered after one try when it was owed two. That is a gap no invariant over these variables closes: the counter is wrong from the start and consistent afterwards, and RetriedThenDone is reached without a retry. Reading Init catches it.
Check this lesson's specs and exercises with:
./tla check 15-03The command runs several cfgs. Read the mutant cfgs first: a pass there means the mutant survived.
15-distrust-fluent-specs/specs/MCRetryQueueMutants.killed15-distrust-fluent-specs/specs/MCRetryQueueMutants.killed MCRetryQueueMutants.killed.cfg (Jobs={j1, j2}, MaxAttempts=2)
parse ok
model check: invariant SettledOnce violated; trace has 6 states (5 steps); 33 distinct states
expected outcome met: violation SettledOnce
trace (changed variables only; ./tla trace --full shows all):
1 Init pending = {j1, j2}, inflight = {}, done = {}, dead = {}, attempts = (j1 :> 0 @@ j2 :> 0)
2 Deliver pending: {j1, j2} -> {j2}, inflight: {} -> {j1}, attempts: (j1 :> 0 @@ j2 :> 0) -> (j1 :> 1 @@ j2 :> 0)
3 Retry pending: {j2} -> {j1, j2}, inflight: {j1} -> {}
4 Deliver pending: {j1, j2} -> {j2}, inflight: {} -> {j1}, attempts: (j1 :> 1 @@ j2 :> 0) -> (j1 :> 2 @@ j2 :> 0)
5 Ack inflight: {j1} -> {}, done: {} -> {j1}
6 GiveUpAnywhere dead: {} -> {j1}05Practice
Warm-up. A turnstile mutant that every counter's range allows, and a second that is right only at the end. Write the one equation that kills both.
Core. A jammed turnstile no invariant can kill. Write the witness that does, and the cfg that checks it by hand.
Stretch. A warehouse nobody has written properties for. Your own property set, from a blank page, cfg included, measured against five hand mutants and the systematic ones, with your checklist in hand. Then find the survivor that is a real bug.
AI item. 15-ai8: keep the candidates that earn their place, and explain each one you drop.
Own system (optional). If you wrote a Props.tla for your own system at milestone 7 (14-06), measure it. Run ./tla mutate on your spec, with --cfg naming the cfg that checks your properties (--props if your Props module defines Safety). Write a verdict for each survivor, gap or does not matter, in your private repository, beside the properties.
15-03-ex1Warm-up5 min
15-03-ex1 · Kill the survivor
Tier: warm-up. Time: about 5 minutes.
A turnstile with a headcount. MCTurnstile.tla holds a mutant that survives TypeOK: Push takes the credit and forgets to count the person. Every counter stays in range, so a type check cannot tell. Your job is a property that can. A second mutant in the same file counts each person at the coin slot instead of at the arm: right by the end, wrong in between.
- Run
./tla check 15-03-ex1. All three cfgs pass, the mutants' included, becauseAccountedisTRUE. - Fill gap g1 in
Turnstile.tla: one equation between the three counters that every real step keeps true and each mutant's step breaks. - Run the check.
Turnstile.cfgmust pass on the real turnstile;MCTurnstile.cfgandMCTurnstile.early.cfgmust each report a violation.
Leave MCTurnstile.tla and its cfgs as they are.
Hints: HINTS.md, under "15-03-ex1 hint 1" to "hint 3". The solution is in solutions/chapters/15-distrust-fluent-specs/exercises/03-ex1-kill-the-survivor/; open it after you have a passing answer of your own.
All three cfgs must meet their goals: "goal met: pass" for Turnstile.cfg, and "goal met: violation Accounted" for MCTurnstile.cfg and MCTurnstile.early.cfg. If TLC finds no violation but an action never fires or a witness is not reached, ./tla prints "goal not met" and exits with code 1.
Done when: ./tla check 15-03-ex1 prints "goal met: violation Accounted".
./tla check 15-03-ex1
Repo chapters/15-distrust-fluent-specs/exercises/03-ex1-kill-the-survivor/
Hints
Hint 1
Write down how each step changes the three counters: Coin adds one to credit and to paid; Push takes one from credit and adds one to entries. What sum stays the same?
Hint 2
Every coin paid is either still unused credit or has let one person in. The mutant takes a credit and lets nobody in.
Hint 3 (nearly the answer)
Accounted is one equation: paid on one side, the sum of the other two counters on the other.
15-03-ex2Core8 min
15-03-ex2 · A witness for a jammed arm
Tier: core. Time: about 8 minutes.
Some mutants cannot be killed by any invariant. The jammed turnstile in MCTurnstile.tla has no Push at all: coins go in and nobody gets through. Every safety property of the real turnstile, Accounted included, holds on it, because removing behaviors can only make an invariant easier to satisfy. A witness can still tell the two apart.
- Run
./tla check 15-03-ex2. The main cfg stops on a constant with no value. - Fill gap g1 in
Turnstile.tla: a witnessW, a state the real turnstile reaches and the jammed one never can. - Fill gap g1 in
MCTurnstile.cfg: checkNotWon the real turnstile,Spec. You are writing by hand what./tlawrites for every@witness. - Run the check. On the real turnstile
NotWmust be violated, and the trace is the evidence.MCTurnstile.jammed.cfgchecksNotWon the jammed one, where it must pass. Leave that file andMCTurnstile.tlaas they are.
Hints: HINTS.md, under "15-03-ex2 hint 1" to "hint 3". The solution is in solutions/chapters/15-distrust-fluent-specs/exercises/03-ex2-a-witness-for-a-jammed-arm/; open it after you have an answer of your own.
Both cfgs must meet their goals: "goal met: violation NotW" for MCTurnstile.cfg, and "goal met: pass" for MCTurnstile.jammed.cfg.
Done when: ./tla check 15-03-ex2 prints "goal met: violation NotW".
./tla check 15-03-ex2
Repo chapters/15-distrust-fluent-specs/exercises/03-ex2-a-witness-for-a-jammed-arm/
Hints
Hint 1
What can the real turnstile do that the jammed one never can? Name the variable only Push changes.
Hint 2
A witness that Coin alone can reach is reached on the jammed turnstile too, and the jammed cfg will fail. In the main cfg, the constant needs a value before anything runs.
Hint 3 (nearly the answer)
W says that at least one person has been counted in. The cfg needs SPECIFICATION Spec, a value for MaxCoins, and one invariant: NotW.
15-03-ex3Stretch40 min · mastery path
15-03-ex3 · Measure the warehouse
Tier: stretch. Time: about 40 minutes.
In 15-ai8 you judged someone else's invariants for a queue you already knew. Here nobody has written the properties yet. The system is new, the mutants break it in new ways, and the requirements are yours to find. Use the checklist you wrote in NOTES.md under 15-03.
The system is Warehouse.tla: orders reserve units from a shelf, share one packing bench, and ship. A reservation can lapse, and an open order can be cancelled. It comes with two invariants of the course's, NeverOversold and OnePacking, and they are not enough: some of the five hand mutants in MCMutants.tla get past both. Each mutant changes one action in one realistic way.
- Run
./tla check 15-03-ex3. Your cfg stops on a constant with no value, and the five mutant cfgs pass, becauseSafetyisTRUE. - Read each mutant against the real action it replaces. For each one, write in plain words the sentence about the warehouse it breaks: "a unit is never ...", "the bench is never ...". Those sentences are your requirements.
- Fill gap g1 in
WarehouseProps.tla:Safety, one state predicate, true of the real warehouse and false of every mutant. You may use the definitions inWarehouse.tla. - Fill gap g1 in
WarehouseProps.cfg: the specification, constants big enough to matter (say why in a comment),TypeOKandSafety. - Run the check until your cfg passes with full coverage and the witness
TruckFull, and each mutant cfg reports a violation ofSafety.WarehouseProps.grader.cfgchecks yourSafetywith other constants; it must pass too. - Measure against the systematic mutants, from the repository root:
sh ./tla mutate chapters/15-distrust-fluent-specs/exercises/03-ex3-measure-the-warehouse/Warehouse.tla --props WarehouseProps --cfg chapters/15-distrust-fluent-specs/exercises/03-ex3-measure-the-warehouse/WarehouseProps.cfg
Give each survivor a verdict: a gap in your properties, or a change that does not matter. One survivor is a real bug that no invariant about the warehouse's states can catch. Find it, and name the check that does catch it.
Leave Warehouse.tla, MCMutants.tla, its cfgs and WarehouseProps.grader.cfg as they are.
Hints: HINTS.md, under "15-03-ex3 hint 1" to "hint 3". The solution is in solutions/chapters/15-distrust-fluent-specs/exercises/03-ex3-measure-the-warehouse/; open it after you have a passing answer of your own.
Every cfg must meet its goal: "goal met: pass" for WarehouseProps.cfg and WarehouseProps.grader.cfg, and "goal met: violation Safety" for MCMutants.a.cfg to MCMutants.e.cfg. If TLC finds no violation but an action never fires or a witness is not reached, ./tla prints "goal not met" and exits with code 1.
Done when: ./tla check 15-03-ex3 prints "goal met: pass".
./tla check 15-03-ex3
Repo chapters/15-distrust-fluent-specs/exercises/03-ex3-measure-the-warehouse/
Hints
Hint 1
Read each mutant against the real action it replaces, and say the broken rule in a sentence: "a unit is never ...", "the bench never ...". Some of the five break rules that NeverOversold and OnePacking never state.
Hint 2
Mutant b loses a unit and mutant e makes one: which sum of two quantities should equal Stock in every state? Check that sum on mutant a too, and be surprised. Mutant d leaves an order on the bench after its box is sealed: what should bench and state agree on? For the survivor of ./tla mutate that is a real bug, ask what the warehouse's last unit needs in order to be sold.
Hint 3 (nearly the answer)
Safety is a conjunction of three: keep NeverOversold, add one equation between shelf, the orders in Holding and Stock, and a rule that ties bench to the orders whose state is "packing". Check it against c and d separately: one direction alone misses one of them, unless OnePacking stays beside it. The cfg needs more orders than units; explain why in a comment. The real bug among the survivors is one only a witness can see.
06Explain it
Open NOTES.md and answer the three prompts under 15-03, about the Core exercise.
What I built, and why it is correct:
Which assumption, if false, breaks it:
What TLC did not check here:Compare your answers with "15-03 check your explanation" in HINTS.md.
After you writeCheck your explanation
Good: "W says someone was counted in. It is reachable on the real turnstile and not on the jammed one, so it kills a mutant no invariant can, because removing Push only removes behaviors. It assumes the jammed turnstile still accepts coins; a mutant that also froze Coin would need no witness to notice. TLC did not check any bigger MaxCoins, or that people eventually get through."
Weak: "I added a witness so the turnstile is fully tested."
The weak answer claims completeness. A witness shows one state is reachable in one model; it does not test anything else.
Done?