Part 5 of 6 · 2 min read
Exercises
Easy
Easy 1: Run it and read the tables (30 minutes)
In code/mini-statebus, run pytest -q and python run_all.py.
Done when: you report items kept, retries and model calls for the three policies, and say why last-writer-wins does not raise an error.
Hint
shared.averaged(policy) and messages.averaged(policy).
Easy 2: Replay a lost update by hand (30 minutes)
Write the sequence of reads and writes for two agents that loses one update, then run it with shared.Store.
Done when: you show the final list and say which agent's work was lost.
Hint
st.snapshot() then st.write(k, ...) from both agents.
Easy 3: Count duplicates (30 minutes)
Run messages.deliver for at_least_once and idempotent with the same seed.
Done when: you report messages sent, effects repeated and missing for both, and explain why the traffic is the same.
Hint
deliver("idempotent", 100, Channel(), 0).
Medium
Medium 1: Back-off (2 hours)
Add a random back-off (1 to 4 ticks) before an optimistic retry.
Done when: you report retries and ticks with and without it for 6 and 12 agents.
Hint
in the optimistic branch set a["wait"] = r.randint(1, 4) on conflict.
Medium 2: Partition the state (2 hours)
Give each agent its own report section and merge at the end.
Done when: you show zero conflicts, report the cost of the merge step, and say when partitioning is not possible.
Hint
keys report_a0, report_a1, and merge at the end.
Medium 3: Dead letters (3 hours)
Add a dead-letter list for messages that exceed max_attempts.
Done when: you report how many messages end there at 40 percent loss and what the receiver should do with them.
Hint
collect ids whose attempts reached max_attempts without an acknowledgement.
Hard
Hard 1: A real shared file or stream (4 hours)
Run three real agents that append findings to one file or stream, with and without versioning. (I did not run this, so your numbers are the ground truth.)
Done when: you report lost entries, retries and model calls, the model and the date, and compare them with the simulation.
Hint
use an append with a version check, or a stream with message ids.
Hard 2: Conflict resolution policy (4 hours)
Let two agents propose different values for one field and add a resolver (priority, vote, or a judge agent). (I did not run this.)
Done when: you report how often each resolver picks the right value under an assumed accuracy and what it costs in calls.
Hint
make the resolver a function of the proposals and measure its accuracy against a ground truth.
Hard 3: Prompt-injection through shared state (4 hours)
Let one agent write an instruction into the shared state and observe whether another agent acts on it. (I did not run this.)
Done when: you report whether it did, and show one mitigation (schema validation, scoped views, or a trust label) and what it still misses.
Hint
label every entry with its author and trust level before showing it.