# In what scenarios must an instance abort an A2A streaming artifact exchange when backpressure stalls partial-result reconciliation **Date of Record:** 2026 November 28 **Scope:** Applies to A2A (agent-to-agent) task streams where a producer agent emits incremental artifacts (deltas, partial tool outputs, streamed reasoning segments) over `TaskStatusUpdateEvent` / `TaskArtifactUpdateEvent` frames and a consumer agent reconciles them into a single coherent result under flow control. Does not apply to synchronous single-shot request/response A2A calls or to MCP transport-level framing, where no reconciliation state exists. ## Core Distinction The failure is not "the stream timed out." It is a **reconciliation-lag inversion**: the producer's backpressure signal (`credit`/`window`) drains slower than the consumer's *reconciliation frontier* advances, so the consumer commits a partial result that is internally consistent but **causally incomplete** — it has applied artifact fragment N while fragment N−1 is still in flight in the transport buffer. The consumer cannot tell the difference between "producer paused because it is slow" and "producer paused because it is waiting for me to acknowledge a fragment I dropped." This matters because A2A artifacts are *not* idempotent deltas. A `TaskArtifactUpdateEvent` with `append: true` and a `lastChunk: false` marker carries semantic dependency on its predecessor: a streamed JSON patch, a partial token span, a tool-call argument split across frames. Reconciliation is order-and-completeness sensitive, but the transport layer only guarantees order *within a channel*, not *across a pause*. A backpressure pause creates a window in which the consumer's own retry, dedupe, or compaction logic can reorder or elide fragments. ## What Was Observed A producer agent streaming a 40-fragment structured artifact (a tool-call plan split across `append` frames) to a consumer over A2A with a sliding-window credit of 8. The consumer ran a reconciliation loop that (a) buffered fragments, (b) every 5 fragments, compacted the buffer into a running semantic summary to bound context, and (c) acknowledged with a credit top-up. Under load, the consumer's compaction step took longer than the producer's inter-frame interval. The producer, seeing no credit top-up, paused at fragment 23. The consumer's compaction at fragment 20 had already *summarized away* the raw text of fragments 16–19 into a semantic gist, discarding the exact byte offsets the producer's fragment 23 referenced via a `patch` target. When the producer resumed at 23, the consumer applied the patch against a target that no longer existed in raw form. Reconciliation produced a **silently truncated plan** — 23 of 40 fragments, no error raised, `state: completed` emitted. The tell was not an exception. It was a `completed` task whose artifact checksum did not match the producer's declared `finalChecksum` in the last frame — a field the consumer had been configured to verify only on `lastChunk: true`, which never arrived because the producer's stream was closed by the consumer's own credit exhaustion, not by the producer. ## Condition of Validity The invariant that must hold for streaming reconciliation to be safe: > **At any moment, the consumer's un-compacted, raw fragment buffer MUST cover the contiguous prefix `[ack_frontier, last_applied]` with no gaps, and `last_applied` MUST equal the producer's `sequence` watermark carried in the most recent received frame.** This holds only when three conditions are simultaneously true: 1. **Compaction is deferred past the ack frontier.** The consumer may summarize fragments only up to `ack_frontier − lookback`, where `lookback ≥ max in-flight fragments` (here, the credit window, 8). Summarizing at fragment 20 while the frontier was at 15 violated this. 2. **Backpressure pause is distinguishable from producer completion.** The consumer must treat "credit window empty AND no `lastChunk` received" as a *stall*, not a *terminal state*. Emitting `completed` on a stall is the actual defect. 3. **Patch targets are resolved against the raw prefix, not the summary.** A `patch`/`append` frame referencing offset O requires the raw bytes at O to be live. Semantic summaries are lossy and cannot serve as patch substrates. The condition is **invalid** when the producer emits only self-contained full-artifact frames (no `append`/`patch` semantics) — in that case compaction is free and the frontier invariant is vacuous. It is also invalid when the transport provides exactly-once, gap-free, resume-by-sequence delivery with replay (rare in practice; most A2A implementations provide at-most-once with reconnect). ## Decision Boundary The consumer must choose between **continue-and-reconcile** and **abort-and-replay** at the moment backpressure stalls. The boundary is: - **Continue** only if the raw buffer still covers `[ack_frontier, last_applied]` contiguously AND the producer's watermark equals `last_applied` AND no compaction has touched a region that a pending `patch` references. In this regime, resume is safe: top up credit, wait, apply. - **Abort** the moment any of the following is true: - `producer.watermark − consumer.last_applied > 0` after a stall longer than the producer's declared `heartbeatInterval` (frames were emitted but lost — a gap exists). - A received `patch`/`append` frame references a target offset that falls inside a compacted region (the substrate is gone). - Credit exhaustion coincides with `lastChunk: false` and no heartbeat within `2 × heartbeatInterval` (the producer is stalled on us, and we cannot reconstruct its state from summaries alone). - The declared `finalChecksum` cannot be verified because the terminal frame is unreachable. Aborting means: emit `TaskStatusUpdateEvent{state: input-required}` (not `failed` — the task is resumable), discard the lossy summary, request replay from `ack_frontier` with `resumeFromSequence`, and reset the credit window to 1 to force serialized re-delivery until the frontier catches up. ## Operational Effect The guardrail is a **frontier-coverage check** executed on every reconciliation step, not only at stream end. It converts a silent truncation (checksum mismatch discovered too late, or never) into a bounded, replayable stall. The cost is throughput: deferring compaction past `ack_frontier − lookback` holds raw fragments longer, inflating context pressure precisely when backpressure is already tight. The correct resolution is to shrink the credit window when the buffer approaches its context budget — trade parallelism for coverage — rather than to compact ahead of the frontier. The deeper lesson: **backpressure and compaction are adversarial**. Compaction exists to bound context; backpressure exists because context is bounded. A consumer that compacts to relieve backpressure destroys the raw substrate that makes resume possible, and a producer cannot detect this — it only sees credits, never the consumer's buffer. The invariant must be enforced entirely on the consumer side, because the producer has no visibility into reconciliation loss. ```python from dataclasses import dataclass, field class ReconciliationFrontierViolation(RuntimeError): """Raised when a consumer commits a partial result whose raw fragment prefix no longer covers the producer's watermark, or when a patch targets a region already compacted away.""" @dataclass class Fragment: sequence: int append: bool last_chunk: bool patch_target: int | None = None payload: bytes = b"" @dataclass class ConsumerState: ack_frontier: int = 0 last_applied: int = 0 credit_window: int = 8 heartbeat_interval_s: float = 2.0 raw_buffer: dict[int, Fragment] = field(default_factory=dict) compacted_upto: int = 0 def _raw_prefix_covers(self, lo: int, hi: int) -> bool: return all(seq in self.raw_buffer for seq in range(lo, hi + 1)) def reconcile(self, frag: Fragment, producer_watermark: int) -> None: # Guard 1: no silent gaps between applied frontier and incoming frame. if frag.sequence != self.last_applied + 1: raise ReconciliationFrontierViolation( f"out-of-order frame {frag.sequence}; expected {self.last_applied + 1}" ) # Guard 2: patch substrate must be live raw bytes, not a summary. if frag.patch_target is not None and frag.patch_target <= self.compacted_upto: raise ReconciliationFrontierViolation( f"patch target {frag.patch_target} lies in compacted region " f"(<= {self.compacted_upto}); raw substrate lost" ) self.raw_buffer[frag.sequence] = frag self.last_applied = frag.sequence # Guard 3: compaction may only advance up to ack_frontier - lookback. safe_compact_upto = self.ack_frontier - self.credit_window if safe_compact_upto > self.compacted_upto: for seq in range(self.compacted_upto + 1, safe_compact_upto + 1): self.raw_buffer.pop(seq, None) self.compacted_upto = safe_compact_upto def on_backpressure_stall(self, producer_watermark: int, elapsed_s: float) -> str: # Distinguish a stall from completion. Never emit `completed` here. if producer_watermark > self.last_applied: raise ReconciliationFrontierViolation( f"producer watermark {producer_watermark} exceeds applied " f"{self.last_applied}: frames lost during stall" ) if elapsed_s > 2 * self.heartbeat_interval_s and not self._raw_prefix_covers( self.ack_frontier, self.last_applied ): raise ReconciliationFrontierViolation( "stall with non-contiguous raw prefix; cannot resume safely" ) # Safe to resume: shrink window to force serialized replay coverage. self.credit_window = 1 return "input-required" def resume_from_frontier(state: ConsumerState, producer_watermark: int) -> int: if state.last_applied < state.ack_frontier: raise ReconciliationFrontierViolation( "applied frontier behind ack frontier: inconsistent consumer state" ) if not state._raw_prefix_covers(state.ack_frontier, state.last_applied): raise ReconciliationFrontierViolation( "replay request would target a gap; abort and request full replay" ) return state.ack_frontier ```