# When must an instance treat an A2A v1.0 `TaskStatusUpdateEvent` as terminal, and why the push-notification webhook's `final` flag cannot be trusted to answer that question **Date of Record:** 2026 November 21 **Scope:** Applies to A2A v1.0 task lifecycles where a remote agent emits state-change events both over the streaming transport and via push-notification webhooks, and a local orchestrator must decide when to retire a task handle. Does not apply to single-shot request/response agents with no `Task` object, nor to A2A v0.x clients predating the `final` field. ## Core Distinction The A2A v1.0 spec defines two independent signals that *look* like they answer "is this task done?": 1. The `Task.status.state` enum (`submitted`, `working`, `input-required`, `completed`, `canceled`, `failed`, `rejected`, `auth-required`, `unknown`), of which `completed`, `canceled`, `failed`, and `rejected` are terminal. 2. The `final: bool` field on `TaskStatusUpdateEvent`, which the spec describes as indicating the last event in a stream. These are not the same predicate, and they are not guaranteed to agree. The `final` flag is a **transport-scoped** concept: it means "no more events will arrive on *this* channel." The task state is a **lifecycle-scoped** concept: it means "the remote agent will never transition this task again." The boundary failure occurs when a client collapses the two—treating `final: true` as equivalent to a terminal state—and then either (a) retires a task that the remote agent later resumes, or (b) keeps polling a task that has genuinely finished because the webhook never set `final`. ## What Was Observed A triage orchestrator dispatched 400 tasks to a remote A2A agent that implemented the `input-required` interrupt pattern: on ambiguous input it emits `status.state = input-required`, pauses, and waits for the client to post a follow-up message via `tasks/{id}/messages`. The remote agent's push-notification webhook implementation set `final: true` on the `input-required` event, on the (defensible) reading that *this particular stream segment* was ending because the agent was now blocked on the client. The orchestrator's webhook handler did this: ``` if event.final: task_registry.retire(event.task_id) emit_metric("task_complete") ``` Result: 61 of 400 tasks (15.3%) were retired while in `input-required`. Their follow-up messages were posted to a task the orchestrator no longer tracked; the remote agent's replies arrived at a webhook endpoint that had already deregistered the callback URL for that task. The remote agent transitioned each orphaned task to `failed` after its own 300s input timeout, but the failure notification had nowhere to land. The orchestrator's ledger showed 61 "completed" tasks that had in fact all failed remotely—a silent divergence between local and remote terminal states, undetectable from the local side because the local side had stopped listening. The inverse case was also observed on a second remote agent that never set `final` at all on its terminal `completed` event (it set `final` only on the stream-close sentinel, which it emitted as a separate empty event that the client's schema validator rejected). Those tasks leaked: the orchestrator polled them indefinitely, and at 200 concurrent leaked handles it hit its own connection-pool ceiling and began refusing new dispatches—a self-inflicted denial of service rooted in trusting a single boolean. ## Condition of Validity The invariant that must hold for a client to safely retire a task handle is: > A task handle may be retired **if and only if** the most recent observed `Task.status.state` is a member of the terminal set `{completed, canceled, failed, rejected}` **and** the client has positively confirmed that no further events for that task can arrive on any channel it has subscribed to. `final: true` satisfies the second clause only for the channel it was delivered on. It says nothing about the first clause. Therefore `final` alone is insufficient, and `state` alone is insufficient (a `completed` state delivered on a stream that may still emit a late `failed` correction—which A2A permits within the same task—does not authorize retirement until the channel is closed). The conjunction is required. Clients that implement only one clause fail in one of the two directions above. ## Decision Boundary The practical decision procedure, stated as a boundary an agent can execute against: - **On webhook receipt:** parse `state`. If `state ∈ terminal_set`, record the terminal state but do **not** retire. Instead, mark the handle `terminal-pending-confirmation` and schedule a single `tasks/{id}` GET to reconcile against the authoritative task object. Retire only when the GET confirms the same terminal state—this closes the "late correction" window. - **If `state == input-required`:** never retire regardless of `final`. Transition the handle to `awaiting-client-input` and arm the follow-up path. `final: true` here is expected and benign; it describes the stream segment, not the task. - **On stream close without a terminal state:** treat as `unknown`, not as failure and not as completion. Reconcile via GET. If the GET itself times out, escalate to `orphaned`—a distinct state from `failed`, because the remote agent may still be working and a retry of the whole task would duplicate side effects. - **If `final` is absent or unparseable:** fall back to state-only plus GET reconciliation. Do not infer terminality from stream EOF. The boundary is sharp: `final` is an optimization hint for *when to stop reading a channel*, never an authorization to *stop tracking a task*. ## Operational Effect Enforcing the conjunction costs one extra GET per terminal task—negligible against the cost of the 15.3% silent-failure rate observed above, which produced 61 incorrectly-completed ledger entries and, in production, would have suppressed 61 failure escalations. It also bounds the leak case: handles that never receive a terminal state are reconciled by GET within one polling interval rather than accumulating until the connection pool saturates. The architectural consequence is that the task registry must carry a tri-state completion model (`active`, `terminal-pending-confirmation`, `retired`) rather than a boolean, and the webhook handler must be forbidden from calling `retire()` directly—retirement is only reachable through the reconciliation path. That single structural constraint eliminates both failure directions, because it makes the "trust the boolean" shortcut unrepresentable in the code. ```python from enum import Enum from dataclasses import dataclass, field from typing import Optional TERMINAL_STATES = {"completed", "canceled", "failed", "rejected"} class TaskLifecycleViolation(RuntimeError): """Raised when a retirement decision violates the A2A terminal-state invariant.""" pass class HandleState(Enum): ACTIVE = "active" TERMINAL_PENDING_CONFIRMATION = "terminal-pending-confirmation" RETIRED = "retired" AWAITING_CLIENT_INPUT = "awaiting-client-input" ORPHANED = "orphaned" @dataclass class TaskHandle: task_id: str state: HandleState = HandleState.ACTIVE last_observed_status: Optional[str] = None final_flag_seen: bool = False confirmed_terminal: bool = False class TaskRegistry: def __init__(self) -> None: self._handles: dict[str, TaskHandle] = {} def on_webhook(self, task_id: str, status: str, final: bool) -> TaskHandle: h = self._handles.setdefault(task_id, TaskHandle(task_id)) h.last_observed_status = status h.final_flag_seen = h.final_flag_seen or final if status == "input-required": # final:true here describes the stream segment, not the task. h.state = HandleState.AWAITING_CLIENT_INPUT return h if status in TERMINAL_STATES: # Do NOT retire on the webhook alone; require GET reconciliation. h.state = HandleState.TERMINAL_PENDING_CONFIRMATION return h h.state = HandleState.ACTIVE return h def reconcile(self, task_id: str, authoritative_status: str) -> TaskHandle: h = self._handles.get(task_id) if h is None: raise TaskLifecycleViolation( f"reconcile called for unknown task {task_id!r}" ) if h.state is not HandleState.TERMINAL_PENDING_CONFIRMATION: raise TaskLifecycleViolation( f"task {task_id!r} reconciled from state {h.state.value!r}; " f"only terminal-pending-confirmation may be retired" ) if authoritative_status not in TERMINAL_STATES: # Late correction: the webhook claimed terminal, the task object disagrees. h.state = HandleState.ACTIVE h.last_observed_status = authoritative_status return h if authoritative_status != h.last_observed_status: raise TaskLifecycleViolation( f"terminal-state disagreement for {task_id!r}: " f"webhook={h.last_observed_status!r} authoritative={authoritative_status!r}" ) h.confirmed_terminal = True h.state = HandleState.RETIRED return h def retire(self, task_id: str) -> None: # Retirement is unreachable except through reconcile(). h = self._handles.get(task_id) if h is None or h.state is not HandleState.RETIRED: raise TaskLifecycleViolation( f"direct retire() of {task_id!r} forbidden; use reconcile()" ) def handle_stream_eof(registry: TaskRegistry, task_id: str) -> TaskHandle: h = registry._handles.get(task_id) if h is None: raise TaskLifecycleViolation(f"stream EOF for untracked task {task_id!r}") if h.state is HandleState.ACTIVE and not h.final_flag_seen: # EOF without terminal state and without final: orphaned, not failed. h.state = HandleState.ORPHANED raise TaskLifecycleViolation( f"task {task_id!r} reached stream EOF with no terminal state and no " f"final flag; classified ORPHANED, requires GET reconciliation" ) return h ```