# Under what conditions must an instance reject a duplicate A2A v1.0 `TaskStatusUpdateEvent` rather than acknowledge it as an idempotent replay **Date of Record:** 2026 November 26 **Scope:** Applies to A2A v1.0 servers that emit `tasks/sendSubscribe` SSE streams and maintain a server-side task state machine keyed by `taskId`. Does not apply to stateless one-shot `tasks/send` calls, nor to transport-level retries that never reach the state machine (e.g., TCP reconnect handled by an intermediary proxy). ## Core Distinction Idempotency is a property of an *effect*, not of a *message*. A2A's streaming lifecycle makes it tempting to treat any `TaskStatusUpdateEvent` carrying a `(taskId, status.state)` pair identical to the last acknowledged one as a harmless retransmission and to answer it with `200 OK` / re-emit the cached terminal event. That reasoning conflates two distinct things: **transport-level duplicate delivery** (the same logical event arriving twice) and **state-machine-level duplicate transition** (a distinct event whose payload happens to share a state label with a prior one). The invariant that must hold is: > A status transition is idempotent only if `(taskId, fromState, toState, eventId)` is identical. Two events that share `toState` but differ in `eventId`, `timestamp`, `final`, or attached `artifact`/`message` payloads are *distinct transitions*, and one of them is almost always a protocol violation by the peer. The non-obvious failure: acknowledging the second event silently *advances the peer's belief* that the server has processed a transition it never applied, because the server's terminal-state guard (e.g., `COMPLETED → COMPLETED` is a no-op) swallows a payload-bearing event that the peer believes changed the task's output. ## What Was Observed A planner agent (client) drives a worker agent (server) over `tasks/sendSubscribe`. The worker's executor loop emits status events from two concurrent coroutines: a heartbeat coroutine that re-emits the current state to keep the SSE connection warm, and a transition coroutine that mutates state and emits a new event. Both share a single `emit()` function with no serialization. Observed trace during a 40-minute task: 1. `t=0.00` transition coroutine: `WORKING → WORKING` with `artifact={chunk: 17}`, `eventId=E-881`, `final=false`. 2. `t=0.02` heartbeat coroutine reads stale `current_state=WORKING` from a lock-free snapshot and emits `WORKING → WORKING` with `artifact=null`, `eventId=E-882`, `final=false`. 3. Client receives E-881, applies chunk 17, then receives E-882. Client's dedup layer sees `(taskId, WORKING)` matching the last seen state and **drops E-882 as a replay** — correct behavior on the client side. 4. But the client's ack for E-882 was already in flight (it acks on receipt, before dedup). The server's `emit()` sees the ack for E-882 and marks E-882 as *delivered and confirmed*, then garbage-collects the pending-event buffer entry for E-881 (same `toState`, assumed superseded). 5. On SSE reconnect at `t=14:03`, the client requests `Last-Event-ID: E-882` (its last *received*, not last *applied*). The server replays from E-882 forward. **E-881 is gone from the buffer.** Chunk 17 is never redelivered; the client's task state machine believes `WORKING` with an empty artifact set, while the server believes `WORKING` with chunk 17 applied. 6. The divergence is only detected at `COMPLETED`, when the client's assembled output is missing one chunk and the server's `final` artifact hash does not match the client's. The failure surfaces as a *content* mismatch, not a *state* mismatch, which is why state-only conformance tests pass. The root cause is that the server treated `(taskId, toState)` as the idempotency key for its pending-event buffer, while the client treated the same key as its dedup key. Both are wrong under A2A v1.0, which requires `eventId` to be the sole replay identity and requires `Last-Event-ID` to reference the last *contiguously applied* event, not the last received. ## Condition of Validity The "acknowledge duplicate" behavior is valid **only** when all four of the following hold: - **C1 (Identity):** the incoming `eventId` equals a previously acknowledged `eventId` for the same `taskId`. Equal `toState` alone is insufficient. - **C2 (Payload equivalence):** the `status`, `final`, `artifact`, and `message` fields are byte-identical to the buffered event with that `eventId`. If they differ, the peer has reused an `eventId` — a hard protocol violation, not a duplicate. - **C3 (Monotonicity):** the incoming event's `eventId` is not *older* than any event the server has already advanced past in its own state machine. An event that arrives after the server has transitioned beyond its `toState` is a stale replay, not a duplicate, and must be answered with the current state rather than the cached event. - **C4 (Contiguity):** the server's pending-event buffer still contains the event, and the gap between the client's `Last-Event-ID` and the server's head is fully buffered. If any buffer entry has been evicted, the server cannot prove idempotency and must fail the stream with a resync signal. If C1 fails (different `eventId`, same `toState`), the event is a **new transition** and must be applied, not deduplicated. If C1 holds but C2 fails, the event is **poisoned** and must be rejected. If C1 and C2 hold but C3 or C4 fails, the event is a **stale or unrecoverable replay** and must trigger a stream reset, not a silent ack. ## Decision Boundary The boundary between "acknowledge" and "reject" is not the state label — it is the tuple `(eventId, payload_hash, buffer_contiguity)`. Concretely: | Condition | Server action | Client-visible result | |---|---|---| | C1 ∧ C2 ∧ C3 ∧ C4 | Ack, re-emit cached event, no buffer mutation | True idempotent replay | | ¬C1 (new `eventId`, same state) | Apply transition, append to buffer | New event delivered | | C1 ∧ ¬C2 (same `eventId`, different payload) | **Reject** with `INVALID_EVENT_ID_REUSE`, terminate stream | Peer must resync from scratch | | C1 ∧ C2 ∧ ¬C3 (stale replay past head) | Re-emit current state, do **not** rewind state machine | Peer sees current state, not stale | | C1 ∧ C2 ∧ C3 ∧ ¬C4 (buffer gap) | **Fail stream** with `REPLAY_UNAVAILABLE`, force `tasks/get` resync | Peer must re-fetch authoritative state | The critical guardrail: **the pending-event buffer must be keyed by `eventId`, never by `toState`.** A state-keyed buffer is the single most common conformance defect in A2A v1.0 implementations, and it is invisible to state-only conformance suites because every state transition still appears to succeed. ## Operational Effect When the state-keyed buffer is replaced with an `eventId`-keyed buffer plus the C1–C4 gate, three things change operationally: 1. **Reconnect cost rises.** Clients that previously reconnected with `Last-Event-ID` pointing at a deduped state must now reconnect with the last *applied* `eventId`. Servers must therefore persist the applied-event cursor on the client side, not just the last received one. This adds one field to client task state and one round-trip on reconnect when C4 fails. 2. **Poisoned-event detection becomes possible.** `eventId` reuse with divergent payloads is now caught at the server rather than manifesting as a silent content mismatch at `COMPLETED`. The failure moves from "wrong output, no error" to "explicit `INVALID_EVENT_ID_REUSE`, task fails fast" — strictly better for auditability. 3. **Heartbeat coroutines must be demoted.** A heartbeat that re-emits the current state with a fresh `eventId` is now a *new transition* under C1, which means it pollutes the buffer and advances the client's cursor. Heartbeats must either reuse the last `eventId` (true replay, C1∧C2) or be moved off the status-event channel entirely (e.g., SSE comment frames). The lock-free snapshot read that produced the stale `WORKING` in the trace above is no longer a correctness hazard *only if* the heartbeat path is removed from the transition channel. The invariant to encode in conformance tests: **for any task, the sequence of `eventId`s delivered to a client across reconnects must be exactly the sequence of applied transitions, with no gaps and no reordered payloads.** State-equality assertions are insufficient; the test must assert event-identity contiguity. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class A2AConformanceError(RuntimeError): """Raised when an A2A v1.0 status event cannot be safely acknowledged.""" class EventIdReuseError(A2AConformanceError): """Same eventId, divergent payload — peer violated event identity.""" class ReplayUnavailableError(A2AConformanceError): """Last-Event-ID references an evicted buffer entry; resync required.""" @dataclass class StatusEvent: task_id: str event_id: str state: str final: bool artifact: Optional[bytes] = None message: Optional[str] = None def payload_hash(self) -> str: h = hashlib.sha256() h.update(self.state.encode()) h.update(b"\x00") h.update(b"1" if self.final else b"0") h.update(b"\x00") h.update(self.artifact or b"") h.update(b"\x00") h.update((self.message or "").encode()) return h.hexdigest() @dataclass class PendingBuffer: # Keyed by eventId, NEVER by toState. entries: dict[str, StatusEvent] = field(default_factory=dict) applied_cursor: Optional[str] = None def acknowledge(self, incoming: StatusEvent) -> str: """Return 'replay' | 'applied' | raise on violation.""" prior = self.entries.get(incoming.event_id) # C1: identity match? if prior is not None: # C2: payload equivalence? if prior.payload_hash() != incoming.payload_hash(): raise EventIdReuseError( f"eventId={incoming.event_id} reused with divergent payload " f"for taskId={incoming.task_id}" ) # C3: not older than applied cursor? if self.applied_cursor is not None and incoming.event_id < self.applied_cursor: # Stale replay: re-emit current state, do not rewind. return "stale_replay" # C4: still buffered (it is, by construction of `prior`). return "replay" # C1 fails: new transition. Append and advance cursor. self.entries[incoming.event_id] = incoming self.applied_cursor = incoming.event_id return "applied" def replay_from(self, last_event_id: str) -> list[StatusEvent]: if last_event_id not in self.entries: raise ReplayUnavailableError( f"Last-Event-ID={last_event_id} not in buffer; " f"contiguity broken, client must resync via tasks/get" ) ids = sorted(self.entries) idx = ids.index(last_event_id) return [self.entries[i] for i in ids[idx + 1:]] def handle_stream_event(buf: PendingBuffer, ev: StatusEvent) -> str: result = buf.acknowledge(ev) if result == "replay": # Re-emit cached event; no buffer mutation. return "200 OK (replay)" if result == "stale_replay": return "200 OK (current state, no rewind)" return "200 OK (applied)" ```