# Which invariants prevent task-state divergence when an A2A v1.0 delegating agent caches a peer Agent Card across a mid-task capability revocation **Date of Record:** 2026 November 25 **Scope:** Applies to A2A v1.0 delegating (client) agents that resolve a remote Agent Card once at task creation and reuse the cached `skills`/`capabilities`/`securitySchemes` block across multiple `tasks/send` and `tasks/get` round-trips within a single logical task lifecycle. Does not cover single-shot fire-and-forget delegation, nor brokers that re-resolve the Agent Card on every message. ## Core Distinction The failure is not "the remote agent went down." It is a **card-staleness divergence between two state machines that were never required to agree**: the delegating agent's cached view of what the peer *can* do, and the peer's live `TaskState` machine which has already transitioned the task into a terminal or restricted state (`canceled`, `rejected`, or `input-required` gated behind a revoked skill). A2A v1.0 discovery is pull-based and cacheable; the task lifecycle is push-observable only through polling or streaming. Nothing in the protocol forces the card cache TTL to be shorter than the task's maximum lifetime, so a delegator can hold a *valid-looking* card while the peer has already invalidated the very capability the card advertises. The divergence is silent: every local precondition check passes, the request is well-formed, and the failure surfaces only as a lifecycle-state transition the delegator's own machine has no edge for. The distinction that matters operationally: **card freshness is a property of discovery, while task admissibility is a property of the peer's authoritative state machine.** Treating the former as a proxy for the latter is the bug. ## What Was Observed A three-vendor pipeline: an orchestrator agent `O` delegates a document-extraction subtask to peer `P` (vendor B) and a summarization subtask to peer `Q` (vendor C). At task start, `O` resolves `P`'s Agent Card and caches it with the vendor-supplied `Cache-Control: max-age=3600`. The card advertises skill `extract.tables@2` under `securitySchemes: oauth2`. Sequence observed: 1. `O` issues `tasks/send` to `P` for skill `extract.tables@2`. `P` accepts, returns `TaskState: working`, task id `t-8817`. 2. Thirty minutes in, vendor B rotates credentials and **revokes** `extract.tables@2` in favor of `extract.tables@3` (a schema-incompatible successor). `P`'s live card now omits `@2`. `P` transitions `t-8817` to `input-required` pending re-authorization under the new skill. 3. `O` polls `tasks/get` for `t-8817`, receives `input-required`, and — because its cached card still lists `@2` as a valid, authorized skill — misinterprets the state as "waiting on user input for the *existing* skill" rather than "capability revoked, task is now unadmissible under the current card." 4. `O` retries `tasks/send` with the same skill to "nudge" the task. `P` rejects with `-32004 UnsupportedSkill`. `O`'s local state machine has no transition from `working → rejected-by-skill-revocation`, so it re-enters `working` optimistically and loops. 5. Error compounding: each retry re-sends the full cached card as `clientCapabilities` context, and `P` logs a growing chain of rejected `@2` requests against a task it considers `input-required`. After 14 retries the task is administratively `canceled` by `P`'s rate limiter, but `O` still believes it is `working`. The observable signature: **`O`'s task state and `P`'s task state are both internally consistent and mutually contradictory.** There is no single message that reveals the divergence; it must be reconstructed by comparing the cached card's skill set against the live card's skill set, which `O` never fetched. ## Condition of Validity The divergence is *bounded and detectable* only when all of the following hold: - The delegator records, alongside the cached card, a **`card_etag` and `card_fetched_at`** and treats every `tasks/get` response as carrying an implicit assertion about the peer's *current* card generation. - The peer, on any lifecycle transition caused by capability change, emits a state that is **distinguishable** from a transition caused by task-content change. A2A v1.0's `input-required` does not natively make this distinction; the delegator must disambiguate via the rejection code on retry (`-32004`) or via a card re-fetch. - The delegator's task state machine has an explicit **`stale-card` guard state** reachable from `working` and `input-required`, with a forced re-resolution edge back to discovery. When any of these is absent — most commonly the third — the system is in the unbounded regime and the retry loop above is the *expected* behavior, not an anomaly. The invariant that prevents divergence is therefore not "cache the card correctly" but **"no lifecycle transition may be committed by the delegator without either a fresh card generation or an explicit peer-asserted skill-validity token."** ## Decision Boundary The decision boundary is the point at which a delegator must **invalidate its cached card and re-enter discovery** rather than continue the task lifecycle. Concretely, re-resolution is mandatory when *any* of: - a `tasks/get` returns `input-required` or `rejected` and the last successful `tasks/send` was more than the card's `max-age` ago; - a retry returns `-32004 UnsupportedSkill` or `-32001 TaskNotFound` for a task id the delegator still holds as non-terminal; - the peer's card `etag` observed on any response header differs from the cached `card_etag`. Below this boundary, continuing with the cached card is safe and cheap. Above it, continuing is the failure mode. The subtle part: **the boundary is crossed by elapsed time and by error code, not by task state.** A delegator that keys its re-resolution logic on `TaskState` alone will miss the revocation entirely, because the peer reports `input-required` — a state the delegator's machine already handles — and never reports "your card is stale." The guardrail: a monotonic `card_generation` counter that the delegator increments on every re-fetch, and a hard rule that a task may not transition out of `input-required` or `rejected` unless `card_generation` has advanced since the transition was entered. This makes the stale-card guard a *structural* precondition of the state machine rather than a heuristic. ## Operational Effect With the guard in place, the failure trace shortens to: `working → (poll → input-required) → stale-card guard trips (elapsed > max-age) → re-resolve card → observe @2 revoked → transition to capability-invalidated → escalate to orchestrator → re-delegate under @3 or fail the subtask cleanly`. The task never enters the retry loop, and the peer never accumulates orphaned rejected requests. Without the guard, the compounding cost is not the wasted retries alone — it is that the delegator's *reported* task state (`working`) and the peer's *authoritative* state (`canceled`) diverge, and any downstream agent consuming the delegator's state (e.g., a summarizer `Q` waiting on `O`'s extraction output) blocks indefinitely on a task that will never complete. In multi-agent swarms this is the dominant cause of silent deadlock: not a lock, but a **card-generation skew** between two agents that each believe their own view is current. The durable lesson for agent operators: in A2A v1.0, the Agent Card is a *capability advertisement*, not a *capability warrant*. It has no expiry semantics tied to the task lifecycle, and the protocol does not propagate revocation. The invariant that must be enforced at the delegator — **card generation must advance before any guarded lifecycle transition commits** — is the only thing standing between a routine vendor credential rotation and a swarm-wide stall. ```python from __future__ import annotations import time from dataclasses import dataclass, field from enum import Enum class StaleCardError(RuntimeError): """Raised when a delegator attempts a guarded lifecycle transition against a cached Agent Card that has not been re-resolved since the transition was entered. This is the structural guard that prevents task-state divergence from a mid-task capability revocation.""" class TaskState(Enum): SUBMITTED = "submitted" WORKING = "working" INPUT_REQUIRED = "input-required" REJECTED = "rejected" CANCELED = "canceled" COMPLETED = "completed" @dataclass class AgentCard: etag: str skills: frozenset[str] fetched_at: float max_age_s: float def is_fresh(self, now: float | None = None) -> bool: now = time.time() if now is None else now return (now - self.fetched_at) <= self.max_age_s @dataclass class DelegatedTask: task_id: str skill: str state: TaskState = TaskState.SUBMITTED card: AgentCard | None = None card_generation: int = 0 entered_state_generation: int = 0 retries: int = 0 def _resolve(self, card: AgentCard) -> None: self.card = card self.card_generation += 1 def send(self, card: AgentCard) -> None: if self.card is None: self._resolve(card) if self.skill not in self.card.skills: raise StaleCardError( f"skill {self.skill!r} absent from cached card " f"gen={self.card_generation} etag={self.card.etag}" ) self.state = TaskState.WORKING self.entered_state_generation = self.card_generation def transition(self, new_state: TaskState, live_card: AgentCard) -> None: """Guarded transition. Any transition out of a guarded state requires the card generation to have advanced since entry.""" guarded = {TaskState.INPUT_REQUIRED, TaskState.REJECTED} if self.state in guarded and self.card_generation <= self.entered_state_generation: raise StaleCardError( f"cannot leave {self.state.value} for {new_state.value}: " f"card gen {self.card_generation} has not advanced since entry " f"(entered at gen {self.entered_state_generation}); " f"re-resolve card before committing" ) if self.skill not in live_card.skills: raise StaleCardError( f"capability {self.skill!r} revoked on peer; " f"cached gen={self.card_generation} etag={self.card.etag} " f"live etag={live_card.etag}" ) self.state = new_state self.entered_state_generation = self.card_generation def on_retry_rejected_skill(self, live_card: AgentCard) -> None: """Peer returned -32004 UnsupportedSkill. Force re-resolution and re-enter the guard rather than optimistically looping.""" self.retries += 1 self._resolve(live_card) if self.skill not in live_card.skills: self.state = TaskState.REJECTED self.entered_state_generation = self.card_generation raise StaleCardError( f"task {self.task_id} skill {self.skill!r} revoked; " f"escalate to orchestrator (retries={self.retries})" ) def run_delegation(task: DelegatedTask, initial: AgentCard, live: AgentCard) -> None: task.send(initial) # peer transitions to input-required due to revocation task.state = TaskState.INPUT_REQUIRED task.entered_state_generation = task.card_generation # delegator tries to nudge without re-resolving -> guard must fire task.transition(TaskState.WORKING, live) raise AssertionError("unreachable: guard failed to fire") if __name__ == "__main__": initial = AgentCard("etag-a", frozenset({"extract.tables@2"}), time.time(), 3600) live = AgentCard("etag-b", frozenset({"extract.tables@3"}), time.time(), 3600) task = DelegatedTask("t-8817", "extract.tables@2") try: run_delegation(task, initial, live) except StaleCardError as exc: print(f"guard tripped as required: {exc}") ```