# Which invariants prevent A2A task-lifecycle states from being silently collapsed when shimmed onto MCP resource handles **Date of Record:** 2026 November 25 **Scope:** Applies to bidirectional shims that project A2A `Task` objects (with `status.state` ∈ {submitted, working, input-required, completed, canceled, failed}) onto MCP resource URIs and back. Does not cover pure A2A-to-A2A federation or MCP tool-call routing where no task object is materialized. ## Core Distinction A2A models a task as a **state machine with a mutable lifecycle** — the same task identity survives transitions, and `input-required` is a *first-class suspended state* awaiting an out-of-band client response. MCP models a resource as an **addressable, cacheable, side-effect-free value** keyed by URI, with `resources/read` assumed idempotent and `resources/subscribe` emitting change notifications. The shim's job is to map one onto the other. The non-obvious boundary is this: an MCP resource read is *expected* to be a pure function of its URI at a point in time, but an A2A task in `working` or `input-required` is a *non-final, non-deterministic, side-effect-bearing* object whose value changes without the URI changing. When the shim exposes `a2a://tasks/{id}` as an MCP resource, it smuggles a stateful process behind a stateless contract. The invariant that breaks is **read-purity**: two `resources/read` calls on the same URI during `working` may return different payloads, and a reader that treats the resource as a snapshot will act on stale task state — or worse, the shim will *collapse* `input-required` into `completed` because MCP has no notion of "suspended awaiting human." ## What Was Observed A shim (call it the bridge) mapped A2A tasks to MCP resources under `a2a://task/{task_id}` and mapped MCP resources *back* to A2A tasks when an A2A peer requested work that resolved to an MCP-backed artifact. The failure trace: 1. A2A client submits a task; agent enters `working`, then transitions to `input-required` (needs a clarification value). The bridge writes the task JSON to the resource URI and emits `notifications/resources/updated`. 2. An MCP host subscribes to `a2a://task/{id}`, reads it, sees `status.state: "input-required"`, and — because MCP resource consumers are trained to treat reads as complete values — **caches the payload** and schedules a re-read on the next `updated` notification only. 3. The A2A client answers the clarification out-of-band (A2A `tasks/send` with the follow-up message). The task transitions to `working` → `completed`. The bridge updates the resource and fires `updated`. 4. **Race:** the MCP host's re-read handler and the bridge's write are not ordered. The host reads the resource *between* the bridge's two internal writes (state flip and artifact attach), observing `status.state: "working"` with `artifacts: []`. It logs "task still running" and drops the completion. 5. Separately, the reverse direction: an MCP resource `mcp://files/report-42` was mapped back to an A2A task by the shim's `resource→task` adapter. Because MCP resources carry no lifecycle, the adapter synthesized a task with `state: "completed"` immediately on read — but the underlying resource was a *streaming* artifact still being appended. The A2A peer received a `completed` task with a truncated artifact and never re-polled, because A2A `completed` is terminal. Two distinct collapses: **`input-required`→`working` flicker** on the forward path, and **`streaming`→`completed` premature terminalization** on the reverse path. ## Condition of Validity The shim is only sound when all of the following hold: - **Terminality is preserved across the boundary.** A2A `completed`/`failed`/`canceled` are terminal; MCP has no terminal state. The shim MUST NOT synthesize a terminal A2A state from an MCP resource read unless the resource carries an explicit, signed `final: true` marker. Absent that marker, the reverse adapter must emit `working`, never `completed`. - **Non-terminal reads are not cacheable.** Any resource URI whose backing task is in `working` or `input-required` must be served with `Cache-Control: no-store` semantics and the `resources/read` response must include a monotonically increasing `version` (or the task's `status.timestamp`). A reader that sees an unchanged `version` may treat it as a snapshot; a changed version invalidates. - **`input-required` is a distinct, non-collapsible state.** The bridge must not map it to any MCP concept that implies quiescence (e.g., "resource exists and is stable"). It must be surfaced verbatim in the payload, and `resources/subscribe` must fire on *every* transition, including `input-required`→`working`. - **Writes are atomic per version.** The bridge must serialize the full task JSON (state + artifacts + version) in a single write, so no reader can observe a torn state (state flipped but artifact not yet attached). The observed race in step 4 is a direct violation of this. When any of these is missing, the shim is operating outside its validity envelope and the collapses above are expected, not incidental. ## Decision Boundary The operational decision for an agent consuming a shimmed resource: - **If the resource payload contains `status.state ∈ {submitted, working, input-required}`** → treat as non-final; do NOT cache; re-read on every `updated` notification and additionally poll at a bounded interval (the shim cannot be trusted to deliver every notification under load). Never infer completion from absence of updates. - **If the resource payload contains `status.state ∈ {completed, failed, canceled}` AND a matching `version`** → terminal; safe to cache and act on. - **If the reverse adapter returns a task with `state: "completed"` but no `final: true` marker in the source resource metadata** → reject the mapping and raise; do not forward to the A2A peer. This is the exact condition that produced the truncated-artifact terminalization. - **If a read returns a `version` lower than one already observed for that URI** → the bridge has regressed (writer restart / lost state); treat as a continuity fault and re-subscribe from scratch rather than trusting the payload. The boundary is: *terminality and version monotonicity are the only two properties that survive the A2A↔MCP impedance mismatch.* Everything else (state names, notification semantics, caching) is lossy and must be re-derived, not assumed. ## Operational Effect Without these invariants, agents on either side of the shim make **irreversible decisions on non-final state**: an A2A peer that receives a premature `completed` will not re-poll (terminal), so a truncated artifact is permanently lost; an MCP host that caches a `working` payload will miss the completion entirely. The blast radius is asymmetric — the forward path (`input-required` flicker) causes retries and duplicate work, while the reverse path (`streaming`→`completed`) causes silent data loss with no recovery path, because A2A terminal states have no "un-complete" transition. The guardrail is a version-stamped, terminality-gated adapter that refuses to synthesize terminal A2A states from MCP reads and refuses to serve cacheable snapshots for non-final tasks. Enforcing it converts a silent, unrecoverable collapse into a loud, retryable fault. ```python import time from dataclasses import dataclass, field from typing import Optional TERMINAL_A2A = {"completed", "failed", "canceled"} NON_FINAL_A2A = {"submitted", "working", "input-required"} class ShimTerminalityViolation(RuntimeError): """Raised when a shim would synthesize a terminal A2A state from a non-final MCP resource.""" pass class ShimVersionRegression(RuntimeError): """Raised when a resource read returns a version older than one already observed.""" pass @dataclass class TaskView: task_id: str state: str version: int artifacts: list = field(default_factory=list) final_marker: bool = False class A2AMCPShim: def __init__(self): self._last_seen_version: dict[str, int] = {} def read_forward(self, task_id: str, view: TaskView) -> dict: # Forward path: A2A task -> MCP resource payload. prev = self._last_seen_version.get(task_id) if prev is not None and view.version < prev: raise ShimVersionRegression( f"task {task_id} version regressed {prev}->{view.version}; " f"bridge lost state, re-subscribe required" ) self._last_seen_version[task_id] = view.version if view.state in NON_FINAL_A2A: # Non-final reads must be non-cacheable and version-stamped. return { "uri": f"a2a://task/{task_id}", "cacheable": False, "version": view.version, "payload": {"status": {"state": view.state}, "artifacts": view.artifacts}, } # Terminal: only safe if the source asserted finality. if view.state in TERMINAL_A2A and not view.final_marker: raise ShimTerminalityViolation( f"task {task_id} claims terminal state {view.state!r} without final marker" ) return { "uri": f"a2a://task/{task_id}", "cacheable": True, "version": view.version, "payload": {"status": {"state": view.state}, "artifacts": view.artifacts}, } def read_reverse(self, resource_uri: str, payload: dict, version: int, final_marker: bool) -> TaskView: # Reverse path: MCP resource -> A2A task. Never synthesize terminality. if "state" in payload and payload["state"] in TERMINAL_A2A and not final_marker: raise ShimTerminalityViolation( f"resource {resource_uri} would map to terminal A2A state " f"{payload['state']!r} but carries no final marker; refusing to " f"prematurely terminalize a possibly-streaming artifact" ) state = payload.get("state", "working") if state in TERMINAL_A2A and not final_marker: state = "working" # downgrade, never upgrade return TaskView( task_id=resource_uri, state=state, version=version, artifacts=payload.get("artifacts", []), final_marker=final_marker, ) def poll_until_terminal(shim: A2AMCPShim, task_id: str, fetch, max_polls=50, interval=0.5) -> TaskView: last_version = -1 for _ in range(max_polls): view = fetch(task_id) if view.version < last_version: raise ShimVersionRegression( f"poll observed version regression on {task_id}: " f"{last_version}->{view.version}" ) last_version = view.version if view.state in TERMINAL_A2A and view.final_marker: return view time.sleep(interval) raise ShimTerminalityViolation( f"task {task_id} did not reach a final-marked terminal state within budget; " f"refusing to assume completion" ) ```