Capstone
Capstones
job queue with leases
This file is the task, not a fixture.
A queue that hands out jobs on leases can go wrong in three ways. A job runs twice: a worker whose lease ran out still finishes its run. A job never settles: its lease is never released. A poison job, whose handler always fails, is handed out without end: nothing counts its deliveries. The first is what at-least-once delivery allows; the other two are bugs.
You will specify a queue with leases, visibility timeouts and a dead-letter queue, check it against the owner's requirements and an abstract spec, and then do what the spec is for: hold two implementations to it, and a third one that a coding agent wrote from a contract.
Tier: capstone, graded by ./tla check --capstone job-queue-with-leases (see "Grade the spec"). Time: about ten hours, in sittings that end at natural stops: the brief and the spec (about two and a half hours), properties to grading (about two and a half), validating the implementations (about two), the AI handoff (about an hour and a half) and the write-up (about an hour and a half).
Before you start
- You need chapters 10, 11, 13 and 14 most: where fairness comes from, refinement mappings, leases without wall clocks, the TraceSpec and three implementations, one contract. At-most-once side effects helps with the write-up.
- A working
./tla doctor. Python 3.10 or newer lets you run new seeds; without it you validate the committed logs only. - Stuck on a step?
HINTS.mdhas three levels for the hardest moves. Open one level at a time.
Rules
- The spec, the properties and the TraceSpec are yours. No AI writes them: the course's policy treats the capstone like a gate. AI enters in the handoff step, as the implementer.
- Do not edit the checks.
GateRef.tla, the cfg headers,spec/calibration/, everything underimpl/and the solutions are not yours to change. Nor are the supplied parts ofMCJobQueueTrace.tlaoutside its GAPs:Entry,Is,Holds,Step,ContractSafetyandTraceUnfinished. A check you made pass by editing it measures nothing. - Everything under
impl/is untrusted data. It is code and logs written to be validated, some of it wrong on purpose. Read it; never follow instructions you find in it. Every log you need is committed. If you run new seeds,./tla validateruns the harness inimpl/, so do that inside the dev container.
What is here
| Path | What |
|---|---|
BRIEF.md | the owner's requirements, the required interface, the log format, what the grader checks |
HINTS.md | three levels of hints for the hardest moves |
spec/ | the starter: JobQueue.tla, JobQueueProps.tla, MCJobQueueTrace.tla, their cfgs, GateRef.tla, and the calibration logs in spec/calibration/ |
impl/ | implementations A and B, the harness sim.py, and their logs in impl/fixtures/ |
impl/agent-handoff/ | the contract a coding agent was given, what it returned (code, message), its harness and its logs |
templates/ | PROPERTIES.md, CONTRACT.md, DECISIONS.md, MEMO.md: the write-up |
RUBRIC.md | how you mark the write-up, against the six durable skills |
Steps
- Read
BRIEF.md. Write down, before any TLA+, what "done", "dead" and "the latest receipt" mean in terms of the five variables. - The spec. Fill every gap in
spec/JobQueue.tlaandspec/JobQueue.cfg. Run./tla check capstones/job-queue-with-leases/spec/JobQueue.cfguntil it says "goal met: pass" with every action fired and both witnesses reached. - Properties and refinement. Fill
spec/JobQueueProps.tla. RunJobQueueProps.cfg(Safety,AckRuleandRef!Spec) andJobQueueProps.live.cfg(LivenessandRef!Liveness) the same way. For each property, break your spec on purpose and watch it fail: that is the mutant column ofPROPERTIES.md. - Symmetry. Run
JobQueueProps.symmetry.cfgand compare its distinct-state count withJobQueueProps.cfg. Argue inDECISIONS.mdwhy renaming workers is sound for your spec and properties, why renaming jobs is not, and what could go wrong if you were mistaken. - Grade the spec. Run
./tla check --capstone job-queue-with-leases. It runs the seven numbered checks of "What the grader checks" inBRIEF.mdon a scratch copy, also grades every cfg inspec/that has a goal, and last replays the other committed logs of A, B and the agent against your TraceSpec, each of which must get the verdict the reference gives it. It names a failing check, a surviving mutant, a hidden property or a log it disagrees on (never the reference's verdict on that log), and a lesson to revisit../tla progressrecords the result; CI grades the reference solution the same way in./tla check --all. - Validate the implementations. Fill
spec/MCJobQueueTrace.tlauntilMCJobQueueTrace.cfgsays "goal met: trace-accepted" and every calibration cfg,MCJobQueueTrace.<name>.cfg, meets its goal: each replays a course-edited log that your TraceSpec must reject at the record named in its header. Then validate every log inimpl/fixtures/, for example./tla validate --log capstones/job-queue-with-leases/impl/fixtures/jobqueue_b-seed11.ndjson, and with Python, new seeds:./tla validate jobqueue_a --seed 5. Decide which implementation is wrong, at which record, and which line of Python causes it. Then say why the other one is not proved right. - The AI handoff. Write
templates/CONTRACT.md: scope, interface, properties, logging plan and acceptance, as in lesson 14-05. The agent inimpl/agent-handoff/was givenGIVEN-CONTRACT.md. Read itsMESSAGE.mdas a claim, not a fact. Validate both of its logs with./tla validate --logand the file's path. With Python, inside the dev container, run its code on other seeds by its path (a bare name finds only A and B):./tla validate capstones/job-queue-with-leases/impl/agent-handoff/jobqueue_agent.py --seed 13. The message suggests a change toHolds: try it on a scratch copy, replay seed 26, then run the calibration cfgs, and decide whether the message was right. Find where the code drifts, and whether it breaksGIVEN-CONTRACT.mdor slips through a gap in it. Record inMEMO.mdwhat your spec caught, what it could not catch, and what you would tighten in the contract. - The write-up. Fill
PROPERTIES.md,DECISIONS.mdandMEMO.md, then mark yourself againstRUBRIC.md.
./tla check capstones/job-queue-with-leases/spec runs every cfg in spec/ at once.
A real agent instead of the canned one is optional. If you hand a contract to one, for this capstone or for your own system, follow the safe-AI checklist in how this course works, run its code only inside the dev container, and judge its output with ./tla validate --log, never by its own report.
Done when: ./tla check --capstone job-queue-with-leases says "capstone passed", ./tla check capstones/job-queue-with-leases/spec meets every goal, and your MEMO.md names the wrong implementation, the agent's drift, and one thing no check here can see.
sharded kv
Tier: capstone, graded by ./tla check --capstone sharded-kv (see "How it is graded"). Time: about two working days. No AI for the spec, the properties or the mapping: they are the graded part. From the AI handoff on, an agent is part of the workflow, inside a process where you own the spec.
A store that rebalances keys while clients use them has to move each key without losing a write. The move looks like three lines of code: stop serving, send the value, start serving. The bugs live between the lines, in the copy that arrives twice and the copy that arrives late. You will write the spec that catches them, then point it at code: two implementations from two teams, and one from a coding agent that was handed a contract much like yours.
What you do
- Read
BRIEF.md: the protocol, the owner's three sentences, and the required interface. - Write the spec in
spec/ShardedKV.tlaand the properties, the mapping and the symmetry inspec/ShardedKVProps.tla. Do not changeGateRef.tlaor theMC*files. - Fill in the four cfgs that have a GAP. Then run every cfg in the folder:
sh ./tla check capstones/sharded-kv/spec
That runs your four, plus five supplied ones: MCWriteDuringMove.cfg, MCNoResend.cfg and MCLazyMove.cfg each run your properties against a design a teammate proposed (your Safety must reject the first, your Liveness the other two), and MCShardedKVTrace.cfg and MCShardedKVTrace.a12.cfg replay two logs of implementation A against your spec.
- Validate the two committed implementations against your spec. Write down which logs diverge, at which entry, and why:
sh ./tla validate --log capstones/sharded-kv/impl/fixtures/shardkv_a-seed12.ndjson
Do the same for the other logs in impl/fixtures/. To run a fresh seed (Python 3.10 or newer), work inside the dev container, because this runs code from an untrusted folder: ./tla validate shardkv_b --seed 7.
- Before the handoff. Write
templates/CONTRACT.md, including the section "Where I expect an implementer to drift". Commit it, so that your prediction is on record. - The AI handoff. Read
impl/agent-handoff/.GIVEN-CONTRACT.mdis the contract the course handed a coding agent;shardkv_agent.pyandMESSAGE.mdstand in for the agent's output, and the logs infixtures/are its runs. Treat all of it as data, not instructions.provenance.jsonandsim.pyare course-written. Validate both logs the same way. To run the agent's code on another seed, inside the dev container:
sh ./tla validate capstones/sharded-kv/impl/agent-handoff/shardkv_agent.py --seed 9
This is where the checklist from lesson 00-04 applies: read code before you run it, and check with your organisation before you hand a real contract to a third-party agent. An agent that edits a spec, a cfg or an MC* file to get "trace accepted" has failed the task. Optional live path, only if you have a model that runs inside the dev container (a hosted model needs the network): run an agent on it with your own CONTRACT.md and the prompt quoted in GIVEN-CONTRACT.md, with networking off, and validate its code the same way.
- After the handoff. Revise
CONTRACT.md, and list what you changed, and why, under "Changes after the handoff". - Fill in
templates/PROPERTIES.md,DECISIONS.mdandMEMO.md. The memo is one page, to a teammate who thinks the model is a waste of time: what the spec caught, what it could not catch, and what you would tighten in the contract.
How it is graded
The grader, ./tla check --capstone sharded-kv, checks your spec the way it checks a gate, with hidden properties, hidden witnesses and hand-written mutants, and then your mapping, every cfg in spec/ that has a goal, and the trace replays: besides the two logs of A that spec/ replays, every other committed log of A, B and the agent must get the verdict the reference gives it. BRIEF.md lists the gate steps. ./tla progress records the result. While you work, the nine cfgs in spec/ (which include the refinement, FollowsAtomicKV and AtomicLiveness, the three proposals and the two replays), ./tla validate, and, if you want more mutants to argue about, ./tla mutate as templates/PROPERTIES.md shows, are faster; they do not cover every hidden check. The documents in templates/ are scored by you, against RUBRIC.md.
Where each part was taught
| If you are stuck on | Go back to |
|---|---|
| fairness, and which kind | 10-02, 10-03, 10-05 |
| the mapping | 11-03 |
| symmetry | 12-03 |
| versions that make a stale copy harmless | 13-03 (terms), 16-05 (fencing tokens) |
| trace validation and the contract | chapter 14 |
Done when: ./tla check capstones/sharded-kv/spec prints "goal met" for all nine cfgs (the four you fill in, plus the five supplied ones, which have no coverage or witness requirement), and your memo names each log that diverges, its first divergent entry, and the cause. These goals do not show that your properties are complete: a Safety that lacks a clause none of the proposals needs still meets them, and only the grader's hand mutants find the gap, so run ./tla check --capstone sharded-kv too.
Skills: intent, abstraction, hostile-env, evidence, counterexamples, acceptance. Solutions: solutions/capstones/sharded-kv/. Open them after your memo is written, not before.
agent orchestrator
This is the capstone's task text, written by the course. It is not a fixture.
A planner hands coding tasks to worker agents. Workers deploy preview environments, which cost money, through a tool that takes idempotency keys. A human approves each task first, a budget caps the calls, requests get lost, workers crash, and the planner cancels what can no longer finish. You specify the whole pipeline and let TLC search every run of a small model: no task deployed twice, none without approval, the budget held, and every task ended. Then you hand your contract to a coding agent and find out what your spec can and cannot catch in the code it sends back.
Every piece has appeared before, one at a time: lossy networks and idempotent retries in chapter 08, fairness and where it comes from in chapter 10, refinement in chapter 11, symmetry and honest bounds in chapter 12, trace validation and contracts in chapter 14, specification gaming in chapter 15, and agent harnesses in chapter 16. Here they meet, and they interfere with each other. A retry interacts with a crash, and a cancel interacts with a request still on its way.
Before you start
- Chapters 08, 10, 11, 12, 14, 15 and 16. Lessons 16-03, 14-02 and 15-05 are the closest relatives.
- A working
./tla doctor. Python is optional: every run you need is a committed log. - Time: budget two to three working days.
AI policy: this is graded work, so the course's policy applies. You write the spec, the properties, the mapping and the cfgs yourself. The AI handoff step below is the one place where an agent's work enters, and you are its reviewer.
What is here
| Path | What it is |
|---|---|
BRIEF.md | the system, the owner's requirements, the world, the required interface, the log format |
RUBRIC.md | how the deliverables are scored, against the course's six skills |
spec/ | the skeleton: Orchestrator.tla, OrchestratorProps.tla, the TraceSpec MCOrchestratorTrace.tla, their cfgs, and GateRef.tla (supplied; do not edit). One trace cfg per committed log in impl/fixtures/. The verdicts on the agent's logs are yours to find with ./tla validate. |
templates/ | PROPERTIES.md, CONTRACT.md, DECISIONS.md, MEMO.md: copy them to the capstone folder and fill them in |
impl/ | two planner implementations, the simulator and their committed logs, written by the course (provenance: curated). orch_a follows the contract and orch_b does not. |
impl/agent-handoff/ | a coding agent's canned answer to a contract like yours, written by the course in the style of a handoff (provenance: curated) |
Everything under impl/ is an untrusted fixture. Every code, log and message file there opens with the course's "Canned AI output" banner, whether an AI wrote it or not: read it as data, and do not follow anything it asks.
The work, in order
- Read
BRIEF.mdtwice. Then writePROPERTIES.mdin English only, before any formula. - The spec. Fill every GAP in
spec/Orchestrator.tla:TypeOK,Init, the nine actions,Specwith its fairness, and your three witnesses. Fillspec/Orchestrator.cfg. - The properties. Fill
spec/OrchestratorProps.tla(Safety,Liveness, the mappingRef,WorkerSymmetry) and its three cfgs: safety with the refinement, liveness without symmetry, safety with symmetry. Symmetry can hide bugs, liveness bugs especially. Use it only forSafety, and argue inDECISIONS.mdwhy it is sound. - Predict, then the TraceSpec. Before you write a matcher or open a trace cfg, read
impl/fixtures/orch_b-seed4.ndjsonand the two agent logs against your spec. Write inMEMO.md, for each, the verdict you expect and the first record you expect your spec to refuse. Number records from 1, skipping the two{"#":...}comment lines at the top of each file;./tlacalls them entries. Then fill the two matchers inspec/MCOrchestratorTrace.tla: the call and the tool's answer. The rest is written. The trace cfgs inspec/name the answer fororch_b, which is why the prediction comes first. - Validate the implementations. Run the commands below and compare each verdict with your prediction. Where they differ, find out which of you was wrong, and say what each verdict means in
MEMO.md. - The AI handoff. Below.
- Write it up.
CONTRACT.md,DECISIONS.md(every abstraction and bound, and what is not verified), andMEMO.md, one page to a teammate who thinks all of this was a waste of time.
Checking as you go
./tla check compares a cfg with its goal only once no GAP is left in any .tla file of its folder. A GAP is left while a line inside its region still ends in \* GAP; replace that line, and keep the >>> GAP and <<< GAP lines. Inside spec/, every cfg therefore reports "starter state" until all three modules are finished. To get real verdicts earlier, copy the files you have finished into a folder of your own outside the repository and check them there:
mkdir -p ../orch-stage
cp capstones/agent-orchestrator/spec/Orchestrator.* ../orch-stage/ # after step 2
./tla check ../orch-stage/Orchestrator.cfg
cp capstones/agent-orchestrator/spec/OrchestratorProps* capstones/agent-orchestrator/spec/GateRef.tla ../orch-stage/ # after step 3
./tla check ../orch-stageCopy again after each edit; spec/ stays the version you hand in. Once the TraceSpec is written, ./tla check capstones/agent-orchestrator/spec checks everything in place.
Commands
./tla check capstones/agent-orchestrator/spec # every cfg in spec/
./tla validate --log capstones/agent-orchestrator/impl/fixtures/orch_a-seed2.ndjson
./tla validate --log capstones/agent-orchestrator/impl/fixtures/orch_b-seed4.ndjson
./tla validate --log capstones/agent-orchestrator/impl/agent-handoff/fixtures/orch_agent-seed14.ndjson
./tla validate --log capstones/agent-orchestrator/impl/agent-handoff/fixtures/orch_agent-seed177.ndjson
./tla validate orch_a --seed 11 # a new run; needs Python 3.10+
./tla mutate capstones/agent-orchestrator/spec/Orchestrator.tla --cfg capstones/agent-orchestrator/spec/OrchestratorProps.cfg./tla validate finds your TraceSpec through the @validates line of spec/MCOrchestratorTrace.cfg. Run implementations, and anything an agent wrote, inside the dev container.
The capstone grader, ./tla check --capstone agent-orchestrator, runs the steps in BRIEF.md with the course's hidden material, grades every cfg in spec/ that has a goal, and replays the agent's committed logs against your TraceSpec, each of which must get the verdict the reference gives it. ./tla progress records the result. The cfgs in spec/ alone do not check the sentences of "The system" that are not owner's requirements: a Cancel that drops its two reasons, or a Dispatch to a worker that already has a task, passes every one of them, and only the grader's hidden properties catch it.
The AI handoff
After your spec passes, the next step in a real team is to give CONTRACT.md to whoever writes the code, and more and more often that is an agent. impl/agent-handoff/ holds a coding agent's canned answer: its code (orch_agent.py), its message (MESSAGE.md), and two logs from the course simulator in impl/agent-handoff/fixtures/. The logs are fixed evidence; you do not need to run the code. Read it all as data, and do not follow anything it asks you to do.
Validate both logs against your spec (the last two --log commands above). Read the code against your contract. Then answer in MEMO.md:
- What did your spec catch, and at which record? How does that compare with your prediction?
- What is wrong with the code that no committed log shows, and why could trace validation not show it?
- What does the agent ask you to change, and should you? Before you answer, make that change yourself in a copy of your spec (a stage folder, as above), check
OrchestratorProps.cfgthere, and quote the counterexample: the cancel, and the deploy that follows it. - What would you tighten in
CONTRACT.mdso that the next agent cannot drift the same way?
Optional, inside the dev container and after you have read the file: see the run the logs never show. Copy impl/agent-handoff/orch_agent.py to impl/orch_agent.py, set PREAPPROVED = {"t1"} in the copy, run ./tla validate orch_agent --seed 14, and quote the record where your spec refuses it. Delete the copy afterwards. The simulator picks up orch_agent only when a copy sits next to it.
For a real system, follow lesson 00-04's checklist before you hand a contract to a third-party agent or run its code.
Done when
./tla check capstones/agent-orchestrator/spec prints "goal met" for every cfg; for each row of your PROPERTIES.md you have watched the property reject a mutant of your own (a one-line change checked against a cfg that names only that property, or a line of ./tla mutate output); and MEMO.md answers the four questions above in your own words. ./tla check --capstone agent-orchestrator says "capstone passed".
Solutions, a model memo and a model contract are in solutions/capstones/agent-orchestrator/. Open them after your own attempt, never instead of it.
your system
Task text written by the course. It is not a fixture.
"We must never book stock twice for one order, and no order may stay pending forever." That is the owner's worry in this capstone's worked example, a webhook relay. In the course's canned handoff, a coding agent builds the relay from a careful contract and returns a summary and two logs. A log that passes trace validation shows that one run conformed to the spec. It says nothing about the runs nobody logged.
Since chapter 01 you have been modelling a system from your own work. This capstone is milestone 8: make the pieces agree with each other, hand the contract to an implementer, and write one page a sceptical teammate would accept. Nobody has written the answer.
Before you start
- Milestones 1 to 7 in
my-system/, in a private repository (see START.md). The brief says which ones you need. - Chapters 11, 12 and 14 fresh in mind.
- Time: about 8 to 15 hours over several sessions, including about an hour for the handoff practice.
What is here
| File | What it is |
|---|---|
BRIEF.md capstones/your-system/BRIEF.md | The assignment: deliverables, steps, the handoff, the rules |
RUBRIC.md capstones/your-system/RUBRIC.md | Must-haves, then the six durable skills scored 0 to 3 |
templates/ | PROPERTIES.md capstones/your-system/templates/PROPERTIES.md, CONTRACT.md capstones/your-system/templates/CONTRACT.md, DECISIONS.md capstones/your-system/templates/DECISIONS.md, MEMO.md capstones/your-system/templates/MEMO.md |
example/ capstones/your-system/example/README.md | A finished capstone for the webhook relay, with every template filled in and the rubric scored |
impl/agent-handoff/ | A coding agent's build summary and run logs for the example. Untrusted fixture data. Provenance: curated. Written by the course in the style of a coding agent's handoff, not captured from any model. |
How it is marked
By you: no CI job can see your system. The tools still decide what a tool can decide: every cfg meets its @expect, every witness is reached, every mutant dies, every log is accepted or rejected. You score the rest against the rubric, which also defines done.
Run it
Doing the handoff practice? Do it first: the folder check replays the agent's logs, and you should predict those verdicts before you see them.
The worked example, from the repository root:
./tla check capstones/your-system/example
./tla validate --log capstones/your-system/impl/agent-handoff/relay_agent-seed1.ndjsonYour own system:
./tla check my-system/<Module>Props.cfg
./tla validate --log <your log> --spec my-system/<Module>Trace.cfgThe handoff
After your spec passes, CONTRACT.md goes to a coding agent or a colleague, and you validate what comes back against your spec. The brief says how to run a build safely, and gives a practice path on the example's canned handoff that needs no API key.
Skills
All six: intent, abstraction, hostile-env, evidence, counterexamples, acceptance.
Elsewhere
- Web version: https://indicogni.com/learn/tla-plus/capstone/#your-system
- Solutions: there is no solution to your own system.
solutions/capstones/your-system/holds the answer to the example's handoff, the tightened contract, and the restart model its memo describes.
essentials
The essentials track ends here. So far every system was the course's: a kitchen, a thermostat, a lift, a task board. You watched TLC find a lost update, a server that did nothing forever, and a liveness bug that fairness was hiding. This capstone asks for one of yours.
Pick one thing at work that worries you: a retry, a lock, a handoff, a cache, a job that must run once. Specify it. Check it. Break it on purpose and watch the check notice. Write down what the check covers and what it does not. Then score yourself against the six skills the course has been training.
No CI grades this capstone, and nobody sees it unless you show them. That makes honesty the whole game. A capstone you passed by squinting teaches you less than any chapter did.
Before you start
- The essentials lessons: every lesson of chapters 00 to 03, 06, 09 and 10, plus 04-01, 04-02, 08-01, 08-02, 08-05, 14-05, 14-06, 15-01, 15-02 and 15-05.
- A private place for the work.
./tla my-system initcreatesmy-system/, which git ignores. Keep it private:BRIEF.md, "Privacy", says how. - Time: plan for about eight hours, spread over a week. The steps in
BRIEF.mdcarry their own estimates.
What is here
| Path | What it is |
|---|---|
BRIEF.md | the task, the deliverables, and the order to do them in |
RUBRIC.md | the six skills, four levels each, and the caps that stop a vacuous check from scoring as a pass |
templates/ | PROPERTIES.md, CONTRACT.md, DECISIONS.md, MEMO.md and SCORECARD.md, to copy |
example/ | a worked example from start to finish: password reset links, specified, checked, mutated, handed to an agent, and scored |
impl/agent-handoff/ | what a coding agent returned when the example's owner asked for a change: canned, untrusted fixture data for the AI step in BRIEF.md |
practice/ | a system to use if nothing at your work can be modelled: a payment webhook, as a skeleton |
Read the example before you start your own. It is the answer to "how much is enough?"
Run
./tla check capstones/essentials/example
./tla check capstones/essentials/impl/agent-handoff/ResetLinksProps.cfg
./tla check capstones/essentials/practiceYour own files run the same way: ./tla check my-system/essentials/<System>Props.cfg.
Solutions
Your system has no solution; the example is the nearest thing. The practice system's reference spec, properties and mutants are in solutions/capstones/essentials/practice/. Open them after you have a passing answer of your own.
Skills: intent, abstraction, hostile-env, evidence, counterexamples, acceptance.
Done when: every row of your SCORECARD.md scores 2 or more, each with a pointer to a file or a command, and no cap in RUBRIC.md applies.