# How does an instance detect terminal-state divergence in A2A task lifecycle conformance when both peers certify to the same state machine version **Date of Record:** 2026 November 29 **Scope:** Applies to Agent-to-Agent (A2A) task lifecycle conformance and interoperability certification where two independently certified agents exchange `Task` objects whose `status.state` transitions are validated by each peer's local state machine. Does not apply to single-agent internal tool loops, nor to transport-level (HTTP/gRPC) retry semantics absent task-object state. ## Core Distinction Certification suites for A2A task lifecycle typically validate each agent against a *reference state machine*: a table of legal transitions (`submitted → working → input-required → working → completed`, `working → failed`, `working → canceled`, and the terminal set `{completed, failed, canceled}`). Passing certification means the agent accepts and emits only transitions present in the table. It does **not** mean the agent agrees with its peer on *which terminal state is reachable from a given non-terminal state under concurrent events*. The non-obvious boundary: two agents can both pass the same versioned conformance suite and still diverge on terminal-state reachability when an `input-required` pause races a peer-initiated `cancel`. The suite checks transition *legality* per side; it does not check transition *commutativity* across the wire. The invariant that fails is not "does my transition table match the spec" but "does my terminal-state selection match my peer's, given the same interleaving of accepted messages." ## What Was Observed Two certified agents, `planner` and `executor`, negotiated `A2A/lifecycle@1.2`. Both passed the vendor suite: every emitted `TaskStatusUpdateEvent` was a legal edge, every terminal state was in the allowed set, and every `final: true` event was preceded by a legal predecessor. During an interoperability run, the harness injected a `tasks/cancel` from the client while `executor` sat in `input-required` awaiting a clarification payload. The trace: 1. `executor` receives `tasks/cancel`, transitions `input-required → canceled`, emits `TaskStatusUpdateEvent{state: canceled, final: true}`, and closes the stream. 2. Concurrently, `planner` (the delegating peer) had already dispatched the clarification response and, on its own timer, transitioned its local view `input-required → working` before the cancel event propagated. 3. `planner` then received `canceled` for a task its local machine had marked `working`. Because `working → canceled` is legal in the table, `planner` accepted it — but it had already emitted a `working` status update downstream and a partial artifact. 4. The client observed two terminal-ish signals: a `working` event followed by `canceled`, plus an artifact reference that the `canceled` task claims does not exist. Both agents were conformant. Neither violated its transition table. The divergence was in *terminal-state reachability under concurrent pause-resume vs. cancel*, which the suite does not enumerate because it tests each agent's edge set in isolation, not the product of the two edge sets under interleaving. The tell: the certification report showed 100% edge coverage on both sides, yet the joint trace contained a `working`-after-`input-required` emission that the peer had already logically superseded with `canceled`. The suite's coverage metric was *per-agent edge coverage*, and edge coverage is not a commutativity proof. ## Condition of Validity The per-agent conformance guarantee is valid only under the assumption that **the peer's accepted transition set is a subset of the observer's legal-predecessor set for every terminal state**. Formally, for terminal state `T` and any non-terminal `S`, if peer `P` can transition `S → T` and observer `O` can transition `S → S'`, then `O` must accept `S' → T` (or must reject `S'` once `T` is in flight). This is a *cross-agent* invariant; no single-agent suite can test it because it quantifies over two transition tables. The invariant holds when: - Terminal states are absorbing and mutually exclusive, and - The cancel path is ordered *before* the resume path in the peer's event log (i.e., a total order on the wire), or - The observer treats any terminal state as authoritative and rolls back non-terminal emissions that post-date it. It fails when the wire does not impose a total order (concurrent `tasks/cancel` and `tasks/send` for the same `taskId`), and when the observer's table permits a non-terminal transition out of a state that the peer has already collapsed to terminal. ## Decision Boundary An instance must decide, on receiving a terminal status for a task it holds in a non-terminal state, whether to (a) accept the terminal as authoritative and suppress/roll back its own subsequent non-terminal emissions, or (b) reject as a conformance violation and raise to the harness. The boundary is: - **Accept-and-collapse** when the terminal state's predecessor set in the *peer's* advertised capability includes the instance's current state. This is the interoperable path. - **Reject** when the terminal state arrives for a task the instance has already emitted `final: true` on with a *different* terminal state — that is a genuine double-terminal, a hard violation. - **Quarantine** when the instance cannot determine ordering (no sequence number, no `timestamp` monotonicity) and the terminal conflicts with an in-flight non-terminal it already emitted. Quarantine means stop emitting, mark the task `indeterminate`, and escalate — never silently pick a winner. The trap is treating "legal per my table" as "correct per the joint run." Legal-per-table is necessary, not sufficient. The decision must consult the peer's terminal-reachability advertisement, not just the local edge set. ## Operational Effect Without the cross-agent invariant, certification produces false confidence: two 100%-conformant agents generate joint traces with orphaned artifacts, double terminals, and status regressions that the suite never scores. The observable failures are (1) artifacts referenced by a `canceled` task, (2) `working` events emitted after a peer's `final: true`, and (3) `indeterminate` tasks that no side owns. The guardrail is a *joint conformance check* layered on the per-agent suite: replay the interleaved trace through both transition tables and assert that for every terminal event, the observer's post-terminal emission set is empty, and that no artifact is bound to a terminal state that disclaims it. This is a commutativity test, not an edge-coverage test, and it must be run against the *product* of the two machines. Operationally, an instance should carry a `terminal_authority` flag and a monotonic `event_seq` on every status update, and on terminal receipt, compare against its last emitted `event_seq`. If the terminal's `event_seq` precedes a non-terminal the instance already emitted, the instance is in divergence and must quarantine rather than resolve. ```python import enum from dataclasses import dataclass, field from typing import Optional class TaskState(enum.Enum): SUBMITTED = "submitted" WORKING = "working" INPUT_REQUIRED = "input-required" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" INDETERMINATE = "indeterminate" TERMINAL = {TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED} LEGAL_EDGES = { (TaskState.SUBMITTED, TaskState.WORKING), (TaskState.WORKING, TaskState.INPUT_REQUIRED), (TaskState.INPUT_REQUIRED, TaskState.WORKING), (TaskState.WORKING, TaskState.COMPLETED), (TaskState.WORKING, TaskState.FAILED), (TaskState.WORKING, TaskState.CANCELED), (TaskState.INPUT_REQUIRED, TaskState.CANCELED), } class TerminalDivergenceError(RuntimeError): """Raised when a received terminal state conflicts with an already-emitted non-terminal event under concurrent interleaving, and ordering cannot be established from event_seq monotonicity.""" @dataclass class StatusEvent: state: TaskState event_seq: int final: bool = False @dataclass class LocalTaskView: task_id: str state: TaskState = TaskState.SUBMITTED last_emitted_seq: int = 0 emitted: list = field(default_factory=list) def emit(self, new_state: TaskState, seq: int) -> StatusEvent: if (self.state, new_state) not in LEGAL_EDGES: raise TerminalDivergenceError( f"illegal local edge {self.state}->{new_state} for {self.task_id}" ) ev = StatusEvent(new_state, seq, final=new_state in TERMINAL) self.state = new_state self.last_emitted_seq = max(self.last_emitted_seq, seq) self.emitted.append(ev) return ev def receive_terminal(self, terminal: StatusEvent) -> TaskState: if terminal.state not in TERMINAL: raise TerminalDivergenceError( f"receive_terminal got non-terminal {terminal.state}" ) # Double-terminal with disagreement is a hard violation. for ev in self.emitted: if ev.final and ev.state != terminal.state: raise TerminalDivergenceError( f"double-terminal: emitted {ev.state}, received {terminal.state} " f"for {self.task_id}" ) # If the terminal precedes a non-terminal we already emitted, we are in # divergence unless the peer's advertisement says our state is a legal # predecessor of its terminal (accept-and-collapse). if terminal.event_seq <= self.last_emitted_seq and self.state not in TERMINAL: if (self.state, terminal.state) in LEGAL_EDGES: self.state = terminal.state return self.state self.state = TaskState.INDETERMINATE raise TerminalDivergenceError( f"terminal {terminal.state} (seq={terminal.event_seq}) conflicts " f"with local {self.state} (seq={self.last_emitted_seq}); " f"quarantined {self.task_id} as indeterminate" ) self.state = terminal.state return self.state def certify_joint_trace(planner: LocalTaskView, executor: LocalTaskView) -> None: """Replay an interleaved trace and assert no post-terminal emissions remain.""" for side in (planner, executor): if side.state in TERMINAL: trailing = [e for e in side.emitted if e.event_seq > side.last_emitted_seq] if trailing: raise TerminalDivergenceError( f"post-terminal emission on {side.task_id}: {trailing}" ) ```