Chapter

00

The bug your tests won't find

Part I · Behaviors before syntax

  • 4 lessons
  • 1 h 55 min of core lessons
  • Skills: counterexamples, evidence

Lessons

About

Two transfers run at the same time on one account. The function that moves the money is a few lines of Python, and its 200 tests all pass. Which final balances are possible?

This chapter answers that question three ways. First you predict. Then you see every order in which the two transfers' steps can happen, laid out as a tree. Then you run the model checker TLC on a short model of the same code and read the counterexample it prints. Along the way you learn how the rest of the course works: the lesson loop, hints and notes, gates, and how to use AI tools inside it.

The goals: feel that concurrency bugs live in interleavings, get a first TLC counterexample in lesson 00-03, and learn how the course works. There is no TLA+ to write yet: chapter 01 builds the ideas without syntax, and chapter 02 starts the language.

Before you start

  • Terminal and Git. Reading a short Python function. Python itself is optional.
  • Java 21 and the pinned TLA+ tools, or a Codespace. START.md in the repository root covers both, and lesson 00-03 runs ./tla doctor to check your setup.
  • Time: the chapter page shows the estimate, generated from each lesson's own minutes field.

What else is here

  • specs/Transfer.tla: the model, complete and ready to run. Transfer.cfg checks the invariant NoFreeMoney and expects it to fail. Transfer.explore.cfg explores every state for the interleavings lab. Transfer.equal.cfg is the 00-03 Core practice.
  • impl/py/: the Python transfer() and its tests (python3 -m unittest in that folder).
  • ai/1-agent-transfer/ (00-ai1): an agent's transfer() with a passing test suite and a confident message. Predict whether it is correct, then let TLC decide. It is the Core practice of 00-04.
  • No gate in this chapter. Gates start in chapter 03.

Run it

From the repository root:

shell
./tla doctor
./tla check 00-03
./tla check 00-ai1

Skills

Reading counterexamples (counterexamples), and knowing what a piece of evidence covers (evidence).

Elsewhere

  • Web version: https://indicogni.com/learn/tla-plus/00-the-bug-your-tests-wont-find/
  • Recap of each lesson: CONCEPTS.md. Hints and explanation checks: HINTS.md.
  • Answers to every prediction: solutions/chapters/00-the-bug-your-tests-wont-find/PREDICT-ANSWERS.md. The fix for 00-ai1: solutions/chapters/00-the-bug-your-tests-wont-find/ai/1-agent-transfer/.

Beyond the lessons

  • 00-ai1 AI item · chapters/00-the-bug-your-tests-wont-find/ai/1-agent-transfer/ · ./tla check 00-ai1