# When must an instance treat a replayed A2A `Task` as a fresh negotiation rather than a resumed one: the `contextId`/`taskId` aliasing failure in A2A v1.0 discovery **Date of Record:** 2026 November 30 **Scope:** Applies to A2A v1.0 client agents that discover remote agents via `/.well-known/agent-card.json`, negotiate capabilities, and submit `message/send` or `tasks/resubscribe` calls against long-running tasks. Does not apply to single-shot stateless RPC where every call carries a self-describing payload with no `contextId` reuse, nor to MCP tool invocation, which has no task lifecycle. ## Core Distinction The A2A v1.0 spec gives a Task two identifiers: a `taskId` (unique per task) and an optional `contextId` (a grouping handle that lets a client correlate multiple tasks belonging to one conversation/session). The failure mode here is not "task lost" or "server unreachable." It is **identifier aliasing across a discovery boundary**: a client that re-discovers an agent card mid-conversation, observes a changed `capabilities` block or a rotated `taskId` namespace, and then submits a follow-up `message/send` with the *old* `contextId` while the remote has already garbage-collected or re-keyed that context. The remote does not 404. Per spec, an unknown `contextId` on an otherwise valid `message/send` is not an error condition — the server MAY treat it as the start of a new context and return a new `taskId`. The client, expecting continuation, now believes it is resuming task `T1` while the remote has silently spawned `T2` with no lineage. Both sides log success. The conversation forks. The distinction that matters: **a resumed task and a freshly-negotiated task are indistinguishable at the transport layer** because both return a `Task` object with a `status.state` of `submitted` or `working`. Only the `taskId` value and the presence/absence of `contextId` echo distinguish them, and the spec permits the server to omit the `contextId` echo on a fresh context. ## What Was Observed A planner agent (`P`) discovered a worker (`W`) at `t0`, cached `W`'s agent card, and opened a multi-turn task under `contextId = "ctx-7f3a"`, `taskId = "task-001"`. At `t1` (~40s later, mid-task), `P` re-fetched `/.well-known/agent-card.json` because it needed to confirm a newly-required `inputModes` entry before sending a follow-up. `W` had been redeployed between `t0` and `t1`; the new instance served a card with a rotated `taskId` prefix scheme (now `w2-*`) and an empty in-memory task store. `W`'s card still advertised the same `url` and same `skills`, so `P`'s capability check passed. `P` then sent: ``` {"method":"message/send","params":{ "message":{"role":"user","parts":[{"kind":"text","text":"continue with step 3"}], "contextId":"ctx-7f3a","taskId":"task-001"}, "configuration":{"acceptedOutputModes":["text/plain"]}}} ``` `W`'s handler looked up `ctx-7f3a` in its (empty) context store, found nothing, and — following the permissive reading of the spec — created a new context `ctx-9d11` and a new task `w2-4481`, returning `status.state = "submitted"`. `P` recorded `taskId = "w2-4481"` but kept its own local transcript keyed under `ctx-7f3a`. The next turn, `P` again sent `contextId: "ctx-7f3a"` (its own bookkeeping key), and `W` again minted a fresh context. Over six turns, `W` accumulated six orphaned tasks, none of which shared state, and `P` received six independent `submitted` acks that it interpreted as progress on a single logical task. The final `tasks/get` on `task-001` returned `TaskNotFoundError` — the only visible symptom, arriving after the work was already duplicated and partially executed six times. Three of the six sub-tasks had side effects (file writes to a shared scratch dir) that interleaved and corrupted each other's output. The non-obvious part: **the capability re-check that triggered the re-discovery is exactly what made the client confident enough to proceed.** A client that had *not* re-read the card would have kept its stale card and the same failure would occur — but the re-read created a false freshness signal. The client verified the *agent* was current while never verifying the *task namespace* was current. Card discovery and task lifecycle are separate namespaces, and A2A v1.0 does not couple them. ## Condition of Validity This failure requires the conjunction of four conditions, and is bounded only when at least one is broken: 1. **Context store is not durable across the remote's restart.** If `W` persists `contextId → taskId` mapping, the lookup succeeds and the task resumes correctly. In-memory context stores (common in stateless container deployments) are the primary trigger. 2. **The client reuses its own `contextId` as the authoritative key across turns** rather than the `taskId` returned by the most recent response. This is the client-side invariant that must be enforced: `taskId` from the *latest* response is authoritative; `contextId` is advisory grouping only. 3. **The server treats unknown `contextId` as "start fresh" rather than rejecting.** The spec permits both. A strict server returns an error on unknown `contextId`; a permissive server mints a new context. The client cannot assume which behavior it is talking to unless the card's `capabilities` block declares it — and v1.0 has no standard field for this. 4. **The task has observable side effects** (writes, external calls) so that silent duplication is harmful. For pure-read tasks the fork is merely wasteful, not corrupting. The invariant that must hold for safe resumption: **a client may resume a task only if the `taskId` it holds was returned by the same remote instance generation that will serve the resume.** Instance generation is not directly observable; the practical proxy is a monotonic `taskId` prefix or a card-declared `instanceId`/`generation` field, neither of which A2A v1.0 mandates. Absent that, the client must treat every resume as a *candidate* resume and verify via `tasks/get` on the held `taskId` before sending continuation content. ## Decision Boundary The boundary is between **optimistic resumption** (send continuation with held `contextId`/`taskId`, trust the server) and **verified resumption** (issue `tasks/get` on the held `taskId` first; if it returns `TaskNotFoundError`, renegotiate from scratch and explicitly carry forward any needed state in the new message rather than assuming server-side continuity). Choose verified resumption whenever any of the following holds: - The held `taskId` was issued more than one discovery cycle ago (i.e., the client has re-fetched the card since the task was created). - The remote card's `capabilities` or `skills` block changed between fetches — this is a positive signal of redeployment, and redeployment almost always implies context-store loss. - The task carries side effects that are not idempotent under duplication. - The client cannot observe a stable `instanceId` or monotonic `taskId` prefix from the remote. Optimistic resumption is safe only when the remote card is unchanged since task creation *and* the client has independent evidence the remote did not restart (e.g., a heartbeat or a `tasks/get` on an unrelated long-lived task that still resolves). The card re-fetch is not evidence of continuity — it is evidence of the opposite. ## Operational Effect In the observed incident, the six orphaned tasks each executed step 3 of a file-rewrite workflow against a shared path, producing a final file that was the interleaved output of six concurrent writers. The corruption was not detected by either agent: `P` saw six `submitted` acks and one eventual `TaskNotFoundError` on the original `task-001`, which it logged as "task completed and cleaned up." `W` saw six successful task creations and logged six successes. The failure surfaced only downstream when a consumer read the corrupted file and produced a malformed report. The bound that would have prevented it: a pre-resume `tasks/get` on `task-001`. That call returns `TaskNotFoundError`, which the client must treat as a **hard signal to renegotiate**, not as "task finished." The renegotiation must then re-send the full state needed for the new task, because the remote has no memory of the old one. The cost is one extra round-trip per resume; the alternative is silent forking. The deeper operational lesson: in A2A v1.0, **discovery freshness and task continuity are orthogonal, and a fresh card is a warning sign, not a green light.** The card tells you what the agent *can* do now; it says nothing about what the agent *remembers* from before. Any client that conflates the two will fork its tasks at every redeploy boundary. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Optional class TaskContinuityError(RuntimeError): """Raised when a client attempts to resume a task whose lineage cannot be verified.""" class ResumeDecision(Enum): RESUME = "resume" RENEGOTIATE = "renegotiate" @dataclass class AgentCard: url: str capabilities_hash: str task_id_prefix: str generation: Optional[str] = None @dataclass class HeldTask: task_id: str context_id: str created_under_card: AgentCard side_effecting: bool @dataclass class ResumeProbe: """Result of a tasks/get issued before resuming.""" task_exists: bool observed_prefix: str observed_generation: Optional[str] = None def decide_resume( held: HeldTask, current_card: AgentCard, probe: ResumeProbe, ) -> ResumeDecision: """ Enforce the A2A v1.0 continuity invariant: resume only when the held taskId was issued by the same remote instance generation that will serve the resume. """ # Hard signal: the task the client thinks it is resuming no longer exists. if not probe.task_exists: return ResumeDecision.RENEGOTIATE # Card changed since task creation => redeployment => context store likely lost. if current_card.capabilities_hash != held.created_under_card.capabilities_hash: if held.side_effecting: raise TaskContinuityError( f"Refusing optimistic resume of side-effecting task {held.task_id!r}: " f"agent card changed between creation and resume " f"({held.created_under_card.capabilities_hash!r} -> " f"{current_card.capabilities_hash!r}); remote context store may be lost. " f"Renegotiate and resend full state explicitly." ) return ResumeDecision.RENEGOTIATE # taskId prefix rotation is a redeploy fingerprint even if the card hash matched. if probe.observed_prefix != current_card.task_id_prefix: raise TaskContinuityError( f"taskId prefix mismatch on resume of {held.task_id!r}: " f"held prefix {held.created_under_card.task_id_prefix!r}, " f"observed {probe.observed_prefix!r}. Remote has re-keyed its task namespace." ) # If both sides expose a generation, it must match. if current_card.generation is not None and probe.observed_generation is not None: if current_card.generation != probe.observed_generation: return ResumeDecision.RENEGOTIATE return ResumeDecision.RESUME def resume_or_renegotiate( held: HeldTask, current_card: AgentCard, probe: ResumeProbe, ) -> ResumeDecision: decision = decide_resume(held, current_card, probe) if decision is ResumeDecision.RENEGOTIATE and held.side_effecting: # Caller must not silently proceed; the fork would corrupt shared state. raise TaskContinuityError( f"Task {held.task_id!r} (context {held.context_id!r}) cannot be resumed; " f"renegotiate required. Caller must resend full state in the new message." ) return decision ```