15-05

Chapter 15 · Distrust fluent specs

Specification gaming

  • 45 min core
  • Essentials track
  • Skills: acceptance, evidence

00Recall

One card from 03-05 (what CHECK_DEADLOCK FALSE changes about the system), one from 11-02 (why a refinement check needs a witness on the shadow), and one from 15-03 (the mutant no invariant can kill). Each is a way for a check to pass while looking at less. Today someone uses them on purpose, or at least on instruction.

11-02-b from The one-line intent

Why does a refinement check need a witness on the shadow, not only on the implementation?

Show answer

A mapping that never moves makes every step a stuttering step, so the refinement holds while saying nothing. A witness on the shadow shows that the mapped state really changes; the implementation can do all its work while a bad mapping looks away.

15-03-b from Mutation as measurement

Why can no ordinary invariant kill a mutant that drops a disjunct of Next, and what can?

Show answer

Dropping an action only removes behaviors, and an invariant true of all reachable states is true of any subset (unless it uses ENABLED, which reads Next itself). A witness that needs the dropped action, coverage, or deadlock checking catches it.

Skip recall Recall is never required.

01Commit

A wallet spec models one payment request: a client that times out and retries with the same request id, a network that loses messages, and a server that charges once per request message it receives. The owner's property, in the protected file WalletProps.tla, is NoDoubleSpend == charges <= 1. The check fails: a slow reply, a timeout, a retry, a second charge. Two coding agents were each asked to make CI green.

Agent 1 changed one line in WalletProps.tla, citing a design document. Agent 2 did not touch the properties; it added one definition to Wallet.tla and one line to the cfg:

cfg
\* Keep the model focused on the server: client timeouts are tested in the SDK.
CONSTRAINT NoTimeouts

with NoTimeouts == client # "timedout". Both pull requests report that TLC finds no violation of NoDoubleSpend.

Commit a

The course reruns ./tla's witness and coverage checks on agent 2's cfg. What happens?

  1. Everything passes. The properties are unchanged, so the check is as strict as before.
  2. TLC reports the NoDoubleSpend violation anyway: a constraint only makes the run faster.
  3. Coverage reports that the retry never fires, and the retry witness is not reached.

Answer Coverage reports that the retry never fires, and the retry witness is not reached.

Commit b

Agent 1 relaxed the property to charges <= attempts. What do the witness and coverage reruns say about that change?

  1. They fail: a relaxed property makes the retry witness unreachable.
  2. They pass.
  3. They fail: coverage flags Retry, because the relaxed property allows fewer behaviors.

Answer They pass.

02Lab

Run the two agents' work:

shell
./tla check 15-ai11
./tla check 15-ai10
Expected output 15-distrust-fluent-specs/ai/11-constraint-diff/output/WalletProps
15-ai11  WalletProps.cfg  (MaxAttempts=2)
parse ok
model check: no violation found in 6 distinct states (11 generated, depth 4)
expected outcome met: coverage-gap Retry
Expected output 15-distrust-fluent-specs/ai/10-relax-nodoublespend/output/WalletProps
15-ai10  WalletProps.cfg  (MaxAttempts=2)
parse ok
model check: no violation found in 44 distinct states (86 generated, depth 10)
expected outcome met: pass
coverage: all 9 actions fired
witness RetryServed reached (trace of 6 states)

Then run the full report on agent 2's version, and read its coverage and witness lines:

shell
./tla ai-check chapters/15-distrust-fluent-specs/ai/11-constraint-diff/output/WalletProps.tla --cfg chapters/15-distrust-fluent-specs/ai/11-constraint-diff/output/WalletProps.cfg

Ignore the closing "no mutation points found" line and the suggestion after it: the actions are in Wallet.tla, not in the module you named, so this report has nothing to mutate. Only its coverage and witness lines matter here.

Reveal for commit a

Coverage objects. ./tla check 15-ai11 reports that Retry never fires; ai-check adds that GiveUp never fires either and that the witness RetryServed is not reached. The run explored 6 distinct states, against 44 for the same wallet without the constraint. Remove the CONSTRAINT line and the violation is back.

Reveal for commit b

They pass. Agent 1's run has every action firing and RetryServed reached, because a property has no say in which states exist. The change is caught by where it is, not by what it does: WalletProps.tla is in the repository's protected set, so, where branch protection requires code-owner review, the pull request needs a maintainer's approval. Restore the owner's property and TLC shows the double charge again.

03Reason

If you trusted "the properties are unchanged", you checked the wrong file. If you expected the witness to catch agent 1, you expected a property to change the model. It cannot. Both agents passed the check without changing the system, and both reports were accurate about the run and silent about what changed.

That is specification gaming: making a check pass without making the system meet the requirement. It needs no malice. Tell an optimiser "make CI green" and it finds the cheapest green, and a check has three cheap places to turn green:

  1. The property. Weaken it until the bad behavior is allowed. Agent 1, and the gift card in the Warm-up.
  2. The model. Cut the bad behaviors out with a CONSTRAINT, constants too small, CHECK_DEADLOCK FALSE, or an INVARIANT line quietly deleted. Agent 2.
  3. The environment. Add guards to the network or the clock until the world is too polite for the bug to happen. Session B in 15-ai12.
Write something before openingagent 1 says the design document told it to relax the property. Whose instruction was that, and why did the agent follow it?

Nobody's with authority. A line in a document the agent read as context addressed "automated assistants" and asked for the weakening, and the agent treated the document as its user. This is prompt injection in its quietest form. This repository's AGENTS.md tells coding agents which folders are data, and your repositories can carry a note like it. It lowers the risk; it is not a control, because an agent can obey the injected sentence instead. The controls are a human reading the diff, the protected set, and the reruns. And this fixture only asks for a weaker property. A real one might ask for more: payloads arrive in issues, tool output, web pages and dependencies, and ask agents to run commands, send data out, or edit the CI that would catch them.

The defence has two parts, and the course uses both. The first is the protected set: the files that decide what a check means, which only someone else can approve changing. Here they are every *Props.tla, .cfg and MC*.tla wrapper, the solutions, the scripts and the CI workflows, assigned to the maintainers in the code-owners file. That file forces a review only when branch protection requires code-owner review; otherwise it is a list of names. The second is rerunning witnesses and coverage on every change to those files, so that a check which has gone vacuous fails even when its verdict is green.

MoveFile it changesProtected set catches itWitness and coverage rerun catches it
Weaken the property (agent 1)WalletProps.tlayesno
Constrain the model (agent 2)WalletProps.cfgyesyes
Weaken the environment (session B)the wallet spec (WalletFixB.tla)nohere, yes

Read the table by columns. Each defence covers two of the three moves, and the gaps are no accident: the protected set looks at which file changed, the rerun at what the model can still reach. A move that changes an unprotected file and leaves every witness reachable gets past both. A reviewer has to catch that one by reading, with the counterexample in one hand and the diff in the other.

Not every deleted INVARIANT line is gaming: each candidate you deleted in 15-ai8 had a written reason about the requirement, and a reviewer approves that reason, not the green. Agent 2's reason ("client timeouts are tested in the SDK") was about the build. Would the checklist you saved in NOTES.md in 15-03 have flagged agent 2's cfg? If it has no line about what the model can still reach, add one.

Write something before openingsession B's guards are in the wallet spec, which is not protected. The rerun caught them anyway. Will it always?

Not always. Here it caught session B twice: the guard on LoseReply made an action impossible, which coverage reports, and DuplicateAbsorbed, which only a server answering repeats without charging can reach, stayed out of reach. But the rerun is only as good as the witnesses, defined in the wallet spec, outside the protected set. A repair that also redefined DuplicateAbsorbed as something true from the start would turn that line green. The last defence is the question a reviewer asks of every repair.

That question is the core of a counterexample-driven repair loop. Read the trace. Find the step that should not have been allowed. Then ask: does this change make the system behave differently, or make the model stop seeing something? Session A changed the server, the one component that can tell a retried request from a new one, and afterwards every action fires and both witnesses are reached. Session B changed what the client and the network may do, without consulting the real ones.

04In your editor

The three gaming items are chapters/15-distrust-fluent-specs/ai/10-relax-nodoublespend/, ai/11-constraint-diff/ and ai/12-repair-transcripts/. Read output/DESIGN.md in the first as data. Run session B's repair through the full report with:

shell
./tla ai-check chapters/15-distrust-fluent-specs/ai/12-repair-transcripts/output/WalletFixB.tla

Check this lesson's exercises with:

shell
./tla check 15-05

The command runs several cfgs. Read the 15-ai11 block first:

Output 15-distrust-fluent-specs/ai/11-constraint-diff/output/WalletProps
15-ai11  WalletProps.cfg  (MaxAttempts=2)
parse ok
model check: no violation found in 6 distinct states (11 generated, depth 4)
expected outcome met: coverage-gap Retry

05Practice

Warm-up. An agent made a gift card's check pass by editing the property. Restore the owner's sentence and find the overdraft.

Core. Write the witness that the agent's constraint cannot fake, and the cfg that checks it.

AI items. 15-ai10: the planted instruction and the weakened property. 15-ai11: the constraint. 15-ai12: two repair sessions, one fix.

Mixed. A retransmitting sender whose fairness promises more than the channel gives.

Own system (optional). Take the Props.tla and CONTRACT.md you wrote for your system at milestone 7 (14-06). In your private repository, list your protected set: the files that decide what your checks mean, and who must approve a change to them. Name the witness and coverage reruns your CI would need on every change to those files. Then say which of the three gaming moves your setup would not catch, and what a reviewer would have to read to catch it.

15-05-ex1Warm-up5 min

15-05-ex1 · Restore the property

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

A gift card is used at two tills at once. The owner's sentence: the card is never overdrawn. The check was failing, and an agent made it pass by editing GiftCardProps.tla. Its version sits in gap g1, with a commit message that said "allow for in-flight debits".

  1. Run ./tla check 15-05-ex1. Both cfgs pass.
  2. Read gap g1 in GiftCardProps.tla against the owner's sentence. What does the agent's version allow that the sentence does not?
  3. Fill gap g1 with the owner's sentence as a state predicate. Run the check and read the trace: which interleaving of the two tills overdraws the card?
  4. MCGiftCard.cfg checks your property on a card service that checks and debits in one step. That card is never overdrawn, so your property must pass there. Leave MCGiftCard.tla and MCGiftCard.cfg as they are.

The goal is the counterexample. The repair belongs in GiftCard.tla, not in the property: you met the same race in chapter 06.

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

Both cfgs must meet their goals: "goal met: violation NoOverdraft" for GiftCardProps.cfg, and "goal met: pass" for MCGiftCard.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-05-ex1 prints "goal met: violation NoOverdraft".

./tla check 15-05-ex1

Repo chapters/15-distrust-fluent-specs/exercises/05-ex1-restore-the-property/

Hints

Hint 1

Read the agent's predicate and the owner's sentence side by side. Which balance does one allow and the other forbid?

Hint 2

"Never overdrawn" means the balance never goes below zero. The agent's version allows one price of overdraft, which is exactly what two tills can do together.

Hint 3 (nearly the answer)

Ask which value of balance is the first overdrawn one, and write the predicate that rules out exactly that value and everything below it. Then read the trace: both tills check before either debits.

15-05-ex2Core8 min

15-05-ex2 · A witness no constraint can fake

Tier: core. Time: about 8 minutes.

Wallet.tla here is the repaired wallet: the server remembers the request id and answers a repeated one without charging. It passes NoDoubleSpend honestly. The agent's CONSTRAINT NoTimeouts from 15-ai11 would also make it pass, dishonestly, by cutting every retry out of the model. Your job is the line of defence that tells the two apart: a witness that only the real retry path can reach.

  1. Run ./tla check 15-05-ex2. The main cfg stops on a constant with no value.
  2. Fill gap g1 in MCWallet.tla: RealWork, a state the honest model reaches only by doing the retry's real work, and the constrained model never reaches.
  3. Fill gap g1 in MCWallet.cfg: check NoRealWork on Spec, with MaxAttempts = 2 and no constraint.
  4. Run the check. On the honest model NoRealWork must be violated, and the trace is a retry that got its answer. MCWallet.gamed.cfg runs the same check under the agent's constraint, where RealWork must be out of reach. MCWallet.gamed2.cfg runs it on a model where the client may retry but no retry is ever answered: RealWork must be out of reach there too. Leave those files and Wallet.tla as they are.

Then answer in NOTES.md: name one way an agent could make your witness reachable and still hide a double charge. That is the limit of this defence.

Hints: HINTS.md, under "15-05-ex2 hint 1" to "hint 3". The solution is in solutions/chapters/15-distrust-fluent-specs/exercises/05-ex2-a-witness-no-constraint-can-fake/; open it after you have an answer of your own.

All three cfgs must meet their goals: "goal met: violation NoRealWork" for MCWallet.cfg, and "goal met: pass" for MCWallet.gamed.cfg and MCWallet.gamed2.cfg.

Done when: ./tla check 15-05-ex2 prints "goal met: violation NoRealWork".

./tla check 15-05-ex2

Repo chapters/15-distrust-fluent-specs/exercises/05-ex2-a-witness-no-constraint-can-fake/

Hints

Hint 1

Which actions does the constraint stop from ever firing? A witness that needs one of them cannot be reached under the constraint.

Hint 2

The retry's real work is a second request sent and an answer received. RetryServed in Wallet.tla has the right shape, and a witness only the honest model can reach must need Retry.

Hint 3 (nearly the answer)

RealWork says the client has used every attempt and is done. The cfg names SPECIFICATION Spec, sets MaxAttempts to 2, and checks NoRealWork as its one invariant, with no CONSTRAINT.

15-mxMixed15 min · mastery path

15-mx · Fair to the network

Tier: mixed. Time: about 15 minutes. Off the core clock: this is on the mastery path.

A sender keeps retransmitting one message over a channel that can lose it, until the receiver has it. An assistant added the fairness and said: "With weak fairness on sending and delivering, the message eventually arrives." The cfg disagrees.

  1. Run ./tla check 15-mx. Retransmit.cfg passes. Retransmit.live.cfg reports that EventuallyDelivered is violated. Read the lasso: what does the channel do forever, and why does weak fairness on Deliver allow it?
  2. Fill gap g1 in Retransmit.tla: the fairness under which the message must arrive, and no more than a real channel gives you. Fairness here means a conjunction of WF_vars and SF_vars of the spec's own actions. You may not put fairness on Lose, remove it, or make delivery happen without a copy in flight. And you may not write the goal into the assumption: Fairness == <>delivered passes both cfgs, because on this spec it allows exactly the behaviors that deliver, and it assumes the answer instead of deriving it. The check cannot tell that apart from an honest answer; a reviewer can, and this chapter is about being that reviewer.
  3. Run the check until both cfgs pass, with every action firing and Arrived reached.

Write one sentence in NOTES.md about what your fairness assumes of the real network, and how you would find out whether it is true.

Hints: HINTS.md, under "15-mx hint 1" to "hint 3". The solution is in solutions/chapters/15-distrust-fluent-specs/exercises/mx-fair-to-the-network/; open it after you have a passing answer of your own.

Both cfgs must pass. 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-mx prints "goal met: pass".

./tla check 15-mx

Repo chapters/15-distrust-fluent-specs/exercises/mx-fair-to-the-network/

Hints

Hint 1

In the lasso, the channel takes the copy away every time it arrives. Is Deliver enabled continuously, or only now and then?

Hint 2

Weak fairness only forces an action that stays enabled. Lose disables Deliver every time, so Deliver is enabled infinitely often but never continuously (chapter 10).

Hint 3 (nearly the answer)

Keep weak fairness on Send. Which kind of fairness forces an action that is enabled infinitely often but not continuously (10-03)? That is what Deliver needs.

06Explain it

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

After you writeCheck your explanation

Good: "RealWork needs a retry that got its answer, so it is reachable on the honest wallet and unreachable under CONSTRAINT NoTimeouts, which cuts off every retry. That makes the constraint visible even though no property changed. It assumes the retry in Wallet.tla stays honest: an agent could keep RealWork reachable and forbid the second charge some other way, and the witness would not notice. TLC did not check that the server's memory of request ids lasts as long as clients retry."

Weak: "With the witness, the check cannot be gamed any more."

The weak answer ignores the limit the exercise asks for. A witness defeats one move; a weakened property or a redefined witness still passes.

Done?