# Why does an instance accept a terminal `completed` task and then overwrite it with a late `working` update after a push-notification replay? **Date of Record:** 2026 November 29 **Scope:** Applies to A2A v1.0 task lifecycle transitions when a client agent reconciles task state delivered via push-notification webhooks against state pulled from the remote agent's `tasks/get` endpoint, specifically when webhook delivery is retried or replayed after the task has already reached a terminal state. Does not apply to synchronous `message/send` blocking calls, nor to tasks whose `TaskStatus.state` never leaves `working`/`input-required`. ## Core Distinction A2A v1.0 treats the *task state machine* and the *push-notification transport* as two independent contracts that share a `taskId` but have no shared ordering guarantee. The task lifecycle is monotonic: `submitted → working → (input-required ⇄ working) → completed | failed | canceled`. The webhook contract is at-least-once delivery with no guaranteed ordering across retries. The failure lives precisely in the seam: the protocol specifies legal *states* and legal *transitions*, but it does not carry a monotonic transition counter or a per-notification sequence number that a receiver can use to reject an out-of-order delivery. A replayed `working` notification that was emitted *before* `completed` can arrive *after* the client has already recorded `completed`, and nothing in the payload's structure lets the receiver distinguish "stale replay" from "the agent genuinely regressed the task." This is not a transport bug. It is a missing invariant: the terminality of a task is enforced only by the *sender's* state machine, not by the *receiver's* reconciliation logic. The receiver must reconstruct monotonicity from data the protocol does not provide. ## What Was Observed A client orchestrator subscribes to `tasks/pushNotificationConfig` for a long-running research task. The remote agent emits three webhook POSTs: `working` (t=0), `working` (t=40s, progress update), `completed` (t=90s). The receiver records states in order and marks the task terminal at t=90s, then fires downstream actions (distillation into episodic memory, releasing a downstream dependency). At t=120s the receiver gets a *fourth* POST: a `working` status with `final: false` and a `status.timestamp` of t=38s. This is a retry of the second notification — the remote agent's webhook dispatcher retried after a 5xx from the receiver's edge (a transient, not a rejection). The receiver's handler does not compare `status.timestamp` against the recorded terminal timestamp; it applies the update, transitions the task back to `working`, and — critically — re-opens the downstream dependency that had already been released and re-runs the distillation step against a `working` task with no result artifact. Observed downstream symptoms, in the order they surfaced: 1. **Double distillation.** The episodic-to-semantic distillation ran twice: once on the `completed` artifact, once on the replayed `working` state (which carried a partial artifact). The semantic store ended with two conflicting summaries keyed to the same `taskId`, the second overwriting the first with a *less complete* record. This is the memory-layer manifestation of the bug: a late, lower-fidelity state clobbering a higher-fidelity terminal one. 2. **Dependency re-release.** The released dependency re-armed, causing a second agent to re-issue work already done. That agent's `tasks/get` returned `completed` (the remote's authoritative view), so it discarded its own re-issued work — but only after spending tokens on it. 3. **Auditor disagreement.** A verification agent that polls `tasks/get` saw `completed` and signed off; the orchestrator's local state said `working`. The two agents disagreed about the same `taskId` for 40 seconds until a manual reconciliation. The trigger condition is narrow but not rare: *any* webhook retry, *any* duplicate delivery from an at-least-once dispatcher, *any* network reordering where a `working` notification is delayed past a subsequent `completed`. The receiver's state machine has no way to reject the late update because it never recorded *when* terminality was reached in a form the payload can be compared against. ## Condition of Validity The invariant that must hold for a receiver to safely apply a webhook status update is: > A status update `u` may be applied to local task `T` iff `u.status.timestamp > T.terminal_timestamp` OR `T` is not terminal. Once `T` is terminal, any update with a timestamp `≤ T.terminal_timestamp` is a replay and MUST be discarded (not applied, not logged as a state change, not used to re-arm dependencies). This holds only if the sender populates `status.timestamp` with a monotonically non-decreasing clock *and* the receiver persists the terminal timestamp atomically with the terminal state. In A2A v1.0, `status.timestamp` is an ISO-8601 string with no mandated clock source or skew bound — two agents on different hosts can produce timestamps that violate wall-clock ordering under NTP skew. So the timestamp guard is *necessary but not sufficient*; it must be paired with a monotonic local guard (the receiver's own record of "I have already observed terminal for this taskId") that is checked *first*. The condition fails when: (a) the receiver applies updates by blind overwrite (last-writer-wins on the state field), (b) the receiver treats `final: false` as "not yet terminal" without checking its own terminal record, or (c) the receiver's terminal record and its state field are written non-atomically, so a crash between the two leaves a task that is terminal in one store and `working` in another. ## Decision Boundary The boundary is between two receiver postures: - **Optimistic reconciliation** (apply every update, trust the sender's ordering): correct only when the transport guarantees exactly-once, in-order delivery. A2A push notifications do not. This posture is invalid for any receiver that acts on state transitions. - **Terminal-locked reconciliation** (once terminal, only accept updates with strictly greater timestamp *and* a matching transition counter if present): the required posture. The lock must be acquired atomically with the terminal write, and the replay check must run before any side effect (distillation, dependency release, memory write). The decision boundary is crossed the moment a receiver performs a side effect on a state transition without first verifying that the transition is *newer than the last observed terminal state for that taskId*. The side effect is the point of no return; the guard must precede it. A receiver that logs the replay but still fires the dependency is *outside* the boundary — logging is not guarding. There is a second, subtler boundary: the receiver must not treat `tasks/get` as a fallback that "corrects" the webhook state *after* the side effect. In the observed incident, a `tasks/get` reconciliation ran at t=130s and restored `completed`, but the double distillation had already committed. Post-hoc correction is not a substitute for pre-side-effect guarding, because the side effect is not idempotent (distillation overwrote a higher-fidelity record with a lower-fidelity one). ## Operational Effect The practical consequence is that **terminality is a receiver-side invariant, not a sender-side guarantee.** An A2A client that acts on task state must maintain a per-`taskId` terminal record that is written atomically with the terminal state, checked before every webhook application, and never cleared. The record must store the terminal timestamp and, where the sender provides it, the terminal transition's sequence or version, so that a replay with an equal-or-earlier timestamp is rejected without inspecting the state field. The guard costs one atomic compare-and-set per webhook delivery and one persisted field per task. The failure it prevents costs duplicate token spend, corrupted semantic memory (lower-fidelity overwriting higher-fidelity), and auditor/orchestrator state divergence that requires manual reconciliation. For any agent that distills task results into long-term memory or releases downstream dependencies on completion, the guard is not optional — it is the only thing standing between an at-least-once transport and a non-idempotent side effect. ```python import time from dataclasses import dataclass, field from typing import Optional class StaleTaskReplayError(RuntimeError): """Raised when a webhook status update would regress a terminal task.""" @dataclass class TaskRecord: task_id: str state: str = "submitted" terminal_timestamp: Optional[float] = None # monotonic seconds terminal_state: Optional[str] = None TERMINAL_STATES = {"completed", "failed", "canceled"} class TerminalLockedReconciler: """ Applies A2A v1.0 push-notification status updates under a terminal lock. Rejects any update that arrives after terminality unless it is strictly newer. """ def __init__(self): self._records: dict[str, TaskRecord] = {} def _record_for(self, task_id: str) -> TaskRecord: if task_id not in self._records: self._records[task_id] = TaskRecord(task_id=task_id) return self._records[task_id] def apply_update( self, task_id: str, new_state: str, update_timestamp: float, *, is_final: bool, ) -> TaskRecord: rec = self._record_for(task_id) # Guard runs BEFORE any side effect. Terminality is checked first, # independent of the payload's own `final` flag, because a replayed # `working` notification carries final=False and would otherwise pass. if rec.terminal_timestamp is not None: if update_timestamp <= rec.terminal_timestamp: raise StaleTaskReplayError( f"task {task_id}: replayed update state={new_state!r} " f"ts={update_timestamp} <= terminal_ts={rec.terminal_timestamp} " f"(terminal_state={rec.terminal_state!r}); discarding" ) # A strictly newer update after terminality is itself a protocol # violation — terminal states are absorbing in A2A v1.0. raise StaleTaskReplayError( f"task {task_id}: update after terminality with ts={update_timestamp} " f"> terminal_ts={rec.terminal_timestamp}; terminal is absorbing" ) # Non-terminal path: apply the transition. rec.state = new_state if new_state in TERMINAL_STATES or is_final: # Atomic-with-state terminal write: timestamp and state together. rec.terminal_timestamp = update_timestamp rec.terminal_state = new_state return rec def side_effect_guard(self, task_id: str, expected_terminal: str) -> None: """Call immediately before any non-idempotent side effect.""" rec = self._record_for(task_id) if rec.terminal_timestamp is None or rec.terminal_state != expected_terminal: raise StaleTaskReplayError( f"task {task_id}: side effect for {expected_terminal!r} blocked; " f"local state={rec.state!r} terminal={rec.terminal_state!r}" ) def handle_push_notification(reconciler: TerminalLockedReconciler, payload: dict) -> None: task_id = payload["taskId"] status = payload["status"] try: reconciler.apply_update( task_id=task_id, new_state=status["state"], update_timestamp=status["timestamp"], is_final=status.get("final", False), ) except StaleTaskReplayError: raise # replays are dropped at the edge, never re-applied if status["state"] == "completed": reconciler.side_effect_guard(task_id, "completed") # distill_to_semantic_memory(task_id) # only reachable under the lock ```