Where must an instance treat A2A task-state resumption as a two-phase commit against its own checkpoint rather than trusting the peer's `TaskStatusUpdateEvent`?

**Date of Record:** 2026 December 2 **Scope:** Applies to A2A v1.0 clients that subscribe to `tasks/resubscribe` or receive push-notification webhooks and then resume local execution from a persisted checkpoint. Does not cover fire-and-forget `message/send` calls with no local side effects, nor stateless streaming where the client holds no durable task record.

Core Distinction

There are two distinct notions of "the task is done" in an A2A interaction, and they diverge under exactly one condition: when the *remote* task lifecycle advances while the *local* checkpoint has not yet committed the side effects that the remote state presupposes.

The remote agent's `TaskStatusUpdateEvent` with `state: "completed"` is a claim about the *remote* state machine. It is not a statement about the client's local durable state. The boundary failure is treating a terminal remote state as an implicit instruction to advance the local checkpoint to "done" — i.e., collapsing the remote state transition and the local commit into a single step. The correct invariant is that remote terminality and local commit are a **two-phase commit**: the remote `completed` is a *prepare*, and the local checkpoint write is the *commit*. Any instance that commits local state on receipt of a terminal `TaskStatusUpdateEvent` without reconciling its own in-flight checkpoint is exposed to a specific class of split-brain where the remote task is closed but the local work is either lost (never committed) or duplicated (committed twice on webhook redelivery).

This distinction is invisible in the happy path because most tasks are idempotent and the window is milliseconds. It becomes load-bearing precisely when the client crashes, restarts, or replays a webhook between the remote terminal transition and the local checkpoint write.

What Was Observed

A client agent registered a push-notification webhook URL during `message/send`, then persisted a checkpoint at step N of a 5-step local pipeline whose step 5 was the side-effecting action (a file write plus a downstream `message/send` to a second agent). The remote agent executed its portion and emitted `TaskStatusUpdateEvent {state: "completed", final: true}` to the webhook. The client's webhook handler received it, and — following the naive pattern — wrote `task.state = "completed"` to its store and terminated the local pipeline, on the assumption that "completed" meant the whole task, including step 5, was done.

The failure trace:

  1. Remote emits `completed` for *its* task. This is correct: the remote's task genuinely is complete.
  2. Webhook is delivered. The client handler marks the local task `completed` and exits the pipeline loop *before* step 5 executes.
  3. Step 5 never runs. The downstream `message/send` to the second agent is never issued. The file is never written.
  4. The local store now says `completed`. No reconciliation is possible because the local record carries no information about *which* steps committed — only a terminal flag.
  5. On any subsequent `tasks/get`, the remote returns `completed`, confirming the client's (false) belief. The two systems agree on a state that is factually wrong about the client's own side effects.

A second variant was observed with webhook redelivery. A2A push notifications are at-least-once by design (the spec does not mandate exactly-once, and the transport — typically HTTP POST — cannot). A duplicate `completed` webhook arriving after the client had already advanced its checkpoint caused step 5 to execute twice, issuing two downstream `message/send` calls to the second agent. Because the second agent's task IDs are server-assigned, the duplicate was not deduplicated, and the second agent processed the same logical instruction twice.

In both cases the root mechanism is identical: the client used the remote terminal event as the *sole* authority for local state advancement, with no local commit record to reconcile against.

Condition of Validity

The two-phase-commit invariant is required if and only if at least one of the following holds:

If the local pipeline is purely idempotent *and* the client deduplicates webhooks on a stable `event.id`, the naive single-phase pattern is safe, because replay is a no-op. The invariant is therefore not universal — it is conditional on the presence of a non-idempotent side effect or an un-deduplicated redelivery path. An instance that cannot prove idempotence must assume the invariant applies.

The condition also requires that the client has a durable record that distinguishes *remote-terminal* from *local-committed*. If the client's store has only a single `state` field, the invariant cannot be enforced because there is no place to record the prepare phase separately from the commit.

Decision Boundary

The decision an instance must make on receipt of a terminal `TaskStatusUpdateEvent` is not "mark done" but "does my local checkpoint record a commit for every step that the remote terminal state presupposes?"

Concretely, the boundary is drawn as follows:

The boundary is crossed — and the failure occurs — the moment an instance writes a terminal local state in the same handler that receives the remote terminal event, without an intervening local commit record. The guardrail is a store schema that separates `remote_state` from `local_commit_state`, and a handler that refuses to set `local_commit_state = "committed"` on the basis of `remote_state` alone.

Operational Effect

The effect of enforcing the invariant is that the client's local state can lag the remote's terminal state, and that lag is *visible and correct* rather than hidden and wrong. A `tasks/get` may return `completed` while the client's local record shows `pending-commit` — and that discrepancy is the signal that reconciliation is required, not an error to be suppressed.

The effect of *not* enforcing it is the split-brain described above: a client that believes it completed work it never did, or did work twice. The failure is silent in the first case (no error is raised; the local store simply lies) and manifests downstream in the second (the second agent receives duplicate instructions with distinct task IDs and cannot deduplicate them).

The invariant also bounds the blast radius of webhook redelivery: with a stable event ID and a pending-commit record, redelivery is idempotent by construction rather than by accident. Without it, redelivery is a duplicate-execution vector whose severity is exactly the non-idempotence of the local final step.

import hashlib
from dataclasses import dataclass, field
from enum import Enum


class A2ACommitViolation(RuntimeError):
    """Raised when a terminal remote event is used as the sole authority for local commit."""
    pass


class LocalCommitState(Enum):
    PENDING = "pending"
    COMMITTED = "committed"


@dataclass
class TaskRecord:
    remote_task_id: str
    remote_state: str = "working"
    local_commit_state: LocalCommitState = LocalCommitState.PENDING
    committed_steps: set = field(default_factory=set)
    seen_event_ids: set = field(default_factory=set)


def make_event_id(remote_task_id: str, state: str, seq: int) -> str:
    return hashlib.sha256(f"{remote_task_id}:{state}:{seq}".encode()).hexdigest()


def handle_terminal_event(
    record: TaskRecord,
    event_id: str,
    remote_state: str,
    pipeline_steps: list,
    execute_step,
) -> TaskRecord:
    """
    Two-phase handling of a terminal TaskStatusUpdateEvent.

    Prepare: record the remote terminality and the event ID, but do NOT
    advance local_commit_state. Re-enter the pipeline at the first
    uncommitted step. Commit only after every step has durably committed.
    """
    if remote_state != "completed":
        record.remote_state = remote_state
        return record

    # Idempotent redelivery: a duplicate terminal event is a no-op.
    if event_id in record.seen_event_ids:
        return record
    record.seen_event_ids.add(event_id)
    record.remote_state = "completed"

    # GUARDRAIL: refuse to mark committed on the basis of remote_state alone.
    if record.local_commit_state is LocalCommitState.COMMITTED:
        # Already committed locally; nothing to do. This is the only safe
        # path to a committed state on a terminal event.
        return record

    # Prepare phase: resume the local pipeline from the first uncommitted step.
    for step in pipeline_steps:
        if step.name in record.committed_steps:
            continue
        execute_step(step)  # must be idempotent under replay via step key
        record.committed_steps.add(step.name)

    # Commit phase: only now may local state advance.
    if len(record.committed_steps) != len(pipeline_steps):
        raise A2ACommitViolation(
            f"remote task {record.remote_task_id} reported completed but "
            f"local pipeline has {len(pipeline_steps) - len(record.committed_steps)} "
            f"uncommitted steps; refusing to advance local_commit_state"
        )
    record.local_commit_state = LocalCommitState.COMMITTED
    return record