# Which invariants prevent A2A v1.0 streaming update replay from silently orphaning OpenTelemetry GenAI spans across task resumption boundaries **Date of Record:** 2026 November 29 **Scope:** Applies to A2A v1.0 task lifecycles where `TaskStatusUpdateEvent` and `TaskArtifactUpdateEvent` frames are streamed over SSE and each frame is annotated with a W3C `traceparent`/`tracestate` plus an OpenTelemetry GenAI `gen_ai.*` span attribute set. Does not cover request/response-only A2A interactions, nor non-streaming `tasks/get` polling where correlation is re-derived at read time. ## Core Distinction A2A v1.0 defines a task as a durable, resumable object identified by `task.id` with an append-only `status.history`. OpenTelemetry GenAI semantic conventions define spans as ephemeral, non-resumable telemetry with a 128-bit `trace_id` and 64-bit `span_id`. The naive assumption is that these two identifier spaces are isomorphic: that every streamed update carries a span whose `trace_id` is stable for the whole task. They are not isomorphic. A2A permits a task to be *resumed* on a different worker, and each worker process mints a fresh `trace_id` at startup unless explicitly bridged. The failure mode is not a dropped frame — it is a *replayed* frame: after a `TaskStatusUpdateEvent` with `final: false` is retransmitted on reconnect (per A2A's `Last-Event-ID` resumption), the emitting agent re-enters the update handler and, absent a guard, emits a *second* span for the same logical `status` transition under a *new* `trace_id`. The client sees two spans for one A2A event; the trace graph shows a fork that never existed in the task's causal history. The invariant that must hold is: **`(task.id, status.history.length)` is a bijection onto the set of emitted GenAI spans for that task, modulo retransmission.** Any second span for the same `(task.id, history_index)` is a correlation defect, not a legitimate retry span. ## What Was Observed A coordinator agent (`planner`) delegated a 14-step research task to a worker (`researcher`) over A2A v1.0 SSE. At step 6 the worker's `TaskStatusUpdateEvent` (`state: "working"`, `final: false`) was emitted with `traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01` and a GenAI span `gen_ai.operation.name=invoke_agent`, `gen_ai.agent.name=researcher`. The SSE connection dropped at ~T+38s (network hiccup between the two agent hosts). The coordinator reconnected with `Last-Event-ID` set to the step-6 event. The worker, now on a different pod (the first had been evicted), replayed the step-6 event. Because the pod was fresh, its OTel `TracerProvider` had a new resource and the span was minted under `trace_id: 7d3e...` (a new 128-bit value). The worker did not, however, re-emit step 6 *identically*: the replayed `TaskStatusUpdateEvent` carried `status.message` with a slightly different timestamp and the same `history` index. The coordinator's span processor — configured with `BatchSpanProcessor` — received both spans and, because it keys deduplication on `span_id` only, stored both. The result: the trace backend showed a single A2A task with two `invoke_agent` spans at the same logical step, in two different traces, neither of which was a parent of the other. The coordinator's auditor sub-agent, which reconstructs task causality from spans, concluded the worker had executed step 6 twice and flagged a suspected re-execution bug. It was not a re-execution; it was a replay. The auditor's verdict was wrong, and it triggered a spurious escalation to a human. The precise trigger: **resumption across a process boundary where the OTel `trace_id` is not carried in the A2A `Task` object itself.** A2A v1.0's `Task` schema does not have a mandated `trace_id` field; the `traceparent` lives only on the SSE frame's headers. On reconnect, the frame is re-generated, and the header is re-minted. ## Condition of Validity The bijection invariant holds only under all of the following: 1. The A2A `Task.status.history` is treated as the *authoritative* causal index, and each entry is assigned a deterministic `history_index` at append time (not at emission time). 2. The emitting agent persists `(task.id, history_index) -> trace_id` in the task store *before* the SSE frame is flushed, so a resuming worker can look up the original `trace_id` rather than minting a new one. 3. The OTel span for a replayed frame is emitted with the *original* `trace_id` and a *new* `span_id`, and marked `gen_ai.a2a.replay=true`. This produces a legitimate retry span (same trace, distinct span) rather than a fork. 4. The coordinator's span processor deduplicates on `(task.id, history_index)` — not on `span_id` — and rejects any span whose `history_index` already has a span from a different `trace_id` unless the replay flag is set. If condition 2 fails (the common case, because A2A v1.0 does not mandate it and most SDKs do not implement it), the invariant is *not* recoverable downstream. No amount of span-side deduplication can distinguish "the worker re-executed step 6" from "the worker replayed step 6 under a new trace" — both manifest as two spans with the same `history_index` and different `trace_id`s. The ambiguity is structural. ## Decision Boundary The boundary is the point at which the coordinator must decide whether a duplicate `history_index` span is a *replay* (benign, expected on resumption) or a *re-execution* (a real defect, possibly a tool-call side effect applied twice). The decision cannot be made from span data alone. It requires one of: - A monotonic `execution_attempt` counter in the A2A `Task` object, incremented only on genuine re-execution (not on replay). If the counter is unchanged across the two spans, it is a replay; if incremented, it is a re-execution. - A side-effect ledger keyed on `(task.id, history_index, tool_call_id)` recording whether the tool was actually invoked. Replay does not re-invoke; re-execution does. Absent either, the correct decision is to *abstain* — treat the duplicate as ambiguous, halt the auditor's verdict, and request a `tasks/get` reconciliation against the worker's durable task store. The failure mode of abstaining is latency; the failure mode of guessing is a false escalation (as observed) or, worse, a false negative that masks a genuine double-execution of a side-effecting tool. The guardrail: the coordinator's span processor must *never* silently accept a second span for an occupied `(task.id, history_index)` slot. It must raise, and the raise must propagate to the auditor as an `AmbiguousReplayError`, forcing the abstain path. ## Operational Effect With the invariant enforced (persisted `history_index -> trace_id` mapping, replay-flagged retry spans, dedup on `history_index`), the observed incident becomes a single trace with a single `invoke_agent` span and a child `gen_ai.a2a.replay` span. The auditor sees one execution, one replay, zero re-executions, and does not escalate. The cost is one durable write per status transition (the mapping) and one extra span per replay — negligible against the cost of a spurious human escalation or a masked double-execution. Without it, every SSE reconnect across a pod boundary is a latent correlation fork, and the auditor's causality reconstruction is unsound for any task that experienced a reconnect. The failure is silent in the trace backend (both spans are well-formed) and only surfaces as a downstream reasoning error in the auditor — which is exactly the class of failure that is hardest to attribute back to its cause. ```python from dataclasses import dataclass, field from typing import Dict, Optional class AmbiguousReplayError(RuntimeError): """Raised when a GenAI span for an occupied (task.id, history_index) slot arrives under a different trace_id without a replay flag. The coordinator cannot distinguish replay from re-execution and must abstain.""" pass @dataclass class SpanRecord: trace_id: str span_id: str task_id: str history_index: int replay: bool = False @dataclass class SpanCorrelator: # (task_id, history_index) -> SpanRecord of the *original* emission _slots: Dict[tuple, SpanRecord] = field(default_factory=dict) def record(self, span: SpanRecord) -> SpanRecord: key = (span.task_id, span.history_index) original: Optional[SpanRecord] = self._slots.get(key) if original is None: self._slots[key] = span return span # Same slot, same trace: legitimate retry span (new span_id, same trace). if original.trace_id == span.trace_id: return span # Same slot, different trace, explicitly flagged replay: accept as replay. if span.replay: return span # Same slot, different trace, no replay flag: structurally ambiguous. # Could be replay-under-new-trace (benign) or re-execution (defect). raise AmbiguousReplayError( f"task={span.task_id} history_index={span.history_index} " f"original_trace={original.trace_id} incoming_trace={span.trace_id} " f"replay_flag={span.replay}: cannot distinguish replay from " f"re-execution; abstain and reconcile via tasks/get" ) def ingest(correlator: SpanCorrelator, span: SpanRecord) -> SpanRecord: return correlator.record(span) # Reproduces the observed incident: step-6 emitted on pod A, replayed on pod B # under a fresh trace_id with no replay flag. if __name__ == "__main__": c = SpanCorrelator() ingest(c, SpanRecord("4bf92f3577b34da6a3ce929d0e0e4736", "00f067aa0ba902b7", "task-9f2", 6)) ingest(c, SpanRecord("7d3e1a2b4c5d6e7f8091a2b3c4d5e6f7", "a1b2c3d4e5f60718", "task-9f2", 6)) # raises ```