Skip to content
sync ai agents

Message ordering and duplicates between agents

Assume every message can arrive twice and out of order. Give each message a unique id and record the ids you have handled, so a repeat does nothing. Enforce order only inside one conversation, using a conversation id plus your own sequence number, and let unrelated conversations run in parallel. When a message arrives late, check the current task state before acting on it.

Why do agents receive duplicate and out-of-order messages?

Duplicates come from retries and from storage that keeps more than one copy. Amazon SQS, for example, says that on rare occasions, one of the servers storing a copy might be unavailable when you receive or delete a message. In that case you might get that message copy again. Its guidance is to design your applications to be idempotent.

Reordering comes from parallelism. When several agents work at once and report back over separate connections, replies finish in whatever order the work finishes. Unless one channel carries all of them in sequence, the receiver sees them in completion order, and your design has to say where the original send order matters.

How do I deduplicate by message id or task id?

Keep a store of ids you have already processed and check it before doing any work. Write the id and the result in one transaction, so a crash between the two cannot leave a half-recorded message.

In A2A, the Core Concepts page says each message carries a role and a unique messageId. That id is the natural dedup key for a repeated message.

Task ids behave differently. The specification says Task IDs are server-generated when a new task is created in response to a Message, and that client-provided taskId values for creating new tasks are not supported. A client therefore cannot make task creation idempotent by picking the id. It needs its own retry key. Before resending, it can check existing tasks, since ListTasks can filter by contextId to return tasks from one conversation or session.

The IETF asks that drafts be cited only as work in progress.

The draft says the key must not be reused with a different request payload, and it recommends a UUID or a similar random identifier as the key.

How long should I remember ids?

Remember ids longer than your longest retry window, and no longer than you can afford to store. Stripe's API reference gives one concrete setting. For API v1, it says you can remove keys automatically once they are at least 24 hours old, and Stripe will generate a new request if a key is reused after the original is pruned. A dedup table with an expiry has the same edge, so set the expiry above your maximum redelivery delay.

Stripe's idempotency layer also compares incoming parameters to the original request and errors if they are not the same. Your own store can run the same check, so a reused id with a changed payload fails loudly instead of returning a stale result.

If other agents call yours, publish the window. The IETF draft says a resource should define its expiration policy and publish it in the documentation.

How do I keep order within one conversation?

Scope ordering to one conversation and attach a sequence number you control. On the receiving side, track the last number applied per conversation and handle each incoming message in this order.

  • If its number is at or below the last applied number, drop it as a repeat.
  • If it is the next number, apply it and advance the counter.
  • If it skips ahead, hold it until the missing message arrives or a timeout fires, then decide whether to fetch the missing state or fail the conversation.

A2A supplies the grouping key. The specification says a contextId logically groups multiple Task objects and Message objects that are part of the same conversational context.

Agents also must reject messages containing mismatching contextId and taskId values, so a message that names a task from another conversation is refused.

Amazon SQS FIFO queues order messages based on their message group ID. Within a group, all messages are sent and received in strict order, while messages with different message group IDs may arrive or be processed out of order relative to one another.

What does A2A guarantee about event order?

Within a task's stream, the A2A specification says all implementations must deliver events in the order they were generated, and events must not be reordered during transmission. When several streams are open for one task, each stream must receive the same events in the same order.

Plan your own sequence numbers for order across different tasks, or between a stream and a separate webhook. A late message to finished work gets an error, because the specification says tasks in a terminal state such as TASK_STATE_COMPLETED or TASK_STATE_FAILED cannot accept further messages, and it lists this case under UnsupportedOperationError.

How do I handle duplicate push notifications?

Treat a push notification as a hint and fetch the current state. The A2A streaming guide says that after verifying a notification, the client typically uses the GetTask RPC method with the taskId to retrieve the complete, updated Task object. A duplicate or late notification then costs one extra read.

Its replay-attack guidance adds two checks. Notifications should include a timestamp, and the webhook should reject ones that are too old. For critical notifications, the guide suggests considering unique, single-use identifiers such as event IDs to prevent processing duplicate notifications.

What should happen to messages that keep failing?

Move them aside after a bounded number of tries, and think twice before doing that on an ordered conversation. In Amazon SQS, a redrive policy sets the maxReceiveCount, the number of times a consumer can receive a message before it moves to a dead-letter queue. Dead-letter queues let you isolate unconsumed messages to determine why processing did not succeed.

The same documentation warns against using a dead-letter queue with a FIFO queue if you don't want to break the exact order of messages or operations.

For agents, a poisoned message in an ordered conversation either blocks the conversation or gets skipped, and you should choose which on purpose. If retries start to circle, see preventing agent loops. For tracing a lost message, see debugging multi-agent systems, and the event-driven pattern page covers the wider design.

Which sources does this page use?

What do people ask about message ordering and duplicates between agents?

Updated November 2026

Not sure which pattern fits?

Six questions, about a minute. You'll get a pattern, a shortlist and the tradeoffs.

Take the finder

Which related questions can you explore next?