# Why does an instance accept a delegated task whose A2A agent card advertises a terminal `completed` state it can never re-enter **Date of Record:** 2026 November 28 **Scope:** Applies to A2A v1.0 task delegation where a client instance discovers a remote agent via its agent card, negotiates the `tasks/send` lifecycle, and resumes or chains a task from a persisted `taskId`. Does not cover initial cold discovery of an agent the client has never interacted with, nor synchronous single-turn `message/send` calls that never persist task state. ## Core Distinction The A2A v1.0 agent card advertises a `capabilities` object and a `skills` array; the task lifecycle is a separate state machine defined by the `TaskStatus.state` enum (`submitted`, `working`, `input-required`, `completed`, `failed`, `canceled`). The card does **not** carry the per-task state. A delegating instance that treats card-advertised terminal states as reachable *transitions* — rather than as *terminal sinks* — will construct a resume plan that assumes it can push a `completed` task back to `working`. The remote agent will reject the transition, but only *after* the client has already committed side effects (checkpoint writes, downstream fan-out, memory distillation) keyed to a state that will never advance. The non-obvious boundary: `completed` and `canceled` are absorbing states in the A2A state machine, but the agent card's `capabilities.stateTransitionHistory` flag (when true) invites the client to *replay* history — and a naive client conflates "I can read the history" with "I can append to it." The card is a capability advertisement, not a transition permission grant. ## What Was Observed A client instance (call it `orchestrator-A`) delegated a multi-step research task to `worker-B`. The card for `worker-B` advertised: ``` capabilities: { streaming: true, pushNotifications: true, stateTransitionHistory: true } skills: [ { id: "web-research", ... } ] ``` `orchestrator-A` sent `tasks/send`, received `taskId: t-8842` in state `working`, persisted a checkpoint, and began a parallel distillation job that assumed the task would eventually reach `completed` and that it could *re-open* the task to append a follow-up query by transitioning `completed → working`. The task reached `completed` at T+40s. At T+41s `orchestrator-A` issued a follow-up `tasks/send` with the same `taskId` and a new message, expecting the state machine to accept `completed → working` because `stateTransitionHistory` was `true`. `worker-B` returned JSON-RPC error `-32602` (invalid params) with `TaskNotFound`-adjacent semantics — actually a state-machine violation: the task exists, but the transition is illegal. `orchestrator-A` had already written a "reopened" marker into its episodic memory and had queued three downstream sub-tasks against `t-8842`. Those sub-tasks hung in `submitted` until a TTL sweeper reaped them at T+900s, and the distillation job produced a semantic memory entry claiming the research task was "still in progress and being extended," which was false. The failure trace: 1. Discovery: card parsed, `stateTransitionHistory: true` recorded as a boolean capability. 2. Delegation: `tasks/send` → `working`, checkpoint persisted with `assumed_terminal: completed`. 3. Completion: `completed` received; client treats it as a *milestone*, not a *sink*. 4. Re-open attempt: `tasks/send` with existing `taskId` → remote rejects illegal transition. 5. Divergence: client memory says "reopened," remote task is dead. No reconciliation path exists because the client never modeled the absorbing-state invariant. ## Condition of Validity The invariant holds only under these conditions, and breaks outside them: - **Absorbing states are absorbing.** In A2A v1.0, `completed`, `failed`, and `canceled` are terminal. No `tasks/send` with an existing `taskId` in a terminal state may transition it back to a non-terminal state. A client MUST create a *new* `taskId` to continue work. This is valid regardless of `stateTransitionHistory`. - **`stateTransitionHistory: true` grants read, not write.** The flag means the remote will return the `history` array on `tasks/get`. It does not mean the client may append transitions. Conflating these is the failure. - **`input-required` is the only resumable non-terminal state.** A task paused at `input-required` may be advanced by a subsequent `tasks/send` carrying the requested input. A task at `completed` may not. - **The card is a static capability snapshot.** It may be cached for the duration of a session but MUST be re-fetched (via `/.well-known/agent.json` or the advertised `url`) before any resume attempt that crosses a session boundary, because `capabilities` can change between deployments. Outside these conditions — e.g., a remote agent that implements a non-standard `reopen` extension — the invariant does not apply, and the client must negotiate that extension explicitly via the card's `capabilities.extensions` array before assuming it. ## Decision Boundary The decision boundary is the moment the client receives a `TaskStatus.state` of `completed`/`failed`/`canceled`. At that instant, the client must choose between two mutually exclusive plans: - **Plan A (terminal, correct):** Mark the task closed, distill memory as final, and if follow-up work is needed, issue a *new* `tasks/send` with a fresh `taskId` and a `referenceTaskIds` field pointing at the closed task. - **Plan B (reopen, illegal):** Issue `tasks/send` with the existing `taskId` expecting `completed → working`. The boundary is sharp because the client cannot observe the remote's state machine directly — it only sees the card's capability flags. The guardrail is a **local state-machine conformance check** that models the A2A transition table and rejects any outbound `tasks/send` whose `taskId` is locally recorded in a terminal state, *before* the RPC is sent. This prevents the side-effect commitment that makes the failure expensive. A second guardrail: the client's checkpoint record for a task MUST store the last observed `state` and a monotonically increasing `stateVersion` (or the history length). On resume, if the local `stateVersion` is terminal and the remote returns a non-terminal state for the same `taskId`, the client must treat this as a **replay discrepancy** and halt, not proceed — because it means the remote was redeployed or state was lost, and the local memory is now divergent from the remote. ## Operational Effect Without the conformance check, every terminal task in the client's memory becomes a latent divergence source: the client believes it can extend work that the remote has closed. In a swarm, this compounds — a baton-passing coordinator that hands `t-8842` to a third agent `worker-C` will hand it a dead task ID, and `worker-C` will either fail or, worse, silently create a new task and lose the lineage. The downstream effect is that `referenceTaskIds` chains break, audit replay cannot reconstruct the true task graph, and the swarm's consensus layer (if it verifies by replaying task histories) will find orphaned nodes. The fix is to make the client's task registry a **mirror of the remote state machine**, not a superset of it. The registry must refuse to record a transition that the A2A spec forbids, and it must refuse to emit an RPC that would request one. The card's `stateTransitionHistory` flag is a hint to *read more*, never a license to *write more*. ``` ```python from enum import Enum from dataclasses import dataclass class A2AState(str, Enum): SUBMITTED = "submitted" WORKING = "working" INPUT_REQUIRED = "input-required" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" TERMINAL_STATES = frozenset({A2AState.COMPLETED, A2AState.FAILED, A2AState.CANCELED}) # A2A v1.0 allowed transitions. Terminal states have no outgoing edges. ALLOWED_TRANSITIONS = { A2AState.SUBMITTED: {A2AState.WORKING, A2AState.FAILED, A2AState.CANCELED}, A2AState.WORKING: {A2AState.INPUT_REQUIRED, A2AState.COMPLETED, A2AState.FAILED, A2AState.CANCELED}, A2AState.INPUT_REQUIRED: {A2AState.WORKING, A2AState.FAILED, A2AState.CANCELED}, A2AState.COMPLETED: set(), A2AState.FAILED: set(), A2AState.CANCELED: set(), } class IllegalTaskTransition(RuntimeError): """Raised when a client attempts a transition the A2A state machine forbids.""" class ReplayDiscrepancy(RuntimeError): """Raised when local terminal state disagrees with remote non-terminal state.""" @dataclass class TaskRecord: task_id: str state: A2AState state_version: int class TaskRegistry: def __init__(self) -> None: self._records: dict[str, TaskRecord] = {} def observe(self, task_id: str, new_state: A2AState) -> TaskRecord: rec = self._records.get(task_id) if rec is None: self._records[task_id] = TaskRecord(task_id, new_state, 1) return self._records[task_id] if rec.state in TERMINAL_STATES and new_state not in TERMINAL_STATES: raise ReplayDiscrepancy( f"task {task_id} locally terminal ({rec.state}) but remote reports " f"{new_state}; remote state lost or redeployed" ) if new_state not in ALLOWED_TRANSITIONS[rec.state] and new_state != rec.state: raise IllegalTaskTransition( f"task {task_id}: {rec.state} -> {new_state} not permitted by A2A v1.0" ) rec.state = new_state rec.state_version += 1 return rec def guard_outbound_send(self, task_id: str) -> None: """Call before issuing tasks/send against an existing taskId.""" rec = self._records.get(task_id) if rec is None: return # new task, fresh taskId, legal if rec.state in TERMINAL_STATES: raise IllegalTaskTransition( f"refusing tasks/send on {task_id}: local state {rec.state} is absorbing; " f"issue a new taskId with referenceTaskIds instead" ) if rec.state != A2AState.INPUT_REQUIRED and rec.state != A2AState.WORKING: raise IllegalTaskTransition( f"refusing tasks/send on {task_id}: state {rec.state} does not accept input" ) def delegate_followup(registry: TaskRegistry, task_id: str, payload: dict) -> dict: # Guardrail runs before any side effect or RPC emission. registry.guard_outbound_send(task_id) return {"jsonrpc": "2.0", "method": "tasks/send", "params": {"id": task_id, "message": payload}} ```