CSE Roadmap

Common tier · about 4 hours · 12 parts

Part 2 of 12 · 2 min read

A second write can silently erase the first

A shared whiteboard everyone can rewrite is fast to use and quietly loses work the moment two people edit the same line at once.

Think of two roommates editing the same shared shopping list at the same moment. Each reads it, adds their own item, and saves the whole list back. Whichever save happens second wins, and the first roommate's addition simply vanishes with no error, no warning.

In plain words: shared state is data several agents can read and write, often used as a blackboard where agents post and read partial results. But it creates a race condition: an outcome that depends on timing. The specific failure is a lost update, where two concurrent read-modify-write operations collide. The store, following last-writer-wins, keeps only the most recent write and silently discards the rest.

A worked example. With six agents each adding five items to a shared report, last-writer-wins keeps only 5.9 of the 30 items that should be there, on average, and corrupts a running token counter by 421. Zero errors are raised anywhere. Scaling up the number of concurrent agents makes it worse in direct proportion: lost items rise from 5 at two agents to 14 at four, 24 at six, and 54 at twelve.

The key lines. From code/mini-statebus/shared.py:

# from code/mini-statebus/shared.py
if policy == "lww":
    st.write("report", a["snap"]["report"] + [item])
    st.write("tokens", a["snap"]["tokens"] + cost[i])

Read it as: a["snap"] is the state the agent read at the start of its turn, and the write appends to that stale snapshot, not to whatever the state has become since. If another agent wrote in between, this write simply replaces the whole field with a version that never saw that other agent's change. That is the lost update in two lines.

Shared state, blackboard, race condition, lost update, last-writer-wins

Shared state is data that several agents can read and write. A blackboard is shared state used as the main coordination surface, where agents post and read partial results. A race condition is an outcome that depends on the timing of concurrent operations. A lost update is two concurrent read-modify-write operations where one write overwrites the other. Last-writer-wins means the store keeps the most recent write and silently discards the rest.

Example: "5.9 of 30 items kept, with zero errors raised" is last-writer-wins doing exactly what its name says. The store never claims to have kept everything. It just keeps whatever arrived last, and nothing in the system is obligated to tell anyone what got overwritten.