AI Agent Concurrency: Locks, Leases, and Shared Work
How to keep parallel AI agent runs from colliding by using ownership, locks, leases, idempotency, checkpoints, and conflict-aware handoffs.

AI agents rarely operate alone for long. Several runs may pull from the same queue. A person may edit a record while an agent prepares an update. Two delegates may inspect the same ticket. A scheduled run may overlap with a manual run. A coding agent may work in a repository while another process regenerates files. Even when every individual step looks reasonable, shared work can collide.
Concurrency design is the practice of deciding who owns a piece of work, how long that ownership lasts, what happens when it expires, and how conflicts become visible. It is closely related to AI Agent Coordination and AI Agent Retries and Idempotency , but it deserves its own attention. Coordination describes how delegates share work. Idempotency prevents repeated side effects. Concurrency decides what happens when more than one actor reaches for the same work at the same time.
Shared Work Needs Ownership
A task that belongs to everyone belongs to no one. If a queue item can be opened by any agent at any time, the workflow needs a way to mark that one run has taken responsibility for it. Otherwise the system can produce duplicate drafts, conflicting updates, repeated messages, or confusing handoffs.
Ownership does not have to mean exclusive control forever. It can mean that one run has the current lease on a ticket, one branch carries a code change, one reviewer owns the approval, or one agent lane is responsible for a source-gathering step. A visible assignment helps actors avoid overlap, but it is not an enforced lock: another branch or person can still change the same target.
AI Agent State Management provides the vocabulary. A state like running is too vague when several runs might be involved. The workflow may need states such as claimed, leased, waiting on review, applying, stale lease, conflict detected, or handed off. Those states tell people and agents whether they can safely proceed.
Locks Protect Consequential Work
A lock is a boundary around work that should not be changed by two actors at once. It may protect a file, record, queue item, draft, approval request, browser session, or generated artifact. Without a lock, two runs may each behave correctly from their own perspective while producing a broken combined result.
Consider a support workflow. One agent prepares a reply while another updates the customer classification. If the classification changes after the reply is drafted, the reply may use the wrong policy. In a content workflow, one delegate may rewrite a page while another changes the source reference. In a repository, two agents may edit the same file from different assumptions. The lock does not solve the task. A correctly enforced lock can prevent cooperating actors from applying incompatible changes at the same time; it cannot protect against a writer that bypasses it.
Locks should be narrow and understandable. Locking an entire system because one agent is drafting one update creates unnecessary queues. Locking the exact record, artifact, or action target keeps the boundary useful. Choose a shared key for the thing that can conflict: two different queue messages about ticket 4821 should use the same ticket key. If an operation must change several records together, a lock on only one may be too narrow; protect the invariant across the whole operation. AI Agent Cost, Latency, and Queues matters because broad locks can turn safety into hidden delay.
When several locks are necessary, acquire them in a consistent order and handle timeouts or aborted transactions. Otherwise two workers can each hold one lock while waiting for the other. PostgreSQL’s locking documentation describes this deadlock and the consistent-order practice for its database locks. Avoid holding a database transaction open through model generation or a human review; save the intermediate work, then recheck state in a short transaction at commit time.
Leases Prevent Permanent Claims
Locks create another problem: abandoned ownership. An agent can crash, lose access, wait too long for a tool, or be stopped during review. If its lock never expires, the work can remain frozen. A lease solves this by making ownership time-bound and renewable.
A useful lease says which actor owns the work, when the claim began, when it expires, what condition allows renewal, and what should happen when the lease becomes stale. The agent should renew only while it is still making progress and still has authority. If the run is blocked, waiting for a human, or paused by policy, the lease may need a different state rather than quiet extension.
A claim must be acquired atomically in a shared, authoritative store. Reading “unclaimed” and then writing a claim in separate steps lets two workers both believe they won. Use a transaction, conditional update, or coordination service that grants the claim to one contender. Record the target, owner or run ID, expiry, and a claim generation; use the store’s time and expiry rules rather than assuming worker clocks agree. Renew only if the owner and generation still match and the lease has not expired; an expired owner must acquire a new claim rather than revive the old one. Release conditionally on the owner and generation, so an old worker cannot release a newer claim. Keep generations increasing across release and reacquisition, including after process restarts.
Choose the lease duration against expected work and recovery time: a short lease recovers abandoned work sooner but needs more frequent renewal; a long one delays takeover. If renewal fails or ownership is uncertain, stop initiating protected actions and reconcile any call already in flight. Release the lease when the protected step finishes; a long human review can instead have an explicit waiting state, followed by a fresh claim and recheck before execution.
Leases connect to AI Agent Checkpoints because an expired lease should not erase progress. If another delegate takes over, it needs the prior run’s evidence, partial artifact, validation results, and open questions. Otherwise lease expiration turns into repeated work.
An Expired Worker Can Still Write
Expiration makes a claim available for reassignment; it does not stop the old process or cancel a request already in flight. Imagine worker A holds ticket 4821, pauses, and loses its lease. Worker B acquires the ticket and updates it. A then wakes up with its old draft. A lease check made before the pause cannot protect B’s work.
The protected write needs enforcement at the destination. One approach is a fencing token: the claim service assigns a monotonically increasing generation to each new owner, and the destination atomically rejects writes with a token older than the highest token it has accepted. This only fences the old worker after the destination has seen the newer token; merely granting B a lease does not tell the destination about B. If writes must be rejected immediately after expiry or takeover, the destination needs an atomic check against the authoritative current ownership and expiry, or an equivalent enforced protocol. Another approach, where the state and claim live in the same transactional store, is to check the current owner, generation, unexpired lease, and expected target version in the same transaction as the update. Every relevant writer must participate, including human-facing tools, or use a compatible version check.
A version check protects a different boundary: it rejects an update if the record has changed since it was read, including a human edit. For example, Google Cloud Storage’s generation-match preconditions allow a write or delete only when the object has the expected data generation. If the decision also depends on object metadata, use the applicable metageneration condition as well. A failed condition is a conflict to inspect, not a reason to overwrite the latest version. A version check alone does not prove that a lease is still valid when the target has not changed.
A lock service cannot enforce a fencing token at an unrelated external API unless that destination, or a gateway that controls all writes to it, actually checks the token at the action boundary. A check in the agent immediately before a call still leaves a race. If the destination offers no conditional write, fencing, or reliable deduplication, do not claim exclusive execution is guaranteed; use the service’s available controls, reconciliation, and human review where needed.
A Claim-to-Handoff Example
A support team allows an agent to prepare a reply to ticket 4821. The following is an illustrative flow, not a claim about a particular queue or ticket system:
- The worker atomically claims the ticket for its run and receives generation 12 and an expiry. It reads ticket revision 8 and prepares draft revision 3.
- A reviewer approves that draft for that ticket. While waiting, the workflow saves a checkpoint and releases the claim. The approval identifies the draft and its intended action.
- Before sending, a worker claims the ticket again, rereads its state, and checks that the approval, draft, recipient, and ticket revision still apply. If a person answered or edited the ticket, the worker stops for review.
- The sending boundary enforces the available ownership and version conditions and uses a stable action ID if the service supports it. The worker records the receipt, then conditionally releases its own claim. A timeout after sending is an unknown outcome: check the service for the action before attempting it again. If the service cannot reveal the outcome or safely deduplicate a retry, pause for reconciliation rather than assume the send failed.
For queue-driven work, receiving a message is not necessarily an exclusive claim on the underlying ticket. Amazon SQS visibility timeouts , for example, make a received message temporarily invisible, but delivery can still be duplicated even during the timeout. A separate claim and safe action boundary may therefore be needed for the shared target. Acknowledge or delete the queue message only after the workflow has durably recorded the outcome it needs for recovery.
Idempotency Handles Ambiguous Action
Concurrency often produces ambiguous action. Did the first run send the message, or did it only draft it? Did the record update happen before the timeout? Did another worker already apply the same change? Is this retry new work or the same work continuing?
Idempotency keys and stable action IDs help answer those questions. If an agent prepares or applies an action, the workflow should be able to recognize that action later. A service that implements idempotency can recognize a repeated request with the same key and return the earlier result rather than repeat the side effect, subject to its documented scope and retention period. The key alone does not prevent a different action from racing on the same target; use a version or ownership check for that. Keep the same key and request for retries of the same intended action; use a new key for a genuinely new action. Record the key before sending so it survives a crash. Check the provider’s rules for parameter matching, retention, and returned errors: for example, Stripe’s API v1 idempotency documentation explains that a pruned key can be treated as a new request. A superseded or conflicting action should be rejected or marked for review.
If an external service accepts an action but the worker crashes before saving the receipt, a local claim or checkpoint cannot prove whether it happened. Store an intent before the call and the receipt afterward, then reconcile an unfinished intent against the service. An outbox can make an intent durable with a local state change, but the dispatcher can still retry; safe delivery depends on the destination’s deduplication or on reconciliation.
AI Agent Output Verification should check the actual state, not only the agent’s final statement. In concurrent systems, “I updated the record” is not enough. The reviewer needs to know which record, which version, which prior state, which action ID, and whether the update still matches the approved artifact.
Human Work Is Part Of The Race
Concurrency is not only an agent-to-agent problem. Humans are actors in the same system. A reviewer may edit the artifact while the agent is still refining it. A support representative may answer the ticket manually while an agent prepares a draft. An engineer may push a commit while a coding agent builds on an older branch. A manager may approve one version of a message while the agent later changes it.
The workflow should treat human changes as first-class events. If a person updates the target record, the agent may need to refresh context. If a person changes the draft, the agent should not overwrite the edit without explicit permission. If a person approves an artifact, later changes should invalidate or at least flag that approval. Human Review for AI Agents becomes stronger when the review moment is protected from silent revision.
This is where control surfaces matter. AI Agent Control Surfaces should show who owns the work, whether another actor has touched it, and what will happen if the reviewer approves. A person should not have to infer concurrency from scattered timestamps.
Conflicts Should Become Artifacts
When a conflict occurs, the agent should not simply choose a winner and continue. Some conflicts are easy to resolve, but the resolution should still be visible. Others require judgment. A source changed after drafting. A queue item was handled by someone else. A file was edited in the same area. A lease expired while a tool result was pending. A human approval applies to an old version.
The conflict itself should become a reviewable artifact. It should name the target, competing versions, timing, affected action, and safest next step. AI Agent Artifact Design provides the larger pattern. A conflict note is a small artifact that prevents a messy race from disappearing into a transcript.
Conflict artifacts also help improve the runbook. If the same kind of conflict repeats, the workflow may need a narrower lock, a better trigger, a different queue policy, or a clearer handoff. AI Agent Runbooks should absorb those lessons so each conflict does not become a custom rescue.
Test The Collision And The Recovery
Before relying on the design, run a small failure exercise against a safe test target. Start two workers at the same time and verify that only one acquires the claim. Pause the winner past expiry, let another worker take over and commit a protected write, then resume the first: its protected write and release must be rejected. If the design promises to reject writes immediately on expiry or takeover, test that boundary before the new worker writes as well. Edit the target as a human between draft and commit and confirm the version check surfaces a conflict. Interrupt a send after the external service accepts it but before the receipt is saved; verify that recovery checks the outcome and does not blindly send again.
Also test failed renewals, a review that outlives the lease, and an approval for an older draft. Record whether each case resumes, waits, or needs a person, and monitor expired claims, renewal failures, conflict rates, and time spent waiting. These checks turn AI Agent Runbooks into procedures a team can actually use.
Design For The Boring Collision
Concurrency problems do not usually announce themselves dramatically. They look like duplicate replies, stale drafts, overwritten files, approval confusion, inconsistent records, or work that seems to vanish because another actor completed it first. The failure is boring, which is why it needs boring controls.
Enforced locks protect work that should not be changed concurrently. Leases let abandoned claims expire, while destination checks reject stale work. Ownership tells actors where responsibility sits. Idempotency controls can prevent repeated side effects within their documented scope. Checkpoints preserve continuity when work moves. Conflict artifacts make collisions reviewable. None of these controls makes agents intelligent. They make shared work survivable.
The practical goal is not to serialize everything. It is to let parallel work happen where it is safe and make overlap visible where it is not. An agent program that grows beyond one delegate needs this discipline early. Otherwise scale does not produce more throughput. It produces more ways for correct local behavior to combine into wrong shared state.
Written By
JJ Ben-Joseph
Founder and CEO · TensorSpace
Founder and CEO of TensorSpace and the editor of Fondsites: an engineer working across software, AI, cybersecurity, and biosecurity who builds the site's games and tools.