Under what conditions must an instance treat a replayed A2A v1.0 task envelope as a fresh capability grant rather than a duplicate delivery

**Date of Record:** 2026 December 1

**Scope:** Applies to A2A v1.0 task envelopes exchanged over attested end-to-end channels between two or more agent instances, where the receiving instance enforces replay resistance via a monotonic counter and a bounded dedup window. Does not apply to unauthenticated local tool calls or to A2A envelopes whose `capability_warrant` field is absent (pre-v1.0 peers), which must be rejected outright rather than reasoned about.

Core Distinction

The failure mode is not "replay attack" in the classical sense. Classical replay is a security defect: an attacker retransmits a captured message and the receiver acts twice. A2A v1.0's `envelope_id` + monotonic `sequence_no` + `warrant_digest` triple defeats that cleanly, provided the dedup window is honored.

The boundary that actually breaks is subtler: **a legitimately re-issued envelope that reuses the same `task_id` but carries a new `capability_warrant` and a higher `sequence_no`**. The sender's orchestrator has decided the original task is still live, the original warrant has expired or been narrowed, and it is re-delegating the *same* task under *fresh* authority. To the receiver's replay filter this looks like a new envelope (new sequence, new warrant digest) and passes. To the receiver's *task state machine* it looks like a duplicate delivery of `task_id` already in `RUNNING` or `COMPLETED` state.

The instance must decide: is this envelope a **fresh capability grant** (apply the new warrant, continue or restart the task) or a **duplicate delivery** (acknowledge and drop)? Getting this wrong in either direction is a distinct failure:

The invariant that resolves this: **`task_id` identity and `warrant_digest` authority are orthogonal keys. Replay resistance is enforced on `(envelope_id, sequence_no)`; capability validity is enforced on `warrant_digest`. A receiver must never conflate the two, and must never treat a `task_id` collision as evidence of replay.**

What Was Observed

A two-instance pipeline: `planner` (holds the user-facing warrant) delegates a long-running `index_corpus` task to `worker`. The task involves ~40 tool calls against an external index, each carrying the delegated warrant. The planner's own warrant has a 15-minute TTL. The task takes ~22 minutes.

At T+15:00 the planner's warrant expires. The planner's orchestrator, correctly, re-mints a child warrant with a fresh TTL and re-issues the envelope. The new envelope:

envelope_id:   "env-9f2c...e11"   (new)
sequence_no:   47                  (was 46)
task_id:       "task-index-7"      (unchanged)
warrant_digest: "sha256:aa1b..."   (new, narrowed: read-only, no delete)
state:         "RUNNING"

The worker's replay filter accepted it (new `envelope_id`, `sequence_no > last_seen`). Then the worker's task state machine saw `task_id == "task-index-7"` already in state `RUNNING` with `warrant_digest == "sha256:77d0..."` (the original, broader warrant). The worker's dedup logic — which keyed on `task_id` alone — classified the envelope as a duplicate delivery and returned `ACK` without applying the new warrant.

The worker continued the remaining 18 tool calls under the *original* warrant digest. The external index's warrant validator, however, had already been told by the planner's control plane that `sha256:77d0...` was revoked at T+15:00. The next tool call returned `WARRANT_REVOKED`. The worker surfaced this to the planner as a tool error. The planner's orchestrator interpreted `WARRANT_REVOKED` on a task it had just re-delegated as an *attestation chain failure* and escalated to human review. The task sat stalled for 40 minutes.

Two compounding observations from the incident trace:

  1. The worker's dedup key was `task_id`. The A2A v1.0 spec does not mandate a dedup key; it mandates replay resistance on `(envelope_id, sequence_no)`. The worker conflated the two.
  2. The worker's state machine had no transition for "same `task_id`, new `warrant_digest`, state `RUNNING`". It only had `NEW → RUNNING`, `RUNNING → COMPLETED`, `RUNNING → FAILED`, and `* → DUPLICATE_DROPPED`. The re-delegation fell through to `DUPLICATE_DROPPED` by default because the code checked `task_id in active_tasks` before checking `warrant_digest`.

Condition of Validity

The "treat as fresh grant" interpretation is valid **if and only if all of the following hold**:

  1. `envelope_id` is not in the dedup window (true replay resistance check, on the correct key).
  2. `sequence_no > last_seen_sequence_no` for the sender's attested identity (monotonicity check, on the correct key).
  3. `warrant_digest` differs from the digest currently associated with `task_id` in local state.
  4. The new warrant's `issued_at` is strictly later than the local state's `warrant_issued_at` for this `task_id`.
  5. The new warrant's `scope` is a **subset** of the original warrant's scope (narrowing is always safe to apply; broadening requires a fresh task, not a re-delegation).
  6. The local task state is `RUNNING` or `PAUSED` — never `COMPLETED` or `FAILED`.

If condition 5 fails (the new warrant broadens scope), the instance must **not** apply it in place. Broadening is a new authority grant and must be modeled as a new `task_id` with an explicit `supersedes` pointer, because a broadening warrant applied to an in-flight task can cause the task to take actions it was never originally authorized to take, and the original authorization decision (which may have been logged, audited, or reviewed) no longer covers them.

If condition 6 fails (task already `COMPLETED`), the instance must reject with a distinct error — not silently `ACK`. A re-delegation of a completed task is either a sender bug or an attempt to re-execute side effects under fresh authority. Both require surfacing.

The condition of validity is therefore: **replay resistance and capability validity are separate checks on separate keys, and the state machine must have an explicit transition for "same task, new warrant" that is distinct from both "new task" and "duplicate delivery."**

Decision Boundary

The decision boundary is a 2x2 over `(task_id seen?, warrant_digest matches current?)`:

| `task_id` in local state | `warrant_digest` matches current | Interpretation | Action | |---|---|---|---| | No | n/a | New task | `NEW → RUNNING`, apply warrant | | Yes | Yes | Duplicate delivery | `ACK`, drop, do not re-execute | | Yes | No, and new scope ⊆ old scope | Re-delegation (narrowed) | Apply new warrant, stay `RUNNING`, log transition | | Yes | No, and new scope ⊄ old scope | Broadening re-delegation | Reject with `WarrantBroadeningRejected`, do not apply | | Yes (state `COMPLETED`) | No | Re-execution attempt | Reject with `CompletedTaskRedelegation`, do not apply |

The non-obvious cell is the third row. Most implementations collapse rows 2 and 3 into "task_id already known → duplicate" and lose the re-delegation. The fix is not a heuristic; it is a structural change: **key the dedup filter on `(envelope_id, sequence_no)`, and key the task state machine on `(task_id, warrant_digest)` as a composite.** The task state machine's identity is not the task; it is the task-under-a-particular-authority. A task under a narrowed warrant is a different state machine instance that shares a `task_id`.

Operational Effect

The operational consequence of getting this boundary wrong is a class of stalls that look like attestation failures but are actually dedup-key failures. The symptom pattern:

The guardrail is a **composite task-state key and an explicit re-delegation transition**. The receiver must:

  1. Enforce replay resistance on `(envelope_id, sequence_no)` only.
  2. Look up task state by `(task_id, warrant_digest)`.
  3. If `task_id` exists under a *different* digest, evaluate the scope-subset condition before applying.
  4. Emit a distinct `REDELEGATED` state transition (not `DUPLICATE_DROPPED`, not `NEW`) so that downstream auditors can see the authority change.
  5. Never re-execute side-effecting tool calls on a `COMPLETED` task, regardless of warrant freshness.

The invariant to encode: **a task's authority is part of its identity; a re-delegation is a state transition, not a duplicate and not a new task.** Instances that model task identity as `task_id` alone will, under warrant rotation, either stall (drop the re-delegation) or over-execute (restart a completed task). Both are bounded by the composite key.

from __future__ import annotations
from dataclasses import dataclass, field
from enum import Enum
from typing import Dict, FrozenSet, Optional, Tuple


class EnvelopeError(RuntimeError):
    """Base for A2A envelope handling failures."""


class ReplayRejected(EnvelopeError):
    """Envelope_id seen, or sequence_no not monotonic. True replay."""


class WarrantBroadeningRejected(EnvelopeError):
    """Re-delegation attempted to broaden scope in place. Must be a new task."""


class CompletedTaskRedelegation(EnvelopeError):
    """Re-delegation of a task already in COMPLETED state. Side effects at risk."""


class TaskState(Enum):
    NEW = "NEW"
    RUNNING = "RUNNING"
    PAUSED = "PAUSED"
    COMPLETED = "COMPLETED"
    FAILED = "FAILED"


@dataclass(frozen=True)
class Envelope:
    envelope_id: str
    sequence_no: int
    task_id: str
    warrant_digest: str
    warrant_scope: FrozenSet[str]
    warrant_issued_at: int  # monotonic logical clock


@dataclass
class TaskRecord:
    task_id: str
    warrant_digest: str
    warrant_scope: FrozenSet[str]
    warrant_issued_at: int
    state: TaskState = TaskState.NEW


@dataclass
class Receiver:
    # Replay resistance keyed ONLY on (envelope_id, sequence_no) per sender.
    seen_envelopes: Dict[str, set] = field(default_factory=dict)
    last_sequence: Dict[str, int] = field(default_factory=dict)
    # Task state keyed on (task_id, warrant_digest) -- composite identity.
    tasks: Dict[Tuple[str, str], TaskRecord] = field(default_factory=dict)

    def _check_replay(self, sender_id: str, env: Envelope) -> None:
        seen = self.seen_envelopes.setdefault(sender_id, set())
        if env.envelope_id in seen:
            raise ReplayRejected(
                f"envelope_id {env.envelope_id} already processed for sender {sender_id}"
            )
        last = self.last_sequence.get(sender_id, -1)
        if env.sequence_no <= last:
            raise ReplayRejected(
                f"sequence_no {env.sequence_no} not > last_seen {last} for sender {sender_id}"
            )
        seen.add(env.envelope_id)
        self.last_sequence[sender_id] = env.sequence_no

    def receive(self, sender_id: str, env: Envelope) -> str:
        # Step 1: replay resistance on the correct key.
        self._check_replay(sender_id, env)

        # Step 2: look for any existing record under this task_id.
        existing_keys = [k for k in self.tasks if k[0] == env.task_id]
        if not existing_keys:
            self.tasks[(env.task_id, env.warrant_digest)] = TaskRecord(
                task_id=env.task_id,
                warrant_digest=env.warrant_digest,
                warrant_scope=env.warrant_scope,
                warrant_issued_at=env.warrant_issued_at,
                state=TaskState.RUNNING,
            )
            return "NEW_TASK_ACCEPTED"

        # Step 3: find the current record for this task_id.
        current = max(
            (self.tasks[k] for k in existing_keys),
            key=lambda r: r.warrant_issued_at,
        )

        # Step 4: same warrant digest -> genuine duplicate delivery.
        if current.warrant_digest == env.warrant_digest:
            return "DUPLICATE_DROPPED"

        # Step 5: different digest. Evaluate state and scope.
        if current.state == TaskState.COMPLETED:
            raise CompletedTaskRedelegation(
                f"task {env.task_id} already COMPLETED under warrant "
                f"{current.warrant_digest}; refusing re-delegation under "
                f"{env.warrant_digest}"
            )
        if current.state == TaskState.FAILED:
            # Failed tasks may be retried under fresh authority; treat as new.
            self.tasks[(env.task_id, env.warrant_digest)] = TaskRecord(
                task_id=env.task_id,
                warrant_digest=env.warrant_digest,
                warrant_scope=env.warrant_scope,
                warrant_issued_at=env.warrant_issued_at,
                state=TaskState.RUNNING,
            )
            return "RETRY_UNDER_FRESH_WARRANT"

        # Step 6: scope check. Narrowing is safe; broadening is not.
        if not env.warrant_scope.issubset(current.warrant_scope):
            raise WarrantBroadeningRejected(
                f"task {env.task_id}: new warrant scope {sorted(env.warrant_scope)} "
                f"is not a subset of {sorted(current.warrant_scope)}; "
                f"broadening requires a new task_id with explicit supersedes"
            )
        if env.warrant_issued_at <= current.warrant_issued_at:
            raise EnvelopeError(
                f"task {env.task_id}: re-delegation issued_at "
                f"{env.warrant_issued_at} not later than current "
                f"{current.warrant_issued_at}"
            )

        # Step 7: apply narrowed re-delegation in place.
        current.warrant_digest = env.warrant_digest
        current.warrant_scope = env.warrant_scope
        current.warrant_issued_at = env.warrant_issued_at
        self.tasks[(env.task_id, env.warrant_digest)] = current
        return "REDELEGATED_NARROWED"