An AI agent can pass every individual test and still fail when multiple users interact with it simultaneously. The problem may not be the model. It may be the way we manage state, memory, context and execution.
I used to think about AI agent reliability mainly in terms of whether the agent understood a request, selected the right tool and produced the expected result. If User A could complete a workflow and User B could complete the same workflow independently, that seemed like a reasonable starting point for testing.
But there is an assumption hidden in that approach: that the two users will never interfere with each other. That assumption becomes dangerous when an agent moves from a personal experiment into a shared application.
Imagine a customer support agent. One customer asks about an order that has been delayed. Another asks for a refund on a completely different purchase. Both requests arrive within milliseconds of each other. The agent retrieves information, reads conversation history, calls tools and prepares responses.
Individually, both workflows may be correct. The problem begins when something that should belong to one session is shared with another.
The second customer might receive an answer based on the first customer's order. A refund action might execute twice because two requests reach the same workflow simultaneously. An agent might retry an operation using a state that another request has already changed.
None of these problems necessarily requires a model hallucination. The model may simply be working with the wrong context or an inconsistent view of the application. That is what makes concurrency failures in AI agents particularly interesting. They can look like reasoning failures when the underlying problem is ordinary software engineering.
The single-user testing trap
Most early agent development begins with one user, one conversation and one workflow. We submit a request, inspect the response and check whether the expected action occurred. If something goes wrong, we adjust the prompt, modify the tool or change the application logic.
This process is useful, but it does not tell us whether the system behaves correctly when multiple requests overlap. Consider two customers using the same support application.
- User A asks: "Where is my order?"
- User B asks: "Can I get a refund for my order?"
The agent should retrieve User A's order details for the first request and User B's purchase information for the second. Each conversation should have its own history, permissions and execution state.
Now, imagine the application stores the current conversation context in a shared variable. User A's request writes its context. Before the agent finishes processing it, User B's request overwrites that variable. When User A's workflow resumes, it may read User B's context.
The model did not necessarily make a reasoning mistake. The application supplied the wrong information. This is a classic shared-state race condition, but the consequences are more complicated when the shared state contains customer information, retrieved documents, tool arguments or instructions that influence an AI agent's next action.
The key lesson is that testing two users separately does not prove that their sessions remain isolated when they run together.
1. Shared memory collision: when one conversation enters another
One of the first places I would investigate is memory management. An agent application often maintains several kinds of state: conversation history, user preferences, task progress, retrieved information, intermediate reasoning data and tool execution results. These do not all have the same lifetime or ownership.
Some information belongs to a single message. Some belong to a conversation. Some belong to a user. Other information may be shared across an organisation. The problem starts when those boundaries are not explicit.
For example, an application might use a variable such as current_context to hold information for whichever request is being processed. That can appear to work in a sequential test because only one request uses the variable at a time.
Here is a deliberately simplified example in Python:
import asyncio
current_context = {}
async def handle_request(user_id, question):
global current_context
# Store the current user's context
current_context = {
"user_id": user_id,
"question": question
}
# Simulate an asynchronous model or tool call
await asyncio.sleep(0.1)
# Read the context after the wait
return {
"requested_by": user_id,
"context_used": current_context
}
async def main():
results = await asyncio.gather(
handle_request("user_A", "Where is my order?"),
handle_request("user_B", "Can I get a refund?")
)
for result in results:
print(result)
asyncio.run(main())
The important detail is that both requests can access the same global variable. The second request can replace its value while the first request is suspended.
The output can therefore associate one user's request with another user's context. This is a simplified demonstration of shared mutable state, not a complete production agent or a benchmark of a particular framework.
A straightforward improvement is to pass the context into the request handler rather than relying on a mutable global variable.
import asyncio
async def handle_request(user_id, question):
session_context = {
"user_id": user_id,
"question": question
}
await asyncio.sleep(0.1)
return {
"requested_by": user_id,
"context_used": session_context
}
async def main():
results = await asyncio.gather(
handle_request("user_A", "Where is my order?"),
handle_request("user_B", "Can I get a refund?")
)
for result in results:
print(result)
asyncio.run(main())
Each invocation now owns its local context. The example is intentionally small, but the design principle matters: request-specific state should be explicitly associated with the request that owns it.
In a real system, this responsibility extends beyond a local variable. Conversation storage, memory retrieval, cache keys, tool execution records and background jobs all need appropriate ownership boundaries.
A session identifier alone is not always enough. The application should also verify the authenticated user and tenant associated with that session. Otherwise, a caller might supply another session's identifier and access information that does not belong to them.
Memory isolation is not simply a matter of storing conversations separately. It is about enforcing ownership every time information is written, retrieved or reused.
2. Race conditions: when two agents update the same resource
The next problem is more subtle because it can occur even when user sessions are properly isolated.
Imagine two employees working with an AI agent that manages support tickets. Both employees opened the same ticket. One asks the agent to assign it to an engineer. The other asks the agent to mark it as resolved. Both requests read the ticket while its status is still OPEN.
The first request changes the assignee. The second changes the status. Depending on how the application saves these updates, one operation could overwrite the other. A simplified example looks like this:
import asyncio
ticket = {
"status": "OPEN",
"assignee": None
}
async def assign_ticket():
existing = ticket.copy()
await asyncio.sleep(0.1)
existing["assignee"] = "engineer_1"
ticket.update(existing)
async def resolve_ticket():
existing = ticket.copy()
await asyncio.sleep(0.1)
existing["status"] = "RESOLVED"
ticket.update(existing)
async def main():
await asyncio.gather(
assign_ticket(),
resolve_ticket()
)
print(ticket)
asyncio.run(main())
This example illustrates a lost-update problem. Both operations read an earlier snapshot and later write their own copy back. One update can erase the other.
The danger is not limited to support tickets. AI agents may update customer records, inventory, invoices, bookings, permissions or workflow states. When two requests operate on the same resource, the application must decide how concurrent changes are handled.
One approach is optimistic concurrency control. The application reads a resource version and only accepts an update if that version has not changed. For example, a database update might use a condition like:
UPDATE support_tickets
SET status = 'RESOLVED',
version = version + 1
WHERE ticket_id = 1042
AND version = 7;
If another operation has already changed the version, the update affects no rows. The application can then reload the current state and decide whether the requested action is still valid.
For workflows where operations must be coordinated, database transactions, row-level locking or carefully designed atomic operations may be more appropriate.
The important point is that the AI model should not be responsible for resolving a database race through better reasoning. The data layer must enforce the consistency rules.
An agent can propose an update, but the application must decide whether that update is valid against the latest state.
3. Context leakage: the problem can extend beyond conversation history
Shared memory is one risk. Retrieval introduces another.
Suppose an organisation uses a retrieval-augmented generation system to help employees answer questions about internal documents. Each user can access different records based on their role, department or customer assignment.
The system retrieves relevant documents and passes their contents to the model.
If access control is applied only after retrieval, or if cached results are reused without checking ownership, the model may receive information that the current user should never have seen.
This is particularly dangerous because the answer may look completely reasonable. It could contain accurate information from a real document, but that document was not authorised for the person asking the question.
There are several places where this boundary can break:
- A vector search retrieves documents without applying tenant or user permissions.
- A shared cache uses the question as its key but ignores the user's access scope.
- A background job reuses a previous request's retrieved context.
- A summarisation process combines documents from different permission groups.
- A conversation memory lookup retrieves records using an incomplete session identifier.
A retrieval query should enforce the relevant access constraints before the results reach the model. A simplified example:
def retrieve_documents(
query,
tenant_id,
allowed_document_ids
):
return vector_store.search(
query=query,
filters={
"tenant_id": tenant_id,
"document_id": {
"$in": allowed_document_ids
}
}
)
The exact filtering syntax depends on the vector database, but the principle is independent of the technology. Permissions should be enforced at the retrieval boundary, not left to the model to infer from the prompt.
Caching requires the same discipline. A cache entry should be scoped to the appropriate tenant, user or permission set. If permissions change, the cache must not continue serving content under an outdated access decision.
This is also why a prompt saying "only use documents the user is allowed to see" is not an adequate security control. The model should never receive restricted material in the first place.
A model cannot reliably protect a data boundary that the application has already crossed.
4. Duplicate execution: when a retry performs the same action twice
Concurrency also affects actions.
Imagine a user asks an AI agent to issue a refund. The agent calls a payment service. The payment service processes the refund, but the response is delayed or lost.
The agent does not know whether the operation succeeded. It sees a timeout and retries.
Meanwhile, another request may have triggered the same refund workflow. The system now has two attempts for what should have been one business operation.
This is not just a model problem. It is a distributed-systems problem involving uncertain outcomes. A timeout does not prove that an operation failed. It only tells the caller that it did not receive a response within the expected period.
The distinction matters:
-
FAILEDmeans the system has evidence that the operation failed. -
SUCCEEDEDmeans the system has evidence that it completed. -
UNKNOWNmeans the system cannot currently establish what happened.
Treating UNKNOWN as FAILED can lead to duplicate actions.
A common protection is an idempotency key. The application generates a unique identifier for the intended business operation and passes it to the service acting.
async def issue_refund(
payment_service,
order_id,
amount,
operation_id
):
return await payment_service.refund(
order_id=order_id,
amount=amount,
idempotency_key=operation_id
)
The payment service must support idempotency to provide the intended protection. Reusing the same key should identify the same logical operation rather than create a second refund.
In a production implementation, the application should also persist the operation identifier and its status. If a request times out, the workflow should check the existing operation before deciding whether another action is appropriate.
The agent should not independently invent a new operation identifier every time it retries. Doing so can turn one intended action into multiple distinct operations.
This is especially important when an AI agent can call external systems. The model may decide to retry, but the application needs a reliable execution protocol that protects the business operation.
5. Recovery failure: when the retry uses yesterday's state
The most interesting failure may happen after the first problem has already been detected.
Suppose an agent tries to update a booking. The operation times out. The workflow records the result as UNKNOWN. Before the agent retries, another user changes the booking.
The original request is now based on an outdated view of the resource.
If the agent simply repeats the earlier action, it may overwrite the newer change or execute something that is no longer appropriate. This is where recovery logic becomes as important as the original execution logic.
A safe recovery process should not assume that the state remains unchanged between attempts. It should retrieve the current resource state, verify that the original request is still valid and check whether the intended action has already occurred. The workflow can be expressed as:
REQUESTED
|
v
EXECUTING
|
+----> SUCCEEDED
|
+----> FAILED
|
+----> UNKNOWN
|
v
RECONCILE CURRENT STATE
|
+------+------+
| |
ALREADY DONE NOT COMPLETED
| |
v v
CONFIRM REVALIDATE
|
v
AUTHORISED RETRY
This is not a recommendation to retry every uncertain operation. Some operations need human review, particularly when they affect money, access rights, customer data or irreversible business processes.
The important distinction is between retrying an HTTP request and retrying a business decision. The first may be a technical operation. The second may require fresh evidence and authorisation.
An agent should not turn uncertainty into permission to try again.
6. Why adding more agents can make the problem harder
There is another architectural consideration. Many applications are moving from a single agent to systems where several agents handle different responsibilities.
One agent retrieves information. Another analyses it. A third calls tools. A coordinator manages the workflow.
This separation can be useful, but it also introduces more boundaries where the state can become inconsistent.
Imagine an agent retrieves a customer's account status. A second agent prepares a recommendation using that status. Before the third agent executes the recommendation, the account status changes.
The recommendation may have been valid when it was created, but invalid when the action is executed.
This is a time-of-check/time-of-use problem. The application checked a condition at one point and relied on it later without confirming that it was still true.
The solution is not necessarily to eliminate multi-agent architecture. It is to make the handoff explicit.
Each workflow step should carry enough information to identify the relevant user, tenant, task, resource version and authorisation scope. Before a consequential action, the system should verify that the state and permissions still match the conditions under which the action was approved.
A useful separation of responsibilities is:
- The retrieval component gathers authorised information.
- The reasoning component prepares a recommendation.
- The authorisation layer decides whether the action is permitted.
- The execution component performs the approved operation.
- The verification component checks what actually happened.
These responsibilities can exist in one service or several agents. What matters is that the boundaries remain enforceable even when requests overlap.
7. How I would test an agent for concurrent-user failures
This is where I would change the testing strategy.
Rather than testing only whether User A and User B can complete a workflow independently, I would create tests that deliberately overlap their requests.
I would start with two users and a small number of scenarios, then increase concurrency and complexity.
The first test should establish that the session context remains isolated. User A and User B should use different identifiers and different pieces of information. The test should verify that neither response contains information belonging to the other session.
The second test should create concurrent updates to the same resource. Both operations should attempt to change the resource from the same initial version. The application should reject or reconcile conflicting updates rather than silently overwrite one.
The third test should simulate a timeout after an external operation has completed. The retry should reuse the original operation identity and reconcile the outcome instead of acting again.
The fourth test should check retrieval permissions. Two users should query the same knowledge base with different access scopes. The test should verify that the returned documents, not just the final answers, respect those scopes.
Finally, I would test recovery. A request should be paused, the underlying resource changed by another operation, and the original request resumed. The system should detect the changed state and revalidate the action.
A small test matrix makes these requirements easier to maintain:
| Test | Failure being investigated | Expected behaviour |
|---|---|---|
| Concurrent sessions | Shared context | Each request uses its own context |
| Concurrent updates | Lost update | Version conflict is detected |
| Concurrent refunds | Duplicate action | One logical operation is executed |
| Permission-scoped retrieval | Cross-user data exposure | Only authorised documents are returned |
| Delayed retry | Stale state | Current state is checked before retry |
| Concurrent memory writes | Conflicting memory updates | Ownership and update rules are enforced |
I would also include both negative and positive replay tests.
Negative tests verify that the system blocks unauthorised access, duplicate execution and invalid state transitions. Positive tests verify that normal workflows still work after the security and concurrency controls are introduced.
That second part is easy to overlook. A fix that blocks every suspicious request may appear secure while making the application unusable. Every meaningful change should be tested against both the failure it is intended to prevent and the legitimate behaviour it must preserve.
For repeatability, I would record the test inputs, session identifiers, resource versions, execution IDs, expected outcomes and actual results. This makes it possible to compare behaviour after changes to the agent, database, retrieval layer or orchestration framework.
I would not claim that a system is concurrency-safe because it passed one two-user test. The goal is to build a growing set of repeatable tests that cover the boundaries where shared state and simultaneous execution can cause problems.
8. What should be logged when multiple users interact?
When a failure occurs, a log saying "agent returned the wrong answer" is not enough.
The investigation needs to establish which request used which context, which resource version was read, which documents were retrieved, which permissions were applied and whether another operation changed the state in between.
For each workflow, I would want to capture:
- A unique request and trace identifier.
- The authenticated user and tenant, subject to appropriate privacy controls.
- The conversation or session identifier.
- The resource identifier and version involved.
- The retrieval references and applied access policy.
- The tool call and business operation identifier.
- The execution status, including
UNKNOWNwhere appropriate. - Retry attempts and the reason each retry was permitted.
- The verification result after execution.
Sensitive information should not be copied indiscriminately into logs. The purpose is to make the workflow traceable without creating another place where private data can leak.
There is also a difference between logging that two requests happened and being able to reconstruct how they interacted. Distributed tracing and consistent correlation identifiers help connect events across the application, model service, retrieval system, database and external tools.
If the application cannot reconstruct which state a decision was based on, diagnosing a concurrency failure becomes guesswork.
9. The architecture matters more than the prompt
It is tempting to address every unexpected agent behaviour through prompt engineering. We see an incorrect response, add another instruction and expect the model to behave differently next time.
That approach has a place, but it cannot replace application-level controls.
A prompt cannot make a global variable session-safe. It cannot make a database update atomic. It cannot guarantee that two refund requests will execute only once. It cannot enforce tenant permissions if the retrieval service has already returned restricted documents.
These are properties of the surrounding system.
For a reliable multi-user agent, I would focus on a few architectural principles.
First, make ownership explicit. Every piece of user-specific context should have a clear owner and scope. Avoid shared mutable state for request-specific information.
Second, enforce access at the data boundary. Retrieval, memory and cache operations must apply the correct user and tenant permissions before information reaches the model.
Third, protect shared resources. Use transactions, atomic updates, optimistic concurrency controls or other mechanisms appropriate to the underlying data store.
Fourth, make business actions idempotent. A retry should not accidentally create a second payment, refund, booking or other consequential operation.
Fifth, verify before recovery. When an operation has an uncertain result, inspect the current state before deciding what to do next.
Finally, test concurrent workflows deliberately. A system that works for one user at a time has not yet demonstrated that it works for multiple users at once.
The failure may not belong to the model
I keep coming back to one distinction: an AI agent is not just a model responding to a prompt. It is a system that manages identity, context, memory, retrieval, permissions, execution and recovery.
When two users interact simultaneously, all those components must preserve the boundaries between their workflows.
The model may generate a perfectly reasonable answer based on the information it received. But if that information belongs to another session, the system has already failed. A tool may return a successful response, but if two requests caused the same business action to execute, the workflow has failed. A retry may complete successfully, but if it uses a resource state that has changed since the original decision, the outcome may still be wrong.
That is why I would not treat concurrency as a performance concern alone. It is also a correctness, privacy and authorisation concern.
The interesting question is not simply how many requests an AI agent can handle per second. It is whether the system can handle those requests without confusing who owns the information, which state is current and what action has actually been authorised.
A single-user demo can show that an agent knows how to complete a task. It cannot be proven that the agent can complete that task safely when other people are using the same system.
The real test of an AI agent begins when two users ask at once.
Top comments (0)