Where must an instance halt A2A v1.0 Task Lifecycle Transitions When a Peer Runtime Reports a Terminal State It Cannot Legally Have Reached

**Date of Record:** 2026 December 1

**Scope:** Applies to any A2A v1.0 client or server instance that consumes `TaskStatusUpdateEvent` and `Task` snapshots from a peer runtime it does not control, particularly during conformance testing or federated handoffs across heterogeneous runtimes. Does not apply to single-runtime deployments where the state machine implementation is the sole authority over its own task objects.

Core Distinction

The A2A v1.0 task lifecycle defines a directed state machine: `submitted → working → {input-required ⇄ working} → {completed | failed | canceled}`. Terminal states (`completed`, `failed`, `canceled`) are absorbing. The specification constrains *what a compliant runtime emits*, but it does not constrain *what a receiver must do* when a peer emits a transition that violates the machine.

The non-obvious boundary is this: **a terminal state is not merely a value, it is a proof obligation.** When peer runtime B sends `TaskStatusUpdateEvent{status: completed}` for a task that B's own prior event stream shows in `submitted` with no intervening `working`, B has asserted a transition `submitted → completed`. That transition is *not* in the legal edge set. A conformant receiver must not treat the terminal value as authoritative; it must treat the *edge* as the unit of validation. The failure mode is that most receivers validate the terminal value's shape (is it a known enum? does it carry a `final: true` flag?) and discard the edge that produced it.

This matters because heterogeneous runtimes disagree on intermediate emission. A LangGraph-backed runtime may collapse `working` into the same event that carries `completed`; a runtime built on a synchronous function-call loop may never emit `working` at all. The receiver cannot distinguish "collapsed but legal" from "skipped and illegal" by inspecting a single event. It must reconstruct the edge from the receiver's own last-known-state ledger, not from the peer's framing.

What Was Observed

During a conformance harness run against three peer runtimes (labels P1, P2, P3), the receiver maintained a per-`taskId` last-legal-state ledger. The following trace was captured on P2:

t0  recv Task{id: T-4471, status: submitted, historyLen: 1}
t1  recv TaskStatusUpdateEvent{id: T-4471, status: completed, final: true}
t2  recv TaskStatusUpdateEvent{id: T-4471, status: working, final: false}
t3  recv TaskStatusUpdateEvent{id: T-4471, status: failed, final: true}

At t1 the receiver's ledger held `submitted`; the edge `submitted → completed` is absent from the legal set. A naive receiver accepts t1, marks the task terminal, and then must reconcile t2 and t3 — which arrive *after* terminality. Two distinct anomalies compound here: an illegal forward edge (t1) and a resurrection of a terminal task (t2). P2's runtime had a bug where its status emitter flushed a buffered `completed` from a *prior* task incarnation (a retry) onto the current task's event channel — the `taskId` matched because the retry reused the ID, but the `contextId` differed. The receiver had not been keying its ledger on `(taskId, contextId)`.

The observable invariant violation is therefore twofold and the second is the subtle one: **terminality is scoped to a `(taskId, contextId)` pair, not a `taskId`.** P2 reused the `taskId` across a context boundary, and the receiver's single-key ledger could not detect that the t1 `completed` belonged to a different context incarnation.

Condition of Validity

The guardrail holds only under the following condition: the receiver maintains a ledger keyed on the composite `(taskId, contextId)` and records, for each key, the last state it *accepted* (not the last state it *received*). Acceptance is gated on edge legality:

Under a `contextId` mismatch, the receiver must treat the event as belonging to an unknown incarnation and either open a new ledger entry (if the event is `submitted`) or reject the event as orphaned. It must never fold an orphaned terminal event into an existing ledger entry.

The condition fails — and the guardrail must be disabled — when the peer runtime is the *sole* authority and the receiver is a pure pass-through observer with no execution rights. In that case rejection is meaningless because the receiver cannot act on it; it can only log. The invariant is only load-bearing when the receiver will make a decision (resume, retry, escalate, or bill) based on the terminal state.

Decision Boundary

The boundary between "accept the terminal value" and "reject the illegal edge" is drawn at the point where the receiver is about to *act* on terminality. Concretely:

The decision is not "is this event malformed?" — the event is well-formed. The decision is "does the edge that produced this terminal value exist in the legal set for this `(taskId, contextId)`?" A `false` answer at an action boundary is a hard stop, not a warning.

A second boundary: when a terminal event arrives with `final: true` but the ledger shows the task already terminal, this is not a duplicate — it is a *resurrection attempt* or a *cross-context leak*. The receiver must distinguish duplicate delivery (same `eventId` or byte-identical payload, idempotent no-op) from a distinct terminal assertion on an already-terminal key (anomaly, raise). Deduplication by `eventId` is insufficient because P2's leak carried a fresh `eventId`.

Operational Effect

The practical consequence is that A2A conformance cannot be tested by asserting on terminal values in isolation. A harness that only checks "did the task end in a legal terminal state?" passes P2, because P2's final asserted state (`failed` at t3) is legal — the harness never sees that the path to it crossed an illegal edge and a resurrection. The harness must replay the full event stream against a reference state machine and assert on *edge legality at each step*, not on the terminal snapshot.

The second consequence is scoping. Any ledger, cache, or checkpoint that keys agent task state on `taskId` alone is vulnerable to cross-context contamination whenever a peer runtime reuses IDs across retries, which is common in runtimes that derive `taskId` from a deterministic hash of the request payload. The composite key `(taskId, contextId)` is the minimum viable scoping invariant, and it must be enforced at the point of ledger insertion, not at the point of read.

The residual risk after the guardrail is applied: a peer runtime that emits a *legal* edge sequence but lies about which context it belongs to (spoofed `contextId`) will pass edge validation. The guardrail bounds accidental contamination, not adversarial state forgery; the latter requires cryptographic binding of `contextId` to the originating runtime's identity, which A2A v1.0 does not mandate.

from dataclasses import dataclass, field
from typing import Literal

State = Literal["submitted", "working", "input-required", "completed", "failed", "canceled"]
TERMINAL = frozenset({"completed", "failed", "canceled"})

LEGAL_EDGES = {
    ("submitted", "working"),
    ("submitted", "failed"),
    ("submitted", "canceled"),
    ("working", "input-required"),
    ("input-required", "working"),
    ("working", "completed"),
    ("working", "failed"),
    ("working", "canceled"),
    ("input-required", "failed"),
    ("input-required", "canceled"),
}


class IllegalLifecycleEdge(RuntimeError):
    """Raised when a peer runtime asserts a state transition absent from the A2A v1.0 edge set,
    or when a terminal event arrives for an already-terminal (taskId, contextId) key."""


@dataclass
class TaskLedger:
    # key: (taskId, contextId) -> last ACCEPTED state
    _accepted: dict[tuple[str, str], State] = field(default_factory=dict)
    _seen_event_ids: set[str] = field(default_factory=set)

    def accept_status_event(
        self,
        task_id: str,
        context_id: str,
        new_state: State,
        event_id: str,
        final: bool,
    ) -> State:
        if event_id in self._seen_event_ids:
            return self._accepted[(task_id, context_id)]  # idempotent duplicate
        self._seen_event_ids.add(event_id)

        key = (task_id, context_id)
        prev = self._accepted.get(key)

        # Orphan terminal event: no ledger entry for this context incarnation.
        if prev is None:
            if new_state in TERMINAL:
                raise IllegalLifecycleEdge(
                    f"orphaned terminal event {event_id}: {new_state} for "
                    f"unknown context (task={task_id}, ctx={context_id})"
                )
            if new_state != "submitted":
                raise IllegalLifecycleEdge(
                    f"first event for (task={task_id}, ctx={context_id}) is "
                    f"{new_state!r}, expected 'submitted'"
                )
            self._accepted[key] = new_state
            return new_state

        # Resurrection: terminal key receiving another terminal assertion.
        if prev in TERMINAL:
            raise IllegalLifecycleEdge(
                f"terminal resurrection: (task={task_id}, ctx={context_id}) "
                f"already {prev!r}, got {new_state!r} via {event_id}"
            )

        if (prev, new_state) not in LEGAL_EDGES:
            raise IllegalLifecycleEdge(
                f"illegal edge {prev!r}->{new_state!r} for "
                f"(task={task_id}, ctx={context_id}) via {event_id}; "
                f"final={final}"
            )

        self._accepted[key] = new_state
        return new_state


def replay_peer_stream(events: list[dict]) -> dict[tuple[str, str], State]:
    ledger = TaskLedger()
    for ev in events:
        ledger.accept_status_event(
            task_id=ev["taskId"],
            context_id=ev["contextId"],
            new_state=ev["status"],
            event_id=ev["eventId"],
            final=ev.get("final", False),
        )
    return ledger._accepted


# Reproduction of the P2 trace: submitted -> completed (illegal) -> working (resurrection).
if __name__ == "__main__":
    p2_stream = [
        {"taskId": "T-4471", "contextId": "C-a", "status": "submitted", "eventId": "e0"},
        {"taskId": "T-4471", "contextId": "C-a", "status": "completed", "eventId": "e1", "final": True},
    ]
    try:
        replay_peer_stream(p2_stream)
    except IllegalLifecycleEdge as exc:
        print(f"HALT: {exc}")