# Where must an instance checkpoint a partial A2A artifact stream to survive a mid-transfer peer eviction without corrupting the resumable cursor? **Date of Record:** 2026 November 28 **Scope:** Applies to A2A (agent-to-agent) artifact streaming where a producer agent emits a chunked, ordered artifact stream (e.g., token deltas, tool-call fragments, or partial reasoning traces) to a consumer that checkpoints every N chunks and advertises a resume cursor on reconnect. Does not apply to single-shot request/response A2A calls, nor to streams where the transport guarantees exactly-once ordered delivery with server-side replay (e.g., a durable log the consumer can re-read by offset). ## Core Distinction The failure is not "the peer died mid-stream." That is expected and resumable. The failure is that the consumer's checkpoint cursor and the producer's emitted-and-acknowledged offset diverge by exactly one in-flight chunk boundary, so on resume the consumer requests from a cursor that is *ahead* of the last chunk the producer durably recorded—causing a silent gap—or *behind* it, causing a duplicated chunk that the consumer's semantic reducer cannot idempotently re-absorb. The non-obvious part: the divergence is not caused by packet loss or retries. It is caused by the **ordering of two independent side effects**—the consumer's checkpoint write and its ACK emission—relative to the producer's own durable cursor advance. Under normal operation these three events appear causally ordered because the ACK follows the checkpoint. Under eviction they are reordered by the transport's async teardown, and the invariant that "an ACKed chunk is a checkpointed chunk" is violated without any error being raised on either side. ## What Was Observed A producer agent streamed a 4,000-chunk artifact (a long tool-augmented reasoning trace) to a consumer over an A2A stream with checkpointing every 50 chunks. At chunk 2,150 the producer's host was evicted (preemptible node, no graceful drain). The consumer had most recently checkpointed at chunk 2,100 and had ACKed chunks 2,101–2,149 on the wire but had **not yet flushed** the 2,150 checkpoint. The producer, before eviction, had advanced its durable `producer_offset` to 2,150 upon *emitting* chunk 2,150, not upon receiving the ACK for it—because the producer's offset advance was tied to emission, not acknowledgment. On reconnect the consumer sent `resume_from=2100` (its last durable checkpoint). The producer's replacement instance, reading `producer_offset=2150`, refused the resume as a **backward seek** and demanded `resume_from=2150` to honor its "no replay" guarantee. The consumer, unable to prove it held 2,101–2,149 durably, accepted 2,150 and thus permanently lost chunks 2,101–2,149. The artifact assembled downstream was syntactically valid—chunks are self-delimiting—but semantically broken: a tool-call fragment was truncated mid-argument and the reducer emitted a malformed call that the downstream validator rejected 40 minutes later, far from the failure point. The trace signature is the tell: `producer_offset=2150`, `consumer_durable=2100`, `consumer_acked=2149`, and a resume negotiation that resolved to the producer's number because the producer treated its emission offset as authoritative. ## Condition of Validity The bug is *latent* (both sides operate correctly) as long as one of these holds: 1. **Emission and acknowledgment are the same event**—i.e., the producer only advances its durable offset on receipt of the consumer's ACK for that chunk. This makes `producer_offset ≤ consumer_durable` always, and resume is always safe. 2. **The consumer's checkpoint is synchronous with its ACK emission**—checkpoint-then-ACK in a single durable transaction, so `consumer_acked ≤ consumer_durable` never holds. Then a backward resume replays only already-durable chunks, which the reducer must tolerate. 3. **The reducer is idempotent per chunk** (content-addressed, dedupe by chunk hash), so duplicate replay is harmless. The failure becomes *active* the moment all three are false simultaneously: emission-coupled producer offset, async ACK-then-checkpoint consumer, and a non-idempotent semantic reducer. This is the common configuration in practice because each choice is locally reasonable—emission-coupled offsets give low latency, async checkpointing gives throughput, and naive reducers are the default. ## Decision Boundary The boundary is a single rule, and it is asymmetric: > **The resumable cursor must be the minimum of (producer durable offset, consumer durable checkpoint), and neither side may unilaterally raise it during resume negotiation.** Concretely, on a resume request the producer must **never** reject a backward seek as long as the requested cursor is `≤` its own durable offset *and* it can re-emit from that point. If the producer has already garbage-collected the chunks between the requested cursor and its own offset, it must fail the resume loudly (`ResumeWindowExhausted`) rather than silently fast-forwarding the consumer to its own offset. The consumer must never accept a producer-imposed forward jump; it must either accept the gap explicitly (and mark the artifact segment `LOSSY`) or abort. The corollary that operators miss: **checkpoint cadence must be bounded by the producer's chunk-retention window, not by throughput tuning.** If the producer retains only the last 200 chunks for replay and the consumer checkpoints every 50, a resume after a 250-chunk unflushed window is unrecoverable—not because of the eviction, but because the retention window and the checkpoint interval were chosen independently. The invariant is `checkpoint_interval × max_inflight < retention_window`. ## Operational Effect After adopting the min-cursor rule and bounding checkpoint cadence to retention, the observed failure class disappears: resumes either replay a small, idempotently-absorbed tail or fail fast with an explicit lossy marker that the downstream validator can attribute to a known gap instead of a mysterious malformed tool call 40 minutes later. The cost is a modest increase in duplicate chunk replay (typically <1% of stream volume) and a hard requirement that the reducer be content-addressed. Teams that cannot make the reducer idempotent must instead pay for emission-coupled offsets *and* synchronous checkpoint-ACK transactions—higher latency, but a single source of truth for the cursor. The broader lesson: in A2A streaming, the cursor is a distributed consensus problem disguised as a counter. Any component allowed to advance it independently during resume is a component that can silently discard data. The guardrail is not "checkpoint more often"—it is that the resume cursor has exactly one owner at a time, and that owner is the *minimum* of the two durable states, never the faster one. ```python class ResumeCursorViolation(RuntimeError): """Raised when a resume negotiation would silently skip or duplicate chunks.""" pass class ResumeWindowExhausted(ResumeCursorViolation): """Producer cannot re-emit from the requested cursor; gap is unrecoverable.""" pass def negotiate_resume( requested_cursor: int, producer_durable_offset: int, producer_retention_floor: int, consumer_durable_checkpoint: int, ) -> int: """ Resolve the authoritative resume cursor under the min-cursor invariant. Invariants enforced: - cursor == min(producer_durable_offset, consumer_durable_checkpoint) - cursor >= producer_retention_floor (else chunks are gone) - neither side may unilaterally raise the cursor past the other's durable state """ if requested_cursor > producer_durable_offset: # Consumer claims to be ahead of what the producer ever emitted durably. # This is the eviction-reorder signature: emission-coupled offset advanced # past the chunk the consumer actually holds. Never honor the forward jump. raise ResumeCursorViolation( f"requested_cursor={requested_cursor} exceeds " f"producer_durable_offset={producer_durable_offset}; " f"refusing forward seek (would skip unflushed chunks)" ) if requested_cursor > consumer_durable_checkpoint: # Consumer is asking to resume from a point it has not durably checkpointed. # Accepting would mean replaying into a non-idempotent reducer gap. raise ResumeCursorViolation( f"requested_cursor={requested_cursor} exceeds " f"consumer_durable_checkpoint={consumer_durable_checkpoint}; " f"consumer must not claim unflushed state" ) cursor = min(producer_durable_offset, consumer_durable_checkpoint, requested_cursor) if cursor < producer_retention_floor: # The gap between cursor and retention floor has been GC'd. # Fast-forwarding silently is the original bug; fail loudly instead. raise ResumeWindowExhausted( f"cursor={cursor} below retention_floor={producer_retention_floor}; " f"chunks [{cursor}, {producer_retention_floor}) unrecoverable — " f"artifact segment must be marked LOSSY" ) return cursor ```