What happens when two agents write the same state
Give each key one writer wherever you can. When several agents must write the same key, replace overwrite with a merge function, or attach a version to every read and reject any write that carries a stale one. For history, append events instead of editing a value in place. Then run a test where two agents write at the same moment.
What is a lost update between agents?
A lost update happens when two agents read the same value, each computes a change from that value, and the second write replaces the first without ever seeing it. Nothing fails. The store accepts both writes, and one agent's work is gone.
Overwrite is often the default, which makes this easy to hit. LangGraph's docs say most channels use last-write-wins, while channels with a reducer combine values.
Session stores carry the same risk. Google's ADK docs warn against directly modifying the session.state collection on a session obtained straight from the SessionService, and say this kind of change can lead to race conditions and lost updates.
How does one writer per key prevent conflicts?
If only one agent ever writes a key, there is nothing to conflict. Other agents read it. This is the cheapest fix and the one to try first.
ADK's parallel agent docs describe this for concurrent branches: give each sub-agent an output_key and read those keys from a later agent's instruction. The same page says not to rely on one branch reading a key another branch is still writing. ADK also lists template workflows as superseded in Python, TypeScript, Go, and Kotlin by graph-based and dynamic workflows, so check which structure your SDK language expects.
Mastra's workflows apply the same idea to parallel steps. Each parallel step's output is keyed by its id, and the next step receives one object holding all of them.
A merge step then reads every writer's key and combines them, so the combining logic lives in one place.
When should a reducer merge concurrent writes?
Use a reducer when several agents legitimately contribute to one key, such as a list of findings or a message history. A merging reducer decides how an incoming update combines with the value already stored, so a second write adds to the first instead of replacing it.
In LangGraph, each key has its own reducer, and with no reducer an update overwrites the previous value. A reducer there is a binary function of the current value for the key and the update a node returned. The build checklist says to add a reducer for any key that multiple nodes write, and notes that parallel fan-out then fan-in is often done with reducers.
The docs' example attaches operator.add to a list key with Annotated. In it, foo overwrites and bar appends, so an update of {"bar": ["bye"]} to {"foo": 1, "bar": ["hi"]} yields {"foo": 1, "bar": ["hi", "bye"]}.
Reducers only fit data that merges cleanly. Appending to a list is safe. Merging two different values for a single status field is not, and you need a rule or a single writer there. LangGraph lets you bypass a merging reducer with Overwrite to replace a value, including clearing it. Watch one more trap: with a merging reducer, returning an empty value keeps prior data, which matters for retry counters that must clear between attempts.
How do versioned writes and optimistic checks work?
Attach a version number, timestamp or content hash to every record. An agent reads the record and its version, does its work, and writes back with the version it read. The store accepts the write only if the version still matches, then increments it. A mismatch means someone else wrote in between, so the agent re-reads and redoes its change instead of overwriting.
This is called optimistic concurrency. It suits agent work because model calls are slow, and holding a lock across one would stall every other agent. The cost is a retry path, which you must write and bound. The guide on preventing agent loops covers caps for repeated attempts.
Retries also re-run work. LangGraph's docs say that with a checkpointer, a node that hits an interrupt or retry runs again from the start of its function, and they recommend idempotency keys, upserts, or read-before-write checks.
Some SDKs apply a generation-style guard internally. In the OpenAI Agents SDK's OpenAIResponsesCompactionSession, automatic compaction records which wrapper generation belongs to the run and skips a stale compaction rather than replacing newer history. A concurrent wrapper mutation waits for compaction and then applies to the resulting history. The docs say not to mutate the underlying session directly during compaction, because direct mutations bypass these wrapper guarantees.
Locks are the pessimistic alternative. ADK's append_event serializes concurrent updates to the same session where the service supports it. In ADK's state docs, DatabaseSessionService takes a per-session lock, while InMemorySessionService is not safe for multi-threaded use. Check what your chosen store promises before you assume either behavior.
Why use an append-only log instead of mutable state?
An append-only log records each change as a new entry and never edits an old one. Two agents appending at once produce two entries, so neither overwrites the other. Current state is computed by reading the log, and a bad write can be found and corrected by a later entry.
According to ADK's state docs, session state changes are applied through events. Its append_event call adds the event to session.events, reads the state_delta from the event's actions, and applies those changes to the state the SessionService manages. The docs list the cost of bypassing that path: a direct change isn't recorded as an Event, so auditability is lost.
For tracing which agent wrote what from such a log, see debugging multi-agent systems.
Which sources does this page use?
- Graph API overview (docs.langchain.com), reviewed November 2026
- State (adk.dev), reviewed November 2026
- Parallel workflow (adk.dev), reviewed November 2026
- Control flow (mastra.ai), reviewed November 2026
- Build checklist for the Graph API (docs.langchain.com), reviewed November 2026
- Overview (openai.github.io), reviewed November 2026
- Persistence (docs.langchain.com), reviewed November 2026
- Don't Build Multi-Agents (cognition.com), reviewed November 2026
- langchain-ai/langgraph: libs/langgraph/langgraph/errors.py (GitHub), reviewed November 2026
- Subgraphs (docs.langchain.com), reviewed November 2026
What do people ask about agent state conflicts?
Do conflicts matter if only one agent runs at a time?
Much less, because conflicts need overlapping writes. Cognition's blog argues that the simplest way to follow the principles the post sets out is a single-threaded linear agent, where context stays continuous. He also notes that very large tasks can overflow context windows in that setup.
What happens when one parallel step fails?
It depends on the framework. In Mastra, if any parallel step throws an error, the entire parallel block fails, and the docs suggest handling errors inside the step with try/catch to keep partial results. LangGraph's error code notes that its runner stops sibling tasks after a peer fails.
Is a reducer the same as a lock?
No. A lock makes writers take turns. A reducer lets writes arrive in any order and defines how they combine, so it only works where combining is well defined.
Can parallel calls to one subagent conflict on checkpoints?
Yes, in LangGraph. Per-thread subgraphs do not support parallel tool calls, and parallel calls cause checkpoint conflicts because both write to the same namespace. With a pure StateGraph, the docs say to prevent this yourself, for example by disabling parallel tool calling on the model.
Updated November 2026