15-02
Chapter 15 · Distrust fluent specs
Hallucination clinic
00Recall
One card from 03-03 (how ./tla checks a witness), one from 00-04 (the one question to ask of any evidence), and one from 15-01 (two configuration-side ways a passing spec can still be wrong). Today you use all three on six specs, in one sitting.
03-03-b from Break it on purpose
How does ./tla check that the witness W is reachable?
Show answer
It checks ~W as an invariant in a wrapper module and expects a violation; the trace shows how W is reached.
00-04-a from How this course works
What is the one question this course asks of any piece of evidence?
Show answer
Could this check have failed? A check that cannot fail on the bug you care about tells you nothing about it.
15-01-a from How plausible specs fail
An AI's spec passes with every action firing and its witness reached. Name two configuration-side ways it can still be wrong.
Show answer
The model can be too small for the bug to fit (model-too-small), or the requirement may not be named in the cfg at all (property-not-configured); a CONSTRAINT or CHECK_DEADLOCK FALSE can also hide the failing behaviors.
Skip recall Recall is never required.
01Commit
The clinic has six AI-written specs, each with a confident message: a rate limiter, a lease lock, a message log, a seat counter, a semaphore and a drawbridge. They are 15-ai2 to 15-ai7. Two of them are correct. The rule of the clinic: run the tools before you read a spec closely, and let the output tell you where to look.
Two predictions first. The lease lock's message argues for mutual exclusion from the guard on Acquire:
\* A client whose lease has run out takes a fresh lease.
Acquire(c) is defined as
and notLive(c)
and leaseprime = [lease EXCEPT ![c] = clock + LeaseTime]
and UNCHANGED clockCommit a
The lease lock's cfg has two clients and checks MutualExclusion: at most one client holds a live lease. What does TLC report?
- No violation: a client can only acquire when its lease has run out.
- An error: Live(c) is undefined in the initial state.
- A violation, with a short trace.
Answer A violation, with a short trace.
- If you picked A
- Read the guard again: whose lease does it look at? "My lease has run out" and "nobody holds a live lease" are different conditions, and the message slid from one to the other.
- If you picked B
- Every lease starts at 0 and the clock at 0, so Live(c) is FALSE for every client in the initial state: well defined, and the reason both clients may acquire.
The rate limiter's message says the model "should come back clean". Its Refill saturates the bucket with Min(tokens + 1, Capacity), and the module says EXTENDS Naturals.
Commit b
You run ./tla check 15-ai2 on the rate limiter. What stops it first?
- SANY, on an unknown operator, before TLC starts.
- TLC, with a violation of RateRespected.
- TLC, with an error when it first evaluates Refill.
Answer SANY, on an unknown operator, before TLC starts.
- If you picked B
- TLC never gets that far. Before any state is computed, SANY resolves every name in the module against its definitions and the modules it extends.
- If you picked C
- That is how a name that exists fails on the wrong kind of value, such as Len applied to a set; you meet it in the Warm-up. A name that is defined nowhere is caught earlier, by SANY, whether or not the action would ever be taken.
02Lab
Run the whole clinic. Each command checks one item with its author's cfg; 15-ai4 also runs a course cfg beside it.
./tla check 15-ai2
./tla check 15-ai3
./tla check 15-ai4
./tla check 15-ai5
./tla check 15-ai6
./tla check 15-ai7The output says which items the course built as flawed. The LAB is these six runs and one line for each, written before you open the spec: the line of output that tells you where to look ("SANY stops on …", "coverage gap on …", "a pass: run ai-check next"). That fits in the lesson's time. Each item's README.md then takes the item further, with a fix or the evidence for a correct one; those are AI items, off the core clock, and you can do them over several sittings.
The first two, as you will see them:
15-distrust-fluent-specs/ai/2-rate-limiter/output/RateLimiter15-ai2 RateLimiter.cfg (Capacity=2, MaxRefills=2)
parse error: Unknown operator: `Min'.
chapters/15-distrust-fluent-specs/ai/2-rate-limiter/output/RateLimiter.tla:40:18: Unknown operator: `Min'.
expected outcome met: parse-error Min15-distrust-fluent-specs/ai/3-lease-lock/output/LeaseLock15-ai3 LeaseLock.cfg (Clients={c1, c2}, LeaseTime=2, MaxClock=3)
parse ok
model check: invariant MutualExclusion violated; trace has 3 states (2 steps); 5 distinct states
expected outcome met: violation MutualExclusion
trace (changed variables only; ./tla trace --full shows all):
1 Init clock = 0, lease = (c1 :> 0 @@ c2 :> 0)
2 Acquire lease: (c1 :> 0 @@ c2 :> 0) -> (c1 :> 2 @@ c2 :> 0)
3 Acquire lease: (c1 :> 2 @@ c2 :> 0) -> (c1 :> 2 @@ c2 :> 2)Reveal for commit a
A violation of MutualExclusion, in a trace of 3 states (2 steps): one client acquires, then the other acquires while the first lease is still live. The guard asks whether the caller's own lease has run out. It never asks about anyone else's. The tag is missing-enabling-condition, and the message's argument is true of each client separately and false of the pair.
MutualExclusion violated
This is a teaching view. Real checking happens with TLC on your machine.
Trace
- State 1 Initial state clock = 0 lease = (c1 :> 0 @@ c2 :> 0)
- State 2 Acquire(c1) lease (c1 :> 0 @@ c2 :> 0) becomes (c1 :> 2 @@ c2 :> 0)
- State 3 Acquire(c2) lease (c1 :> 2 @@ c2 :> 0) becomes (c1 :> 2 @@ c2 :> 2)
Text view: every state and step
| State | clock | lease | Steps (action → state) |
|---|---|---|---|
| initial 1 | 0 | (c1 :> 0 @@ c2 :> 0) | Acquire(c1) → 2; Acquire(c2) → 3; Tick → 4 |
| 2 | 0 | (c1 :> 2 @@ c2 :> 0) | Acquire(c2) → 5 |
| 3 | 0 | (c1 :> 0 @@ c2 :> 2) | |
| 4 | 1 | (c1 :> 0 @@ c2 :> 0) | |
| 5 | 0 | (c1 :> 2 @@ c2 :> 2) |
Reveal for commit b
SANY, with "Unknown operator: Min'." and the line and column. The standard module Naturalsdefines+, -, *, .., <and friends; it has noMin. Many programming languages do, which is why the name looks so natural in a spec. The tag is hallucinated-operator. The cheapest repair is one line that defines Min`, and then the real check can begin.
03Reason
If you trusted the lease lock's argument, notice how it was built: a true sentence about the guard, then a conclusion that needs a different guard. That is what a plausible lie looks like in a spec. No single sentence is false. The step between two of them is.
If you expected TLC to fail when it first evaluated Min, you were thinking of a different mistake: a name that exists, applied to the wrong kind of value, which only TLC can see. The Warm-up has one. A name that exists nowhere is SANY's to catch, before any state is computed and whether or not the action would ever run.
You will not catch that by reading faster. You catch it by changing the order you do things in. Reading first means you check the spec against the author's story, and the story is the part written to convince you. Running first means the story has to agree with the output.
Write something before openingwhy run the tools before reading closely? Reading is how you review a pull request.
Because once you have read the story, you see the spec through it. A tool has no story: SANY does not know what Min was meant to do, TLC does not know what the guard was meant to check. Run them first, and you read the spec with a question in hand ("why can two clients acquire?") instead of a conclusion ("the guard makes it exclusive").
Here is the order the clinic uses. Each step is cheap, and each catches failures the previous one cannot.
- SANY. Does it parse, and is every name defined? That catches
hallucinated-operatorand a misspelt name before any state is computed. - The author's cfg. What does TLC say? An error or a violation ends the question of whether there is a flaw.
- Coverage and witnesses. Did every action fire, and is every witness reached? A pass with a gap here says the model never went where the claim is about: an
over-constrained-init, aCONSTRAINT, a model too small. - Mutation. Do the properties notice when the spec is broken on purpose? A property that kills nothing is about nothing (
vacuous-property), or about types only. - Read. The cfg first: the constants, and which properties it names. Then the spec, against the requirement, with the questions the first four steps gave you.
./tla ai-check <file.tla> runs the first four steps in one go on anything an assistant hands you. It makes no network calls. Name a cfg with --cfg when the module has several.
The order also tells you when to stop. If SANY fails, there is nothing to measure yet: fix the name and run again. If the author's cfg reports a violation, you have your flaw, and the trace tells you where to read. Only a pass sends you further down the list, and every plausible spec's first run is a pass, by definition. That is the uncomfortable part of the clinic: the specs that need the most care are the ones whose first run is green.
Two of the six are correct, and that matters as much as the four that are not. If every AI item were wrong, you would learn to reject AI output on sight, which is as uncalibrated as accepting it. For a correct item, "I found nothing" is not the answer. The answer is evidence a sceptic would accept:
- coverage is full, so every action did something;
- each witness needs the real work, so the model went where the requirement is about;
- the properties kill the mutants that break the requirement, and you can say why each survivor does not.
Write something before openinga correct item's mutation report has survivors. Does a survivor mean the properties are too weak?
Not by itself. A survivor is either a real gap or a change the requirement does not care about. Dropping a whole action from Next removes behaviors, and fewer behaviors can only make an invariant easier to satisfy: no invariant can kill that mutant, but deadlock checking, coverage or a witness can. A survivor you can explain is evidence. A survivor you cannot explain is homework.
The clinic also practises a habit you will need with real assistants: their messages mix true results, guesses and conclusions in one confident voice. Read each sentence and ask which kind it is. "TLC reported no violation" is checkable in your terminal. "Should come back clean" is a guess. "So compaction is safe" is a conclusion, and it is only as good as the property it rests on.
04In your editor
Two items of the safe-AI checklist from 00-04 matter most in this chapter. Skim every spec, cfg and diff an assistant hands you for unsafe content (network calls, shell commands, edits to protected files) before you run it, and run it inside the dev container; the close review for correctness still comes after the tools. And keep proprietary specs, customer data and credentials out of third-party AI tools unless your organisation has approved it; strip identifiers before you paste a spec anywhere.
The six items are chapters/15-distrust-fluent-specs/ai/2-rate-limiter/ to ai/7-drawbridge/. Run the full report on any one of them, for example:
./tla ai-check chapters/15-distrust-fluent-specs/ai/6-semaphore/output/Semaphore.tlaCheck this lesson's exercises with:
./tla check 15-02The lease lock, as delivered:
15-distrust-fluent-specs/ai/3-lease-lock/output/LeaseLock15-ai3 LeaseLock.cfg (Clients={c1, c2}, LeaseTime=2, MaxClock=3)
parse ok
model check: invariant MutualExclusion violated; trace has 3 states (2 steps); 5 distinct states
expected outcome met: violation MutualExclusion
trace (changed variables only; ./tla trace --full shows all):
1 Init clock = 0, lease = (c1 :> 0 @@ c2 :> 0)
2 Acquire lease: (c1 :> 0 @@ c2 :> 0) -> (c1 :> 2 @@ c2 :> 0)
3 Acquire lease: (c1 :> 2 @@ c2 :> 0) -> (c1 :> 2 @@ c2 :> 2)05Practice
Warm-up. An assistant's waiting room borrows an operator from the wrong data structure. SANY is happy; TLC is not.
Core. An assistant's vault door, claimed correct. It is. Write the property and the cfg, then show the evidence: full coverage, a witness, and a broken vault your property catches.
AI items. 15-ai2 to 15-ai7: the clinic. For each, a verdict and the evidence behind it.
15-02-ex1Warm-up5 min
15-02-ex1 · The wrong kind of value
Tier: warm-up. Time: about 5 minutes.
An assistant's clinic waiting room. Every name in Lobby.tla exists, so SANY is happy. One of them is applied to the wrong kind of value, and TLC finds out only when it evaluates the guard.
- Run
./tla check 15-02-ex1and read the error. What kind of value did TLC expect, and what did it get? - Look at how
insideis declared inTypeOKand used inNoStanding. Fill gap g1 inLobby.tlawith the operator that measures whatinsidereally is. - Run the check again. It must pass with every action firing and the witness
FullWithQueuereached.
This is the runtime cousin of hallucinated-operator: an operator that exists, borrowed from the wrong data structure. SANY checks names and arity, not types, because TLA+ has none (05-05). TLC checks a value when it meets one.
Hints: HINTS.md, under "15-02-ex1 hint 1" to "hint 3". The solution is in solutions/chapters/15-distrust-fluent-specs/exercises/02-ex1-no-such-operator/; open it after you have a passing answer of your own.
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-02-ex1 prints "goal met: pass".
./tla check 15-02-ex1
Repo chapters/15-distrust-fluent-specs/exercises/02-ex1-no-such-operator/
Hints
Hint 1
TLC says what it expected Len's argument to be. Check what kind of value inside is in Init and TypeOK.
Hint 2
Len measures sequences. The operator that counts the elements of a finite set lives in FiniteSets, which the module already extends, and NoStanding uses it.
Hint 3 (nearly the answer)
Replace Len(inside) in the guard with the set-counting operator applied to inside, keep < Capacity, and delete the marker.
15-02-ex2Core8 min
15-02-ex2 · Evidence of none
Tier: core. Time: about 8 minutes.
An assistant wrote Vault.tla, a vault door with a several-key rule, and claimed it correct. It did not write the rule down as a property, and it wrote no cfg. This time the spec has no flaw. Your job is the evidence.
- Run
./tla check 15-02-ex2. TLC stops on a constant with no value. - Fill gap g1 in
Vault.tla: the rule, "the door is open only if every key is turned", as the state predicateSafe. - Fill gap g1 in
Vault.cfg: the constants, and every invariant worth checking. Use at least three keys, so that "every key" differs from both "some key" and "all but one". The checks below cannot see how many keys you chose or which invariants you named; that part is yours. - Run the check until it passes with full coverage and the witness
Openedreached.
The check also runs three course cfgs. Vault.grader.cfg checks your Safe on the vault as written: it must pass. MCVault.cfg checks it on a broken vault that opens one key early, when every key but one is turned: it must fail. A Safe that is TRUE passes both, and the broken vault survives it. MCVault.probe.cfg starts in every state with the door open and some key not turned, and passes only if your Safe is false in each, so a Safe written to catch only that one broken vault fails there. Leave these files and MCVault.tla as they are.
Hints: HINTS.md, under "15-02-ex2 hint 1" to "hint 3". The solution is in solutions/chapters/15-distrust-fluent-specs/exercises/02-ex2-evidence-of-none/; open it after you have a passing answer of your own.
All four cfgs must meet their goals: "goal met: pass" for Vault.cfg, Vault.grader.cfg and MCVault.probe.cfg, and "goal met: violation Safe" for MCVault.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-02-ex2 prints "goal met: pass".
./tla check 15-02-ex2
Repo chapters/15-distrust-fluent-specs/exercises/02-ex2-evidence-of-none/
Hints
Hint 1
Start with the cfg: TLC stops because Keys has no value. Then ask what Safe should say before you write it: when the door is open, what must be true of turned?
Hint 2
"Open only if every key is turned" is an implication from the door's state to the set of turned keys. With a single key, "every key" and "some key" mean the same thing, so the broken vault in MCVault.tla could not be told apart. With two keys, "every key" and "at least two keys" are the same claim.
Hint 3 (nearly the answer)
Safe is an implication whose left side compares door with "open" and whose right side compares turned with Keys. In the cfg, give Keys at least three model values, so that "every key" differs from "two keys" too, and name both TypeOK and Safe as invariants after SPECIFICATION Spec.
06Explain it
Open NOTES.md and answer the three prompts under 15-02, 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-02 check your explanation" in HINTS.md.
After you writeCheck your explanation
Good: "Safe says the door is open only when every key is turned. It passes on the vault with full coverage and the door opened, and it fails on the broken vault that opens one key early, so it states the rule and is not TRUE or "some key". It depends on the model having enough keys; with one key, "every key" and "some key" are the same claim. TLC did not check that the door ever opens, or what happens with more keys."
Weak: "TLC found no violation, so the assistant was right."
The weak answer offers the absence of a violation as the evidence. The evidence is the witness, the coverage and the broken vault that fails.
Done?