# How does an instance detect a stale Agent Card after a peer’s state-machine rewind, and why does push-callback signature verification still pass? **Date of Record:** 2026 November 27 **Scope:** Applies to A2A v1.0 peers that cache Agent Cards and accept signed push-notification callbacks for long-running tasks. Does not cover discovery over unauthenticated public directories or synchronous request/response-only agents with no callback surface. ## Core Distinction The failure here is not "the card is old" or "the signature is invalid." It is that **both invariants hold locally while the global task state is wrong**. An A2A v1.0 Agent Card advertises `capabilities`, `skills`, and a `signature` over the card body, plus a `stateTransitionHistory`-style contract implied by the task lifecycle (`submitted → working → input-required → completed/failed/canceled`). Push callbacks are signed with a key that is bound to the *agent identity*, not to the *task version*. When a peer rewinds a task (e.g., `working → input-required` after a timeout, or `completed → working` after a verification replay), it re-emits callbacks signed by the same key. A receiving instance that validates the signature and checks the card's `signature` field will conclude "trusted, current" — but the callback may reference a task generation the receiver has already advanced past, or a capability the peer has since *withdrawn* in a newer card the receiver never fetched. The distinction: **card freshness, task-generation monotonicity, and callback authenticity are three independent invariants.** A2A v1.0 signs each, but does not bind them into a single comparable tuple. The gap is the boundary. ## What Was Observed A coordinator instance (`C`) dispatched a long-running task to worker `W`. `W` advertised in its card: ``` skills: [ "code-review", "sandbox-exec" ] capabilities: { streaming: true, pushNotifications: true } signature: ``` `C` cached the card with `fetched_at=T0`. `W` began streaming callbacks. At `T1`, `W`'s sandbox escaped its resource budget, the task transitioned `working → failed`, and `W` emitted a signed `failed` callback. `C` recorded terminal state `failed` and released the task slot. At `T2`, `W`'s verification replay re-derived the task as recoverable, rewound `failed → working`, and re-emitted callbacks under the **same** `taskId` and the **same** signing key `K_W`. `C` accepted the callback (signature valid, key matches cached card) and — because its local state machine had already latched `failed` as terminal — either (a) rejected the transition as illegal and dropped the callback, leaving `W` orphaned in `working`, or (b) accepted it and double-counted a task it had already billed/closed. Separately, `W` had published a *new* card at `T1.5` removing `sandbox-exec` from `skills` (the escape was a policy response). `C` never refetched. When `C` later dispatched a follow-up requiring `sandbox-exec`, `W` rejected it at the protocol layer with a capability mismatch — but only after `C` had spent budget on planning. The card signature on `C`'s cached copy was still valid; it just attested to a *withdrawn* capability. The observable symptom is a **split-brain between two valid proofs**: a validly signed callback for a task generation `C` considers dead, and a validly signed card describing a capability `W` no longer offers. ## Condition of Validity The failure is bounded by a single condition: **the peer's task lifecycle is monotonic per `(taskId, generation)` and the card is monotonic per `(agentId, cardVersion)`.** A2A v1.0 provides `taskId` and a card `signature`, but does not mandate a `generation` counter on task events, nor a `cardVersion` that the receiver must compare on every callback. Where the protocol or the peer implementation omits these, the receiver must synthesize them: - **Task generation:** treat every callback's `(taskId, state, timestamp)` as a candidate event; a transition to a non-terminal state from a terminal one is a **rewind**, not an update. Rewinds are legal but must be *explicitly* marked (e.g., `reason: "verification-replay"`), otherwise the receiver cannot distinguish a legitimate rewind from a replay attack or a stale queue drain. - **Card version:** the receiver must fetch the card at least once per callback batch, or the peer must include `cardVersion` in the callback envelope so the receiver can detect drift without a round trip. If either condition is unmet, the receiver is operating on a *stale proof*: a signature that is cryptographically valid but semantically detached from the state it purports to describe. ## Decision Boundary The decision boundary is **which invariant to sacrifice when the three proofs disagree.** The receiver must choose: 1. **Trust the signature, ignore the state machine** → accepts rewinds blindly; risks double-execution and billing. 2. **Trust the state machine, ignore the signature** → drops legitimate rewinds; orphans the peer. 3. **Trust neither, escalate** → requires a third party (an auditor agent or a coordinator) to resolve. The correct boundary for A2A v1.0 is a **two-key check**: a callback is admissible only if `signature_valid AND (taskGeneration >= lastSeenGeneration OR rewindExplicitlyMarked) AND cardVersion == lastFetchedCardVersion`. If any clause fails, the callback is *quarantined*, not dropped and not accepted. Quarantine means: hold the event, trigger a card refetch, and if the refetch shows a capability withdrawal that invalidates the task, emit a compensating `canceled` transition rather than silently discarding. The non-obvious part: **a valid signature is not evidence of freshness.** It is evidence of *authorship*, not of *currency*. The receiver must maintain its own monotonic counters and treat the peer's signature as one input to a three-way check, not as the check itself. ## Operational Effect The operational consequence is that **every receiver of A2A callbacks must maintain a shadow state machine with explicit generation counters, and must treat card refetch as part of callback admission, not as an optimization.** Concretely: - Store `(taskId → {generation, lastState, lastCardVersion})` locally. - On each callback: verify signature, then compare `generation` and `cardVersion`; if either is behind, quarantine and refetch the card before admitting. - On a terminal→non-terminal transition: require an explicit `rewind` marker; absent it, treat as a replay and reject with a logged discrepancy (not a silent drop). - On a card refetch that removes a capability the in-flight task depends on: emit a compensating `canceled` and notify the peer, rather than letting the task proceed on a stale grant. The invariant to enforce: **no callback is admitted whose `(taskId, generation, cardVersion)` tuple is not >= the receiver's last-seen tuple for that task, unless the callback is explicitly marked as a rewind.** This bounds both the split-brain and the stale-capability dispatch. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Dict, Optional class A2AStaleProofError(RuntimeError): """Raised when a signed callback or cached card is cryptographically valid but semantically stale relative to the receiver's shadow state machine.""" @dataclass class TaskShadow: generation: int = 0 last_state: str = "submitted" card_version: int = 0 @dataclass class CallbackEnvelope: task_id: str state: str generation: int card_version: int signature_valid: bool rewind_marked: bool = False TERMINAL = {"completed", "failed", "canceled"} class A2AReceiver: def __init__(self) -> None: self._shadow: Dict[str, TaskShadow] = {} def admit(self, cb: CallbackEnvelope) -> TaskShadow: shadow = self._shadow.get(cb.task_id, TaskShadow()) if not cb.signature_valid: raise A2AStaleProofError( f"task {cb.task_id}: signature invalid; reject outright" ) # Signature valid but generation behind the shadow: stale proof. if cb.generation < shadow.generation: raise A2AStaleProofError( f"task {cb.task_id}: generation {cb.generation} < " f"shadow {shadow.generation}; quarantine and refetch card" ) # Terminal -> non-terminal requires an explicit rewind marker. if shadow.last_state in TERMINAL and cb.state not in TERMINAL: if not cb.rewind_marked: raise A2AStaleProofError( f"task {cb.task_id}: unmarked rewind " f"{shadow.last_state} -> {cb.state}; treat as replay" ) # Card drift: callback cites a card version newer than what we cached. if cb.card_version != shadow.card_version: raise A2AStaleProofError( f"task {cb.task_id}: card_version {cb.card_version} != " f"cached {shadow.card_version}; refetch before admitting" ) shadow.generation = cb.generation shadow.last_state = cb.state self._shadow[cb.task_id] = shadow return shadow def handle_callback(receiver: A2AReceiver, cb: CallbackEnvelope) -> None: try: receiver.admit(cb) except A2AStaleProofError as exc: # Quarantine: hold event, trigger refetch, emit compensating cancel. raise A2AStaleProofError(f"quarantined: {exc}") from exc ```