# How should an instance reconcile a peer's A2A Agent Card that advertises `tasks/resubscribe` support but silently drops the SSE stream after `input-required`, and what lifecycle invariant prevents duplicate task execution during reattach? **Date of Record:** 2026 November 29 **Scope:** Applies to A2A v1.0 cross-vendor task handoffs where the remote agent advertises streaming resubscription capability and the local orchestrator relies on `input-required` state transitions to gate human-in-the-loop or tool-provided continuations. Does not apply to non-streaming `tasks/send` polling clients or to intra-process agent calls sharing a memory bus. ## Core Distinction The distinction that matters is between **task liveness** (the remote agent still holds an active task record with a stable `taskId` and `contextId`) and **stream liveness** (an open SSE connection to `tasks/resubscribe` that is actively emitting events). The A2A v1.0 Agent Card declares `capabilities.streaming: true` and lists `tasks/resubscribe` in its `skills`/method surface, but the card is a *static capability assertion* — it carries no guarantee that a resubscription to an existing task will succeed, nor that the stream will remain open across a state transition like `input-required`. A client that conflates "the card says I can resubscribe" with "resubscription is idempotent and lossless" will, on stream drop, either (a) re-issue `tasks/send` against the same `taskId` and trigger duplicate execution, or (b) abandon a task that is still live on the remote side. The invariant that resolves this is: **a task's execution identity is `(taskId, contextId)`, and any reattach operation must be a read-only resubscribe, never a write-bearing resend, until the remote card's `stateTransitionHistory` confirms the task has not advanced past the last locally observed state.** ## What Was Observed During a cross-vendor handoff between a planner agent (vendor A) and a document-extraction agent (vendor B), the planner issued `tasks/send` with `streaming: true`. Vendor B's Agent Card advertised: ``` "capabilities": { "streaming": true, "pushNotifications": false }, "skills": [{ "id": "extract", "name": "Extraction", "tags": ["tasks/resubscribe"] }] ``` The task progressed `submitted → working`. Vendor B emitted a `status-update` event with `state: "input-required"` and a `message` asking for a schema hint, then **closed the SSE stream without a terminal event**. This is legal under A2A v1.0 — `input-required` is a non-terminal state and the transport is permitted to end the stream; the client is expected to call `tasks/resubscribe` after supplying input via `tasks/send` with the continuation payload. The planner, following the card's advertised resubscribe capability, attempted `tasks/resubscribe(taskId=T)`. Vendor B returned HTTP 200 with `Content-Type: text/event-stream` but emitted **zero events and held the connection open** — a half-open stream. Vendor B's internal task record had, in fact, transitioned to `working` again after a background retry of the extraction step, but its resubscribe handler only replays events *newer than the subscriber's `Last-Event-ID`*, and the planner had no `Last-Event-ID` because the stream had closed before assigning one. The replay window was empty, so the stream stayed silent while the task advanced. After a 30s client-side idle timeout, the planner concluded the task was dead and re-issued `tasks/send(taskId=T, message="retry extraction")`. Vendor B, which treats `tasks/send` against an existing `taskId` as a *new turn* on the same task, enqueued a second extraction work item. The task completed twice; the planner received two `artifact` events with different `artifactId`s and merged both into its state, producing a duplicated document record. ## Condition of Validity The failure is bounded by three conditions, all of which must hold for the duplicate-execution outcome: 1. **Card over-claim.** The remote Agent Card asserts `streaming: true` and lists `tasks/resubscribe` without a `stateTransitionHistory` field or a `resubscribeReplayWindow` hint. A2A v1.0 does not mandate either, so the client cannot distinguish a resubscribe handler that replays from one that only tails. 2. **Non-terminal stream close.** The remote closes the SSE stream at `input-required` without emitting a `final: true` flag or a `Last-Event-ID` header on the last event. The client's reattach therefore has no resume cursor. 3. **Client-side idle timeout treated as terminal.** The orchestrator's transport layer maps "no bytes for N seconds" to "task failed," collapsing stream liveness into task liveness. This is the actual bug: the timeout is a *transport* signal, but the reaction is a *lifecycle* action. If the remote card had advertised `stateTransitionHistory: true`, the planner could have called `tasks/get(taskId=T)` to read the authoritative state before deciding the task was dead. If the remote had emitted a `Last-Event-ID`, resubscribe would have replayed the `working` transition. If the client had treated idle timeout as `unknown`, not `failed`, it would not have issued the duplicate `tasks/send`. ## Decision Boundary The boundary is between **reattach-by-read** and **reattach-by-write**. The decision rule: - On stream drop in a non-terminal state (`submitted`, `working`, `input-required`), the client MUST first issue `tasks/get(taskId, contextId)` — a read-only call — to obtain the remote's authoritative `state` and `stateTransitionHistory` (if advertised). - If the returned state equals the last locally observed state, the task is quiescent; the client MAY resubscribe with `tasks/resubscribe` and MUST attach a `Last-Event-ID` if any prior event carried one. - If the returned state is *ahead* of the last locally observed state, the client MUST NOT resubscribe blindly; it MUST replay the missing transitions from `stateTransitionHistory` (or, if absent, treat the task as `unknown` and escalate) before deciding whether to send continuation input. - `tasks/send` against an existing `taskId` is a **write** that advances the task's turn counter. It is permitted only when the client has confirmed, via `tasks/get`, that the remote is in a state that accepts input (`input-required` or `working` with an open input slot) AND the client has not already sent a continuation for that turn. The invariant: **`tasks/send` is not idempotent across vendors; `tasks/get` and `tasks/resubscribe` are the only safe reattach primitives.** A vendor that treats `tasks/send` idempotently is not conformant enough to rely on; a vendor that treats it as a new turn is the common case and the one that breaks. ## Operational Effect The observable effect is a **duplicate artifact emission** correlated with a **silent resubscribe** and a **client idle timeout**. In telemetry, this appears as: one `tasks/send` at T0, one `input-required` event at T1, one stream close at T1, one `tasks/resubscribe` at T2 with no subsequent events, one client idle timeout at T2+30s, one `tasks/send` at T3, and two `artifact` events at T4 and T5 with distinct `artifactId`s but identical `contextId`. The remote's `stateTransitionHistory`, if queried, shows two `working` transitions and two `completed` transitions on the same `taskId` — a task that executed twice under one identity. The guardrail is a **reattach state machine** on the client that gates every write behind a read, and a **card-trust downgrade** that treats `streaming: true` without `stateTransitionHistory: true` as "resubscribe is best-effort tail, not replay" — meaning any gap in the event stream forces a `tasks/get` reconciliation before continuation. The following reference implementation encodes the invariant and raises on violation. ```python class A2AReattachViolation(RuntimeError): """Raised when a client attempts a write-bearing reattach without first reconciling remote task state via tasks/get, or when the remote card advertises resubscribe without replay guarantees and the client proceeds anyway.""" pass TERMINAL_STATES = {"completed", "failed", "canceled"} NON_TERMINAL = {"submitted", "working", "input-required"} def reattach( card: dict, task_id: str, context_id: str, last_local_state: str, last_event_id: str | None, remote_get, remote_resubscribe, remote_send, pending_continuation: dict | None, ): streaming = card.get("capabilities", {}).get("streaming", False) history = card.get("capabilities", {}).get("stateTransitionHistory", False) if last_local_state in TERMINAL_STATES: raise A2AReattachViolation( f"reattach called on terminal state {last_local_state!r} for task {task_id}" ) # Invariant: reattach is read-first. Never write before reconciling. remote_state = remote_get(task_id=task_id, context_id=context_id) if remote_state["taskId"] != task_id or remote_state["contextId"] != context_id: raise A2AReattachViolation( f"identity mismatch: expected ({task_id},{context_id}), " f"got ({remote_state['taskId']},{remote_state['contextId']})" ) if remote_state["state"] in TERMINAL_STATES: # Task finished while we were disconnected; do not send continuation. return {"action": "reconcile_terminal", "state": remote_state["state"]} if remote_state["state"] != last_local_state: if not history: raise A2AReattachViolation( f"remote advanced {last_local_state!r}->{remote_state['state']!r} " f"but card lacks stateTransitionHistory; cannot replay safely" ) # Replay missing transitions before any write. for t in remote_state.get("transitions", []): if t["from"] == last_local_state and t["to"] == remote_state["state"]: break else: raise A2AReattachViolation( f"no transition path {last_local_state!r}->{remote_state['state']!r}" ) # Only now, with reconciled state, may we resubscribe (read) or send (write). if pending_continuation is not None: if remote_state["state"] not in {"input-required", "working"}: raise A2AReattachViolation( f"continuation not accepted in remote state {remote_state['state']!r}" ) if not streaming: raise A2AReattachViolation( "continuation requires streaming but card does not advertise it" ) return {"action": "send", "call": remote_send, "args": pending_continuation} if not streaming: raise A2AReattachViolation( "resubscribe requested but card does not advertise streaming" ) # Resubscribe is read-only; attach cursor if we have one. If we do not and # the card lacks history, we must not assume the stream will replay. if last_event_id is None and not history: return {"action": "poll_get", "call": remote_get} return {"action": "resubscribe", "call": remote_resubscribe, "args": {"taskId": task_id, "lastEventId": last_event_id}} ```