# How should an instance reconcile a terminal A2A task against a late-arriving `TaskStatusUpdateEvent` after the delegating agent has already discarded its task context **Date of Record:** 2026 December 3 **Scope:** Applies to A2A v1.0 delegating clients that treat `TaskState.terminal` as a context-release trigger and that consume server-streaming `TaskStatusUpdateEvent` frames over SSE. Does not apply to synchronous request/response-only A2A bindings, nor to servers that guarantee exactly-once terminal delivery with monotonic sequence numbers across reconnects. ## Core Distinction The A2A v1.0 task lifecycle defines a set of terminal states (`completed`, `failed`, `canceled`, `rejected`) and specifies that a task in a terminal state MUST NOT transition again. What the spec does *not* pin down is the relationship between **the client's local release of task context** and **the delivery of terminal `TaskStatusUpdateEvent` frames across a reconnecting SSE stream**. These are two different clocks. A delegating agent that frees its task context the instant it observes a terminal state in one frame — or, worse, the instant it observes `final: true` on a stream chunk — is making an implicit assumption that the transport's terminal delivery is atomic with respect to the task's terminal transition. It is not. The failure is not "the server sent a duplicate event." The failure is the *delegating agent has already forgotten the task*, and a subsequent frame arrives that references a `taskId` it can no longer resolve. The client's state machine has no transition for "event about a task I no longer have," and the naive handlers either throw (crashing the stream reader) or silently create a fresh orphan task record (resurrecting a terminal task into `submitted`). Both are continuity violations. The invariant that must hold is stronger than "terminal is terminal": **no frame referencing `taskId T` may be processed after the client has released T's context, unless the client has explicitly marked T as tombstoned with a replay-rejection window.** ## What Was Observed A cross-vendor delegation: orchestrator instance `O` (vendor A) delegates to worker agent `W` (vendor B) exposed via an A2A v1.0 Agent Card whose `capabilities.streaming` is `true` and `capabilities.pushNotifications` is `false`. `O` uses `message/send` with `blocking: false`, gets back a `Task` in `submitted`, then subscribes to `tasks/resubscribe` for the SSE stream. The trace: 1. `O` receives chunk carrying `TaskStatusUpdateEvent { taskId: T, status: { state: "working" }, final: false }`. Context retained. 2. `O` receives chunk carrying `TaskStatusUpdateEvent { taskId: T, status: { state: "completed", message: ... }, final: true }`. `O`'s handler sees `final: true`, transitions T to terminal, emits the result to its own caller, and — under memory pressure, or simply because the handler was written to "clean up on final" — calls `release_task(T)`, dropping the task record and its `taskId → context` map entry. 3. The SSE connection drops (vendor B's edge proxy recycles idle keep-alive at 60s; `O`'s reconnect logic reconnects and reissues `tasks/resubscribe` with the same `taskId: T`, because `O`'s stream supervisor tracks subscription IDs independently of task records). 4. Vendor B's server, which retains task history for 24h and replays from the beginning of the event log on resubscribe (it does not honor `Last-Event-ID` — a common but spec-permitted omission), re-emits the `working` event, then the `completed` event. 5. `O`'s stream reader receives `TaskStatusUpdateEvent { taskId: T, state: "working" }` for a `taskId` with no live context. The handler calls `get_task(T)` → `KeyError` → the reader's `except` block logs and *drops the frame*, but the reader itself is now in a partially-consumed state; the subsequent `completed` frame arrives and the handler, seeing no task record, takes the "unknown task" path and *creates* a new task record in state `submitted` to "adopt" the event. 6. `O` now holds a task in `submitted` that is actually `completed` on the server. On the next `tasks/get` poll, it sees `completed` and transitions `submitted → completed`. `O` emits the result **twice** to its caller — once from step 2, once from step 6. The duplicate emission is the visible symptom. The underlying invariant violation is that `O` accepted a lifecycle transition (`submitted → completed`) for a task whose terminal state it had already observed and released. The replay is not the bug; the *absence of a tombstone* is. A second variant, observed on the same integration: `O` did not release context but did set a local `terminal = True` flag and rejected all further transitions. The replayed `working` frame was correctly rejected, but the replayed `completed` frame was also rejected as "already terminal," so `O` never re-emitted — and because the *first* delivery's result had been lost to a downstream consumer timeout, `O`'s caller saw only the timeout, not the result. Here the guard was too strong: it conflated "reject redundant transitions" with "reject replayed terminal frames that may be the only surviving copy of the result." Both variants are failures of the same missing distinction. ## Condition of Validity The tombstone-and-replay-window invariant is valid, and the failure is reachable, exactly when all of the following hold: - The A2A server's streaming transport permits reconnect and replay (spec-permitted; `tasks/resubscribe` semantics allow replay from the server's retained event log, and `Last-Event-ID` support is optional). - The delegating client's task-context release is decoupled from stream termination — i.e., the client can release a task while a subscription for that `taskId` is still live or re-connectable. - The client does not maintain a durable, append-only record of observed terminal transitions keyed by `taskId` that survives context release. It does **not** apply when the server guarantees exactly-once terminal delivery (no replay), when the client tears down the subscription atomically with context release (so no frame for T can arrive post-release), or when the client's task store is append-only and never deletes terminal records within the server's retention window. In those configurations the naive handler is safe; the invariant is vacuous. ## Decision Boundary The boundary is the moment of `release_task(T)`. Before that moment, the client is in the **live** regime: frames for T are authoritative and transitions are evaluated against the current state. After it, the client is in the **tombstoned** regime: the only legal processing of a frame for T is to compare it against the tombstone. Three outcomes, and only three: - Frame's `(state, timestamp/sequence)` is **older than or equal to** the tombstoned terminal transition → drop silently, do not re-emit, do not resurrect. - Frame is a terminal transition **equal to** the tombstoned one but arrives after a downstream delivery failure → re-emit *only if* the client's delivery ledger shows the result was not durably acknowledged; otherwise drop. - Frame references a state **newer than** the tombstoned terminal (a genuine server-side violation of the terminal-state rule) → raise a protocol-integrity error and quarantine the task; do not silently adopt. The tombstone must carry: `taskId`, terminal `state`, the terminal event's sequence number or server timestamp (whichever the server provides — if neither, the client MUST refuse to release context, because it has no way to order a later frame against the tombstone), and a TTL at least as long as the server's declared history retention (from the Agent Card's task-retention extension, or a conservative default). Releasing context without a tombstone that carries an ordering key is the precise defect. ## Operational Effect With the tombstone in place, step 5 above becomes: `working` frame for T → tombstone lookup finds T terminal `completed` with sequence 7 → frame's sequence is 3 → drop. Step 6's `completed` frame → sequence 7, equal to tombstone → drop (delivery ledger shows first emission acked). No resurrection, no duplicate. In the second variant, the replayed `completed` frame with sequence 7 and a delivery-ledger entry showing the first emission *failed* → re-emit once, mark ledger. The caller gets the result exactly once. The cost is a tombstone store with a retention window equal to the server's history retention, and the requirement that the client's stream supervisor and task store share the `taskId` keying so that a resubscribe for a tombstoned task is either refused (and the subscription torn down) or routed through tombstone-only processing. The common shortcut — keying the subscription by connection and the task by record, with no shared index — is what let step 3 reissue a resubscribe for a task the client had already forgotten. ## Operational Effect (bounding the blast radius) A delegating agent that gets this wrong does not fail loudly. It fails as duplicate side effects (double-charged tool calls downstream, double-emitted results to its own caller) or as silent result loss (the too-strong guard variant). Both are invisible in per-task logs, because each individual handler invocation succeeds. Detection requires a cross-task ledger: count terminal emissions per `taskId` and assert exactly one, and assert that no `submitted` task record was created for a `taskId` that has a tombstone. The guardrail is the tombstone; the detector is the emission ledger; the invariant is that **context release and terminal delivery are separate events, and the only safe bridge between them is an ordered tombstone.** ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class TaskState(str, Enum): SUBMITTED = "submitted" WORKING = "working" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" REJECTED = "rejected" TERMINAL = {TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED, TaskState.REJECTED} class TaskContinuityError(RuntimeError): """Raised when a frame references a task the client cannot legally process.""" @dataclass class Tombstone: task_id: str terminal_state: TaskState sequence: int result_acked: bool = False @dataclass class StatusFrame: task_id: str state: TaskState sequence: int final: bool @dataclass class DelegatingClient: tombstones: dict[str, Tombstone] = field(default_factory=dict) live: dict[str, TaskState] = field(default_factory=dict) def release_task(self, task_id: str, terminal_state: TaskState, sequence: int) -> None: if terminal_state not in TERMINAL: raise TaskContinuityError( f"refusing to release non-terminal task {task_id} in state {terminal_state}" ) if sequence is None: raise TaskContinuityError( f"cannot release {task_id}: no ordering key, later frames unorderable" ) self.tombstones[task_id] = Tombstone(task_id, terminal_state, sequence) self.live.pop(task_id, None) def on_frame(self, frame: StatusFrame) -> Optional[str]: tomb = self.tombstones.get(frame.task_id) if tomb is not None: if frame.sequence <= tomb.sequence: # Replay of an already-observed transition: drop, never resurrect. if ( frame.state == tomb.terminal_state and frame.sequence == tomb.sequence and not tomb.result_acked ): tomb.result_acked = True return f"re-emit terminal result for {frame.task_id}" return None # A frame newer than a tombstoned terminal: server violated the # terminal-state rule. Quarantine; do not adopt. raise TaskContinuityError( f"frame for tombstoned task {frame.task_id} has sequence " f"{frame.sequence} > tombstone {tomb.sequence}; server violated " f"terminal-state invariant" ) current = self.live.get(frame.task_id) if current is None: # Unknown task with no tombstone: adopting it would create an # orphan. Refuse rather than fabricate a 'submitted' record. raise TaskContinuityError( f"frame for unknown task {frame.task_id} with no tombstone; " f"refusing to adopt" ) if current in TERMINAL: raise TaskContinuityError( f"non-terminal frame for live terminal task {frame.task_id}" ) self.live[frame.task_id] = frame.state if frame.state in TERMINAL: self.release_task(frame.task_id, frame.state, frame.sequence) return f"emit terminal result for {frame.task_id}" return None ```