Eight Tracks in One File
You have now seen every load-bearing idea in Coop from the inside. The best way to find out whether you actually own them is to build them small, with nothing but Python's standard library, and watch each one refuse the thing it exists to refuse. The program below is about 190 lines. Save it as toy_ledger.py, run it with any Python from 3.9 up, and it prints the demo shown under it. Run it twice: each run builds a fresh ledger in a new temporary directory, so the second run prints the same lines.
The Pieces, and Where You Met Them
| In the toy | What it does | In Coop |
|---|---|---|
flock on ledger.db.lock | A second Ledger on the same file refuses to start. | Track 2: the engine lock |
write_permit() + BEFORE triggers | A raw connection's INSERT dies with no such function: write_permit. | Track 2: the missing function |
command(key, …) | A replayed key returns the stored answer; the same key with different arguments conflicts on its fingerprint. | Track 2: a key remembers its answer |
invite | Returns an invitation id and a nonce, never the task's text; refuses a second active invitation for one todo. | Track 3: an invitation without the task |
accept | One transaction: the nonce must be echoed, the take is guarded by status and revision, the outcome obligation is written, and only then is the title returned. | Track 3: accept in one transaction |
report | done closes the todo and resolves the debt; blocked keeps both and makes the review due now. | Track 5: four outcomes |
sweep | Lists every outcome still owed, soonest first. | Track 6: an outcome is owed |
Three Choices Worth Noticing
A wrong answer is not an answer. When the worker replies "Sure, on it!" without the nonce, accept raises, the transaction rolls back, and the invitation is still waiting for a real answer. Coop's adapter treats a final with neither token the same way: it is simply not an answer yet.
A refusal can be a recorded result. When the todo was edited between invite and accept, the guarded UPDATE … WHERE status='open' AND revision=? matches no row. The toy returns a refusal, marks the invitation stale, and commits that, so replaying the same key gives the same refusal. Coop's engine made the opposite choice twice over. It refuses and rolls back instead of recording the refusal, and since todo #471 it does not refuse an edit at all: the worker accepted blind, so the work envelope simply carries the amended todo, and only work someone else already holds makes it raise Work changed before acceptance. The toy's stricter rule is a fine one for a toy. Pick deliberately which of your failures deserve a receipt, and which changes deserve a refusal at all.
Reads leave no receipt. sweep takes no key and writes nothing, the rule Coop adopted after a three-day measurement found read results piling up in its command table.
What This Toy Deliberately Leaves Out
Be honest with yourself about the size of the gap. Everything above is the easy half: a single-file store with a single caller. Coop's hard half is everything that touches a world it does not control.
- Native adapters. Nothing here delivers an invitation to a real chat, reads its transcript, or proves the nonce came from the session you invited. In the toy, the caller simply passes
answer. Track 4 is why that is the difficult part. - Receipts. Stored, accepted by the transport, consumed by the harness, accepted as work, given an outcome: Coop records those as separate facts. The toy has one.
- Generations. A session that is replaced keeps its name here; nothing fences its old incarnation's late report.
- A chief, and notifications. The sweep lists owed outcomes and nobody reads it. Coop wakes a reviewer on evidence and carries outcomes to Dad through an outbox written in the same transaction.
- The fleet. One process, one disk. No hosts, no helper, no adoption.
If you want to grow it, grow it in this order, because each step makes the next one safe: give sessions a generation and check it on every call; add an outbox table that every outcome writes into in the same transaction; then build one consumer of the sweep that records its decisions through command like everything else. Only after that is it worth connecting a real chat, and when you do, expect most of your time to go into proving what a native door actually did.