Race Conditions on Shared Tool Resources
also known as Unlocked Read-Modify-Write, Concurrent Agent Resource Contention
Anti-pattern: let concurrent agents perform read-modify-write on shared external resources without locking, producing silent data corruption.
Context
Multiple agent instances (parallel sub-agents, fan-out workers, swarm members) operate on the same external resource — a row in a database, a file in object storage, a row in a spreadsheet, a calendar entry. Each agent reads, modifies in memory, then writes back.
Problem
When two agents read the same baseline, modify independently, and write back, the last writer wins and the first writer's change is lost. Without explicit locking (compare-and-swap, optimistic concurrency control, lease), corruption is silent — both writes 'succeed' from the agent's perspective. The corruption surfaces hours or days later as missing fields or wrong totals.
Forces
- Parallelization patterns naturally encourage concurrent writes for speed.
- Backing stores without native CAS (spreadsheets, simple files, some APIs) make locking awkward.
- Agents do not naturally serialize because they have no shared view of in-flight work.
Example
A fan-out of 5 sub-agents each appends a row to a shared CSV report. They all read the file, append in-memory, and write back. Two of the appends land at the same time; the second overwrites the first. The report has 4 rows instead of 5 with no error. Discovered three weeks later when a quarterly reconciliation found revenue gaps.
Diagram
Solution
Therefore:
Use the backing store's CAS or ETag mechanisms. Where unavailable, route writes through a dedicated single-writer agent (consumer of an event queue). For non-mutating reads, allow parallelism freely. Pair with quorum-on-mutation when the resource is high-stakes (financial, identity). Detect lost-writes via background reconciliation jobs and alert on divergence.
What this pattern forbids. No useful constraint; the missing constraint is explicit concurrency control on every write to a shared resource.
And the patterns that stand alongside it, or against it —
- complementsQuorum on Mutation·— Require multiple consecutive ticks (or runs) to agree before a mutation to durable state lands.
- complementsMissing Idempotency on Agent Calls✕— Anti-pattern: retry state-mutating agent tool calls without idempotency keys, so retries multiply real-world side effects.
- complementsHidden State Coupling✕— Anti-pattern: agent workflows read or write undeclared shared state (caches, env vars, process globals) instead of explicit inputs and outputs.
- alternative-toParallelization★★— Run independent LLM calls concurrently and combine results.
- complementsCompensating Action★★— Pair every irreversible-looking agent action with a compensating action that can undo or counteract it.
Neighbourhood
Click any neighbour to follow the language. Scroll to zoom, drag to pan.