01 / Reproduce
Replay the same action
Extract the practice ZIP and open PowerShell in the extracted folder. Use Python 3.12 or later with SQLite 3.35 or later. The first script runs the replay. The second checks the supplied results and tests rollback, constraint errors, and a payload containing an apostrophe and non-ASCII text.
python .\queue_lab.py
python .\verify_lab.py
The unchecked table accepts both deliveries of A-101 and holds two rows. The guarded table starts empty and gets four requests. Each request uses a new connection to the same temporary database.
A-101, draft forT-42→queued.A-101, draft forT-42again →replayed.A-101, draft forT-43→conflict. The original draft request stays in place.A-102, draft forT-42→queued. A new action ID can carry identical text.
The final outbox holds A-101 and A-102, both for T-42. Compare your output with observed-results.json. The sample database is removed when the lab exits.
02 / Inspect
Let SQLite enforce the action ID
The table declares action_id TEXT NOT NULL PRIMARY KEY. The insert targets that key. Its RETURNING clause yields a row when SQLite inserts one. The targeted conflict clause leaves other constraint errors, such as a null payload, visible to the caller.
INSERT INTO outbox (action_id, payload) VALUES (?, ?)
ON CONFLICT(action_id) DO NOTHING
RETURNING action_id;
Read enqueue() in queue_lab.py. It binds both values as parameters and consumes the insert result. When there is no returned row, it reads the saved payload for the same ID in the same transaction. An exact text match means replay in this exercise. A different payload means the caller should review the conflict. The calling code exits the transaction before recording the status. A separate check raises an exception before commit and verifies that the next attempt can insert the row.
03 / Make it your own
Choose what makes an action the same
- Try changing the third attempt from
T-43toT-42and rerun the first script. The third status becomesreplayed. Restore the fixture before running the checks again. - Pick one action your agent can request. For a team inbox, that might be a draft reply for a particular workspace and ticket. Decide which fields must match on replay, including the destination if it affects the result.
- Have the caller assign the action ID once and carry it across retries. Decide what to do when the same ID arrives with changed inputs. If several callers share a database, scope the key to the owning tenant or workflow and apply the same scope to the lookup.
The practice README includes an optional prompt for reviewing a handoff design with an assistant.
Boundaries
Follow the write past the queue
The exercise checks one local database with sequential attempts. If a worker later sends a message and crashes before recording the result, the worker still needs a way to reconcile the send. Check whether the receiving service accepts a stable idempotency key and how long it retains that key. Keep replay records for the retry window you need. We tested neither a delivery worker nor an external service, concurrent load, a model, the optional prompt, or performance.
Primary sources / Checked November 9, 2026
Read the SQLite and Python contracts
- Key uniqueness and explicit non-null requirements. SQLite CREATE TABLE
- Targeting an action key without suppressing unrelated errors. SQLite UPSERT
- Rows returned by an insert and the SQLite version requirement. SQLite RETURNING
- Bound values, connection lifetime, and commit or rollback behavior. Python sqlite3 reference
Downloads / Practice files

