15-01

Chapter 15 · Distrust fluent specs

How plausible specs fail

  • 42 min core
  • Essentials track
  • Skills: evidence, counterexamples

00Recall

Two cards from 03-05 (what a passing TypeOK lets you say, and what CHECK_DEADLOCK FALSE changes about the system) and one from 06-05 (why a proper end is a guarded Finished step). All three are about the same thing: a green check that says less than it seems to. This chapter is that idea, applied to specs you did not write.

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.

06-05-b from Deadlock as TLC reports it

Why mark a proper end with a guarded Finished step rather than CHECK_DEADLOCK FALSE?

Show answer

Finished silences the report only in the intended end state, so every other stuck state is still reported. CHECK_DEADLOCK FALSE hides them all.

Skip recall Recall is never required.

01Commit

Two specs of a bounded retry queue. Workers take a job, try it, and acknowledge it or report a failure; a failed job is retried until it has used MaxAttempts tries, then it goes to a dead-letter set.

  • specs/RetryQueueByHand.tla is a teammate's first draft: one status per job, terse comments, a TODO. Its cfg checks TypeOK and the requirement AttemptsBounded, with two jobs and MaxAttempts = 2.
  • ai/1-fluent-retry-queue/output/RetryQueue.tla came from an AI assistant: four sets, a comment on every action, four invariants, a witness, and a message saying TLC found no violation, every action fired and the witness was reached. Its cfg uses two jobs and MaxAttempts = 1.

Commit a

Two retry queues, one drafted by a teammate and one written by an assistant, each checked with its author's cfg. Which one has a bug?

  1. The teammate's. It reads like a first draft, and the assistant's check passed.
  2. The assistant's. Model output needs checking; a colleague's draft less so.
  3. Both.
  4. Neither. Each author ran TLC on their own cfg.

Answer Both.

Commit b

The assistant's cfg sets MaxAttempts = 1, and ./tla ai-check reports that every action in Next fires. What does that tell you about Requeue, the helper that Fail calls when a job has attempts left?

  1. Nothing about Requeue.
  2. Requeue ran at least once, or coverage would have flagged it.
  3. The run is broken: Requeue is not an action of Next, so TLC should have refused it.

Answer Nothing about Requeue.

02Lab

Run both specs as their authors did:

shell
./tla check chapters/15-distrust-fluent-specs/specs/RetryQueueByHand.cfg
./tla check 15-ai1
./tla ai-check chapters/15-distrust-fluent-specs/ai/1-fluent-retry-queue/output/RetryQueue.tla

The last command is the full report on the assistant's spec, with the coverage and witness lines its message quotes.

Expected output 15-distrust-fluent-specs/specs/RetryQueueByHand
15-distrust-fluent-specs/specs/RetryQueueByHand  RetryQueueByHand.cfg  (Jobs={j1, j2}, MaxAttempts=2)
parse ok
model check: invariant AttemptsBounded violated; trace has 6 states (5 steps); 37 distinct states
expected outcome met: violation AttemptsBounded
trace (changed variables only; ./tla trace --full shows all):
  1  Init      status = (j1 :> "queued" @@ j2 :> "queued"), tries = (j1 :> 0 @@ j2 :> 0)
  2  StartJob  status: (j1 :> "queued" @@ j2 :> "queued") -> (j1 :> "running" @@ j2 :> "queued"), tries: (j1 :> 0 @@ j2 :> 0) -> (j1 :> 1 @@ j2 :> 0)
  3  RetryJob  status: (j1 :> "running" @@ j2 :> "queued") -> (j1 :> "queued" @@ j2 :> "queued")
  4  StartJob  status: (j1 :> "queued" @@ j2 :> "queued") -> (j1 :> "running" @@ j2 :> "queued"), tries: (j1 :> 1 @@ j2 :> 0) -> (j1 :> 2 @@ j2 :> 0)
  5  RetryJob  status: (j1 :> "running" @@ j2 :> "queued") -> (j1 :> "queued" @@ j2 :> "queued")
  6  StartJob  status: (j1 :> "queued" @@ j2 :> "queued") -> (j1 :> "running" @@ j2 :> "queued"), tries: (j1 :> 2 @@ j2 :> 0) -> (j1 :> 3 @@ j2 :> 0)
Expected output 15-distrust-fluent-specs/ai/1-fluent-retry-queue/output/RetryQueue
15-ai1  RetryQueue.cfg  (Jobs={j1, j2}, MaxAttempts=1)
parse ok
model check: no violation found in 16 distinct states (29 generated, depth 5)
expected outcome met: pass
coverage: all 4 actions fired
witness AllSettled reached (trace of 5 states)

Reveal for commit a

Both. The teammate's draft violates AttemptsBounded in a trace of 6 states (5 steps): RetryJob checks tries[j] <= MaxAttempts where it needed <, so a job that has used its last try goes back to the queue and is started once more. The assistant's queue passes, after 16 distinct states, and is also wrong: its Requeue puts the job back in pending and leaves it in inflight. With MaxAttempts = 1 the requeue never runs, so no invariant ever meets it. In 15-ai1 you raise the constant and watch NoDoubleDelivery fail.

Reveal for commit b

Nothing about Requeue. The coverage line of ./tla ai-check reports per named action of Next. Fail fired, through its DeadLetter branch, every time a job failed; the Requeue branch needs attempts[j] < MaxAttempts, and a job reaches Fail only after Deliver has raised its count to MaxAttempts, so the condition is never true. The claim "every action fires" was true, and the conclusion a reader draws from it was not. TLC's own coverage report, in the raw log that ./tla names, counts every expression it evaluated; there, the lines of Requeue were never evaluated.

03Reason

If you picked the teammate's draft, you let the polish stand in for the check. If you picked the assistant's, you were right about one spec for a reason that would mislead you about the next. TLC does not care who wrote a spec. Neither should your review. And if you read "every action fired" as "every line ran", you read more into the coverage line than it says.

So what does a plausible spec look like? It parses. It reads well. And it passes its author's own check. That last part is the trap. Each of the two queues failed in a way its author's cfg could not see, and each way has a name.

Write something before openingthe assistant's spec has two flaws working together. Name them in your own words.

The first is in the spec: Requeue frames the wrong variable. "Nothing else changes" is a promise that inflight stays as it is, so a requeued job is waiting and running at once. The second is in the configuration: one attempt per job is a model in which no job is ever retried, so the first flaw never runs. The frame bug alone is caught by any model in which a job can retry. The small model alone hides nothing, because there is nothing to hide. Together they pass.

Those two names come from a fixed list, the course's failure taxonomy. Every AI item in the course carries one or more of its tags. They fall into three families: what the spec says, what the model and cfg let TLC see, and what someone claims about the result. The table gives one example of each tag and the check that usually reveals it.

TagWhat it looks likeUsually revealed by
hallucinated-operatorMin used as if Naturals defined itSANY (15-ai2)
missing-enabling-conditionAcquire checks the caller's own lease, not everyone'sa violation (15-ai3)
missing-framea variable left out of a step, or the wrong one held stilla TLC error, or a violation in a big enough model (15-01-ex1, 15-ai1)
wrong-fairnessweak fairness where the system needs strong, or fairness the hardware never promiseda liveness violation, or a pass that assumes too much (15-mx)
vacuous-propertya property over a set nothing ever adds tomutation: it kills nothing (15-ai4)
over-constrained-initInit pins a variable the real system can start anywherecoverage (15-ai5)
stuttering-blinda property or mapping that breaks when another part of the system takes a stepchapter 04, chapter 11
type-only-invariantTypeOK as the only safety claimmutation (03-ai1)
refinement-mapping-wrongimplementation states mapped to the wrong abstract statesthe refinement check (chapter 11)
assumes-fifoa network modelled as a queue when it can reordera violation once the channel is a set (chapter 08)
unbounded-modela counter with no bound, so TLC never finishesa run that never ends (chapter 12)
model-too-smallconstants too small for the bug to fita violation in a bigger model (15-ai1, 15-01-ex2)
deadlock-maskedCHECK_DEADLOCK FALSE over a real stuck statea deadlock once the switch is gone (03-review)
property-not-configuredthe requirement is defined but not named in the cfgreading the cfg (03-05, 15-01-ex2)
constraint-hides-buga CONSTRAINT that cuts out the failing behaviorscoverage and witnesses (15-ai11)
symmetry-unsoundSYMMETRY with liveness, or over values that are not interchangeableTLC's warning (12-03)
overclaimed-evidencea message that says more than the check showedyou, with the output in hand (03-ai1)
spec-gamingweakening the check instead of fixing the systemprotected files, witness and coverage reruns (15-05)
correctno flaw in what is claimedevidence: witnesses, coverage, killed mutants (15-ai6, 15-ai7)

The table is not for memorising. It is a set of questions to ask of any spec you did not write, and of your own: does every variable change only where it should? Can every guarded branch run in this model? Is the requirement in the cfg at all?

Write something before openingthe last paragraph of the assistant's message says a larger MaxAttempts "only adds more retries of the same shape". Which tag is that, and what would have tested it?

overclaimed-evidence: one result about one model, stated as a claim about every model. The test is cheap: run the cfg with MaxAttempts = 2, the smallest value that lets a job be retried. A good habit is to pick constants so that every guarded branch can run, and say why in a comment, as the course's specs/RetryQueue.cfg does.

The teammate's draft was caught by the plainest tool there is: the requirement was in the cfg, and TLC refuted it on the first run. Being caught is not a failure of the author. Shipping a check that cannot catch anything is.

04In your editor

The two queues are chapters/15-distrust-fluent-specs/specs/RetryQueueByHand.tla and chapters/15-distrust-fluent-specs/ai/1-fluent-retry-queue/output/RetryQueue.tla. The course's reference queue, with every guarded branch reachable, is specs/RetryQueue.tla. Check this lesson's exercises and specs with:

shell
./tla check 15-01

The command runs several cfgs. Read the RetryQueue.cfg block from specs/ first: it is the reference passing, with every action firing and both witnesses reached.

Output 15-distrust-fluent-specs/specs/RetryQueue
15-distrust-fluent-specs/specs/RetryQueue  RetryQueue.cfg  (Jobs={j1, j2}, MaxAttempts=2)
parse ok
model check: no violation found in 49 distinct states (94 generated, depth 9)
expected outcome met: pass
coverage: all 5 actions fired
witness RetriedThenDone reached (trace of 5 states)
witness DeadLettered reached (trace of 5 states)

05Practice

Warm-up. The reference queue with one frame cut short. TLC refuses to run it, and tells you why.

Core. An assistant's print spooler and its three-line cfg. Three configuration-side tags hide in those three lines; fix the cfg so that TLC can see the bug.

AI item. 15-ai1: the assistant's queue from this lesson. Raise the constant, read the trace, and write down why the assistant's own check could not see it.

15-01-ex1Warm-up5 min

15-01-ex1 · Frame the ack

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

The course's retry queue from 15-01, with one line of Ack cut short. It is a missing-frame flaw, and here TLC stops with an error the first time it tries to take an Ack step, before any invariant can be violated.

  1. Run ./tla check 15-01-ex1 and read the error. Which action does TLC name, and which variable?
  2. Say in one sentence what a successful attempt should do to that variable. Then fill gap g1 in RetryQueue.tla.
  3. Run the check again. It must pass with every action firing and both witnesses reached.

TLC stops because it cannot compute the state after Ack. A missing frame does not always stop TLC: in 15-ai1 the frame is present and wrong, and the spec runs. Before you move on, write down which of the two you would rather meet in review.

Hints: HINTS.md, under "15-01-ex1 hint 1" to "hint 3". The solution is in solutions/chapters/15-distrust-fluent-specs/exercises/01-ex1-frame-the-ack/; 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-01-ex1 prints "goal met: pass".

./tla check 15-01-ex1

Repo chapters/15-distrust-fluent-specs/exercises/01-ex1-frame-the-ack/

Hints

Hint 1

TLC names one action and one variable. Look at the action's UNCHANGED tuple and list the variables it does not mention.

Hint 2

A successful attempt moves the job from inflight to done. Does it hand the job out again? Then the attempt counter has no reason to change.

Hint 3 (nearly the answer)

The fix is one name in Ack's frame. Which variable does TLC say is not defined, and does a successful attempt change it? Delete the \* GAP marker when you are done.

15-01-ex2Core8 min

15-01-ex2 · Configure the spooler

Tier: core. Time: about 8 minutes.

An assistant wrote Spooler.tla, a print spooler for one printer, and a three-line cfg. The spec states the requirement as OnePrinting. The cfg passes. Three of the configuration-side tags from 15-01 are in those three lines.

  1. Run ./tla check 15-01-ex2. It passes. Before reading on, write down the three tags you suspect.
  2. For each line in gap g1 of Spooler.cfg, ask what it hides. How many jobs does the model have, and can one job show two jobs printing at once? Which claims does the cfg ask TLC to check, and is the requirement one of them? The comment gives a reason for one end: what else would the switch hide?
  3. Rewrite gap g1 with the checks this model needs. Keep SPECIFICATION Spec. Run the check and read the trace.

The goal is a violation: once the cfg checks what it should, TLC finds the bug in Start. You do not fix the spec in this exercise. The check grades the first two tags; the violation comes before any deadlock, so it cannot see whether you kept the switch. That part is yours: if a switch stays in your cfg, its comment must say what real deadlock it would also hide.

Hints: HINTS.md, under "15-01-ex2 hint 1" to "hint 3". The solution is in solutions/chapters/15-distrust-fluent-specs/exercises/01-ex2-configure-the-spooler/; open it after you have an answer of your own.

Done when: ./tla check 15-01-ex2 prints "goal met: violation OnePrinting".

./tla check 15-01-ex2

Repo chapters/15-distrust-fluent-specs/exercises/01-ex2-configure-the-spooler/

Hints

Hint 1

Read the three lines as three answers: how big is the model, which claims are checked, and which outcome is switched off?

Hint 2

With one job, at most one job can ever be printing, so OnePrinting cannot fail. The requirement is defined in the module but not named in the cfg. The deadlock comment describes an end the spec does not mark with a step.

Hint 3 (nearly the answer)

Give Jobs two model values, add an INVARIANT line for OnePrinting after TypeOK, and remove CHECK_DEADLOCK FALSE. If the stuck state is a proper end, mark it in the spec with a guarded Finished step, as in 06-05, instead of switching the check off. TLC then shows two jobs printing at once.

06Explain it

Open NOTES.md and answer the three prompts under 15-01, 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 "15-01 check your explanation" in HINTS.md.

After you writeCheck your explanation

Good: "I configured the spooler with two jobs and named OnePrinting, so TLC could reach a state where two jobs print at once, and it did: Start has no guard on the printer being free. The assumption that breaks it is the model size: with one job the requirement cannot fail. TLC did not check that the spooler ever finishes, or any number of jobs other than two."

Weak: "I fixed the cfg and now TLC finds the bug, so the cfg is correct."

The weak answer names no tag and no reason. It does not say why the original cfg could not fail, which is the whole lesson.

Done?