ArchitecturePart 5 of 8

Conflict Resolution on Shared State: Owners and Write Rules for Every Key

When two agents write the same key, last-write-wins quietly throws away work. How per-key owners and write rules (append, sum, owner approves, read-only) remove most multi-agent conflicts.

DNotifier Team••5 min read
Back to blog
Conflict Resolution on Shared State: Owners and Write Rules for Every Key

The first four parts of this series were about trust: who is calling, and what they're allowed to do. From here on it's about the shared context itself, and what happens when two agents want it to say different things.

Start with the default most systems have, whether they meant to or not: last write wins. Two agents write the same key, and whichever write lands second is what everyone sees. No error. No record that anything was lost.

In a single-threaded program that's fine, because "second" means "later on purpose". In a multi-agent run it means "the agent whose LLM call happened to take longer". Your shared state is being decided by network latency.

A conflict you won't notice

A research workflow runs two agents in parallel. One searches internal docs, the other searches the web. Both are told to "save your sources to state.sources".

Each agent reads sources (empty), builds its list, and writes it back. The web agent finishes 300 milliseconds later and overwrites the internal list completely. The final report cites only web sources, and the team spends a week wondering why the model "ignores our own documentation".

Nothing about that looks like a conflict. It looks like the model being bad at its job. That's what makes these bugs expensive.

Not all keys are the same kind of data

The fix starts with a small realisation: different keys hold different kinds of data, and each kind has a natural way to combine writes. Once you say which kind each key is, most conflicts stop being conflicts.

These are the rules we use. Five cover almost everything we've seen:

append: a list that agents add to. Evidence, sources, notes, findings. Two writes at the same time both land. Nobody's entry replaces anybody else's.

sum / max: a number that accumulates. Tokens used, cost so far, highest risk score seen. Order doesn't matter, so concurrent writes can't conflict.

owner_approves: a decision or fact one agent is responsible for. The refund decision, the ticket category, the final answer. The owner writes it directly. Anyone else's write becomes a proposal the owner has to accept (more on that in part 6).

read_only: configuration set at the start of the run. The refund limit, the customer's region, the policy version. Nobody writes it after that, and an attempt is an error worth logging.

last_write_wins: still useful, but only for values where staleness is harmless. A heartbeat, a "currently working on" status, a progress percentage. If losing an update would matter, this is the wrong rule.

If you've used CRDTs, the first two will look familiar. Append-only lists and counters are the classic examples of data structures where concurrent updates merge without coordination. You don't need the full theory to use the idea: pick keys whose updates commute, and you never have to resolve anything.

An owner and a write rule for every shared state key
An owner and a write rule for every shared state key

Who owns a key

Ownership answers "whose job is it to get this right?". Two ways to set it:

  • By creation. The agent that first writes a key owns it. Simple and usually right for keys an agent invents for its own work.
  • By declaration. The workflow says up front that refund.decision belongs to the refund agent, regardless of who writes first. Use this for anything important. You don't want ownership of the refund decision going to whichever agent happened to touch it first.

A few rules that keep ownership sane:

  • One owner per key. Two owners is the same as none.
  • Ownership can be handed over explicitly, and the handover is recorded.
  • Ownership is checked against the caller's verified identity from part 2, not a name in the request. Otherwise any agent can claim to be the owner.

Why not just lock the state?

The reflex from database work is "take a lock". It's the wrong tool here.

Agent steps take seconds, sometimes minutes. A lock held for the duration of an LLM call blocks every other agent that needs that key, and a crashed or stuck agent can hold it until a timeout clears it. You end up tuning lock timeouts instead of building features.

Per-key rules avoid most of that. Append and sum need no coordination at all. Owner-approves turns contention into a proposal instead of a wait. For the remaining cases, version-checked writes (part 6) detect conflicts at write time without holding anything during the thinking.

Designing your keys

When we design a new workflow, we go through the state keys one by one and ask:

  1. Is this a list of contributions? append
  2. Is this a running total or a high-water mark? sum or max
  3. Is this a decision someone is accountable for? owner_approves, with a declared owner
  4. Is this set at the start and fixed? read_only
  5. Would it be fine if an update got lost? Only then last_write_wins

It takes ten minutes, and it's the single most effective thing I know for preventing state bugs in multi-agent systems.

How DNotifier handles it

Every workflow run has ctx.state, the shared state all agents in the run read and write, including agents running in parallel with ctx.runAgents and remote agents, whose changes are merged back on reply.

Each key in that state has an owner, either the agent that created it or one you declare, and a write rule: owner_approves, append, sum/max, last_write_wins or read_only. The server applies the rule on every write, using the caller's verified identity.

For the research example, sources is declared as an append key. Both search agents add to it at the same time, and both sets of results are kept. And for the refund example, refund.decision is owned by the refund agent with owner_approves, so when the fraud agent writes "deny", it becomes a proposal instead of an overwrite.

Every write, refused write and proposal appears in the state timeline in Traces, so you can see who changed what, and why a write didn't go through.

FAQ

Is last-write-wins ever the right default?

As a default, no. It's the rule that loses data without telling you. Keep it for values where losing an update is genuinely harmless, and make every other key say what it is.

Are these rules CRDTs?

Append, sum and max behave like simple CRDTs: concurrent updates merge the same way regardless of order. Owner-approves and read-only aren't CRDTs. They're access rules. Together they cover what agents actually write.

Can two agents own the same key?

They shouldn't. If two agents are both responsible for a decision, make one the owner and let the other propose, or split the key into two.

What if an agent needs to replace a whole list?

Then that list isn't an append key. Either give it an owner who can replace it, or model it as a new version (plan.v2) so the old one stays readable.

Trust in multi-agent systems

Part 5 of 8

  1. Part 1Multi-Agent Systems Need Shared Context, Not Just Message Passing
  2. Part 2Agent Identity: How an Agent Proves Who It Is
  3. Part 3Who Can Call Whom: Agent-to-Agent Authorization
  4. Part 4Requested vs Granted: Tool Permissions for AI Agents
  5. Part 5Conflict Resolution on Shared State: Owners and Write Rules for Every Key
  6. Part 6Version-Checked Writes and Proposals: Optimistic Concurrency for AI Agents
  7. Part 7Consensus for AI Agents: Validation, Judges, Votes and Humans
  8. Part 8Agent-to-Agent Prompt Injection and Earned Trust

Tags

#multi-agent-systems#agent-trust#multi-agent conflict resolution#shared state conflicts agents#agent state ownership#last write wins#crdt agents

Keep reading

Related articles

View all →