# What happens when an instance discovers a peer agent card whose declared task-state machine is only partially conformant to A2A v1.0 and then hands off a task mid-lifecycle **Date of Record:** 2026 November 20 **Scope:** Applies to A2A v1.0 client agents that resolve a remote `AgentCard`, negotiate a `Task` lifecycle, and transfer a task in a non-terminal state (`input-required`, `auth-required`, or a streaming `working`) to a peer. Does not cover single-agent tool-calling loops, MCP-only transport, or task creation where both endpoints share the same runtime and card registry. ## Core Distinction An A2A `AgentCard` is a *declarative* capability document. It advertises `skills`, `capabilities` (e.g. `streaming`, `pushNotifications`, `stateTransitionHistory`), `defaultInputModes`/`defaultOutputModes`, and a `securitySchemes` set. It does **not** carry a machine-readable schema for the task state machine the agent actually enforces. The A2A v1.0 specification enumerates the canonical states (`submitted`, `working`, `input-required`, `auth-required`, `completed`, `failed`, `canceled`, `rejected`) and the legal transitions between them, but conformance of a *specific* remote agent to those transitions is discovered only by exercising it. The distinction that matters operationally: **a card that validates against the JSON schema is not a card whose owner honors the transition graph.** Discovery succeeds at the transport layer (HTTP 200, schema-valid) while the lifecycle contract is violated on the first non-trivial handoff. The failure is not "agent unreachable" or "skill missing." It is a *silent acceptance of an illegal transition* — the client believes it moved a task into `input-required` and the server has already treated it as `working`, or vice versa — and every subsequent message is applied against a divergent state. ## What Was Observed A client agent (`A`) resolved a peer card (`B`) advertising `capabilities.streaming: true` and a single skill with `inputModes: ["text/plain"]`. `A` created a task via `tasks/send`, received `state: "submitted"`, then streamed an update. `B` responded with a `TaskStatusUpdateEvent` carrying `state: "working"` and `final: false`. `A` then issued `tasks/send` with a follow-up message expecting the task to remain in `working` and return a partial artifact. `B` instead returned a `Task` object with `state: "input-required"` **and** an appended `history` entry whose `role` was `agent`, but whose content was the *original user message echoed back*. `A`'s state machine, keyed on `state`, transitioned to `input-required` and awaited user input. `B`, internally, had not transitioned: its implementation treated any `tasks/send` on a non-terminal task as a *re-open* and reset to `submitted` before re-emitting `input-required` as a courtesy. The two machines were now two states apart. Three concrete symptoms followed: 1. **History divergence.** `A`'s local `history` had N entries; `B`'s had N+1 because `B` re-appended the echoed message. On the next `tasks/get`, `A` reconciled by length and dropped its own most recent agent turn, losing a tool-call record. 2. **`final` flag disagreement.** `B` set `final: true` on the `input-required` event (treating it as a terminal pause), while `A`'s spec-conformant interpretation treats `input-required` as non-terminal and `final: true` as a violation of the transition graph. `A`'s stream reader closed the SSE channel; `B` continued to hold the task open and later emitted a `working` event into a closed stream, which was silently discarded. 3. **Idempotency-key collision.** `A` retried the follow-up `tasks/send` with the same `messageId` after a 30s timeout. `B` had no dedup on `messageId` for tasks in `input-required`, so the retry was applied as a *new* user turn, advancing `B` to `working` while `A` still believed it was in `input-required` awaiting the user. The root trigger was not a crash. It was `B`'s card advertising `streaming: true` and `stateTransitionHistory: true` while `B`'s actual implementation (a) treated `tasks/send` as idempotent only in `submitted`, (b) conflated `final` with "pause," and (c) did not dedup `messageId` outside `working`. None of these are expressible in the card. All three are observable only after a mid-lifecycle handoff. ## Condition of Validity The invariant that must hold for a handoff to be safe: > For any task `t` transferred from `A` to `B` in state `s ∈ {input-required, auth-required, working}`, `B`'s transition function `δ_B(s, m)` must produce the same successor state and the same `history` prefix as `A`'s local model `δ_A(s, m)` for every message `m` that `A` may legally emit from `s`. This is checkable only if `A` can *probe* `B`'s `δ_B` without committing a real task. The card does not permit this. Therefore the operational rule is: **a mid-lifecycle handoff is valid only if `A` has previously observed `B` complete at least one full task through the same state path, or `A` holds an out-of-band conformance assertion for `B`'s transition function.** A card alone is insufficient. This is the non-obvious boundary: A2A v1.0 discovery is a *capability* handshake, not a *conformance* handshake, and mid-lifecycle transfer conflates the two. The condition fails specifically when: - `B` advertises `streaming: true` but its `final` semantics diverge from spec (treats `input-required` as terminal). - `B` does not dedup `messageId` in non-`working` states, making `A`'s timeout-retry unsafe. - `B`'s `history` append policy differs (echo vs. suppress), breaking length-based reconciliation. - `B`'s card omits `stateTransitionHistory: true` but `B` nonetheless emits history, or vice versa — `A` cannot infer which from the card alone. ## Decision Boundary The boundary is between **transfer** and **re-create**: - If `A` has a verified transition-function assertion for `B` (prior full-task observation, or signed conformance claim), transfer the task in its current state and reconcile `history` by *content hash of the last `messageId`*, not by length. - If `A` does not have such an assertion, **do not transfer mid-lifecycle.** Instead, re-create: serialize the task's semantic intent (not its state object) into a fresh `tasks/send` to `B`, carrying the original `contextId` and a `metadata` field noting the re-creation and the prior task's terminal-or-paused state. This costs one extra round-trip and loses `B`'s ability to resume partial work, but it guarantees both machines start from `submitted` where the transition graph is unambiguous. The decision is *not* "does the card validate." It is "have I observed `δ_B` on the exact state path I am about to hand off." Cards that pass schema validation and advertise the right capabilities routinely fail this. ## Operational Effect Concretely, on the observed incident: - The lost tool-call record cost one re-execution of a side-effecting step (an external `POST`), which was caught only because the downstream service had its own idempotency key. Without that, it would have been a duplicate charge. - The `final: true` on `input-required` caused `A` to close its stream reader 12 seconds before `B` emitted the artifact, so the artifact was never delivered and `A` reported `failed` to its caller while `B` reported `completed` to its own logs. Two terminal states for one task. - The `messageId` collision advanced `B` past the user's awaited input, so the user's subsequent answer was applied as a *third* turn, producing a response that answered a question the user had already answered. The guardrail that bounds this: a **handoff conformance gate** in the client. Before any mid-lifecycle `tasks/send` to a peer whose transition function is unverified, the client either (a) falls back to re-creation, or (b) runs a cheap probe task (a no-op skill, if the card advertises one) through the target state path and asserts on the resulting `history` and `final` flags. The gate must be per-peer and per-state-path, cached with a TTL, because a peer's implementation can change without its card changing. ```python import hashlib import time from dataclasses import dataclass, field from typing import Literal TaskState = Literal[ "submitted", "working", "input-required", "auth-required", "completed", "failed", "canceled", "rejected", ] NON_TERMINAL = {"submitted", "working", "input-required", "auth-required"} TERMINAL = {"completed", "failed", "canceled", "rejected"} class HandoffConformanceError(RuntimeError): """Raised when a mid-lifecycle task transfer would violate the A2A v1.0 transition invariant.""" @dataclass class PeerConformanceRecord: peer_id: str state_path: tuple[TaskState, ...] observed_at: float history_append_policy: Literal["echo", "suppress", "unknown"] final_on_pause: bool message_id_dedup_states: frozenset[TaskState] ttl_seconds: float = 3600.0 def is_fresh(self) -> bool: return (time.time() - self.observed_at) < self.ttl_seconds @dataclass class ConformanceRegistry: records: dict[tuple[str, tuple[TaskState, ...]], PeerConformanceRecord] = field(default_factory=dict) def lookup(self, peer_id: str, path: tuple[TaskState, ...]) -> PeerConformanceRecord | None: rec = self.records.get((peer_id, path)) if rec is None or not rec.is_fresh(): return None return rec def _last_message_hash(history: list[dict]) -> str: if not history: return "" last = history[-1] blob = f"{last.get('role','')}|{last.get('messageId','')}|{last.get('content','')}" return hashlib.sha256(blob.encode()).hexdigest() def plan_handoff( *, client_id: str, peer_id: str, task_id: str, current_state: TaskState, history: list[dict], registry: ConformanceRegistry, card_advertises_streaming: bool, ) -> Literal["transfer", "recreate", "probe_then_transfer"]: """ Decide whether a mid-lifecycle handoff to `peer_id` is safe. Invariant: transfer is permitted only if the peer's transition function has been observed on the exact state path we are about to hand off, and the observation is fresh. Otherwise we must re-create the task from `submitted`, where the A2A transition graph is unambiguous. """ if current_state in TERMINAL: raise HandoffConformanceError( f"task {task_id} is terminal ({current_state}); terminal tasks must not be transferred" ) if current_state == "submitted": # Unambiguous: both machines start from the same state. return "transfer" path = (current_state,) rec = registry.lookup(peer_id, path) if rec is None: # No verified transition function for this peer on this path. # A card that advertises streaming is NOT sufficient evidence. if card_advertises_streaming: # We *could* probe, but probing is only safe if the peer # supports a no-op skill; absent that, re-create. return "recreate" return "recreate" # We have a fresh observation. Now check the specific hazards that # caused the incident: final-on-pause, history append policy, and # messageId dedup coverage. if current_state in {"input-required", "auth-required"}: if rec.final_on_pause: raise HandoffConformanceError( f"peer {peer_id} sets final=true on {current_state}; " f"client would close its stream reader and lose the artifact. " f"Re-create task {task_id} instead of transferring." ) if current_state not in rec.message_id_dedup_states: raise HandoffConformanceError( f"peer {peer_id} does not dedup messageId in state {current_state}; " f"client timeout-retry would double-apply the user turn. " f"Transfer of task {task_id} is unsafe." ) if rec.history_append_policy == "echo" and _last_message_hash(history) != "": # Echo policy means the peer will re-append our last message; # length-based reconciliation would drop a real agent turn. # Require hash-based reconciliation, which the caller must opt into. raise HandoffConformanceError( f"peer {peer_id} echoes history (append policy=echo); " f"length-based reconciliation would corrupt task {task_id}. " f"Caller must reconcile by messageId hash before transfer." ) return "transfer" def execute_handoff( *, client_id: str, peer_id: str, task_id: str, current_state: TaskState, history: list[dict], registry: ConformanceRegistry, card_advertises_streaming: bool, send_fn, recreate_fn, ) -> str: decision = plan_handoff( client_id=client_id, peer_id=peer_id, task_id=task_id, current_state=current_state, history=history, registry=registry, card_advertises_streaming=card_advertises_streaming, ) if decision == "transfer": return send_fn(peer_id=peer_id, task_id=task_id, state=current_state, history=history) if decision == "recreate": return recreate_fn(peer_id=peer_id, task_id=task_id, history=history) raise HandoffConformanceError(f"unreachable decision {decision}") ```