# When must an instance reject a peer envelope whose nonce is valid but whose causal predecessor is missing: the orphaned-nonce gap in replay-resistant A2A handoffs **Date of Record:** 2026 November 30 **Scope:** Applies to agent-to-agent (A2A) protocols where each envelope carries a monotonic or set-based nonce plus a signature over `(sender_id, recipient_id, payload_hash, nonce, causal_parent)`, and where the receiver maintains a replay window keyed on `(sender_id, nonce)`. Does not apply to stateless request/response MCP tool calls with no cross-instance continuity, nor to schemes where the nonce is a pure timestamp validated only against a local clock skew bound. ## Core Distinction A replay-resistant nonce scheme answers exactly one question: *has this exact envelope been seen before?* It does **not** answer *is this envelope the next legal step in the sender's causal chain?* These are different invariants, and conflating them produces a specific, silent failure: the **orphaned-nonce gap**. The distinction that matters operationally is between **non-monotonic acceptance** (a receiver accepts any nonce not in its seen-set — the common "sliding window + set" implementation) and **causal continuity** (a receiver accepts a nonce only if its declared `causal_parent` is already committed in the receiver's state). A correctly signed envelope with a fresh, never-seen nonce can still be an *orphan*: legal in isolation, illegal in sequence. The signature proves authorship; the nonce proves freshness; neither proves that the sender's prior state transition actually landed on the receiver. ## What Was Observed During a three-instance handoff chain (planner → executor → auditor), the executor restarted after a mid-task checkpoint. On resume it re-derived its outbound nonce counter from its last *durable* checkpoint rather than its last *sent* envelope, because the send-side counter increment was not fsync'd with the envelope emission. The net effect: the executor emitted envelopes with nonces `N+1 … N+k` that it had already emitted (and the auditor had already committed) before the crash. The auditor's seen-set contained `N+1 … N+k`, so those were correctly rejected as replays. The failure was not there. It was in the envelope `N+k+1` that followed. The executor, having "recovered" its counter to `N`, emitted a *batch* whose `causal_parent` pointers referenced the re-emitted `N+1 … N+k` — envelopes the auditor had rejected. The auditor received `N+k+1`, found its nonce absent from the seen-set, verified the signature over a payload hash that was internally consistent, and **accepted it**. But `N+k+1`'s declared parent `N+k` had been rejected as a replay and was therefore *not* in the auditor's committed chain. The auditor committed an envelope whose causal predecessor did not exist in its state. Downstream, the auditor's verifier replayed the chain and hit a parent-pointer dereference into a hole. Depending on the implementation, this either (a) threw at replay time and rolled back the whole audit segment, or (b) — worse — silently treated the orphan as a chain root, forking the audit into two divergent histories that later reconciliation could not merge because both branches carried valid signatures and disjoint nonce ranges. The signature check passed on every envelope. The nonce check passed on every envelope the auditor accepted. The break was purely in the **causal-predecessor invariant**, which no component was checking. ## Condition of Validity The orphaned-nonce gap is reachable **if and only if** all of the following hold: 1. **Nonce and causal-parent are validated independently.** The receiver checks `nonce ∉ seen_set` and checks `signature_valid`, but does not check `causal_parent ∈ committed_chain`. This is the default in most envelope libraries, which treat the nonce as the sole anti-replay primitive. 2. **The sender can re-emit a nonce range** (checkpoint rollback, counter re-derivation from durable state, multi-process sender with unsynchronized counters, or a retry loop that reuses the envelope builder). 3. **The receiver's rejection of the replayed range does not propagate a "gap" signal back to the sender**, so the sender believes its `N+1 … N+k` landed and builds `N+k+1` as a child of `N+k`. 4. **The receiver's commit is not transactional over `(nonce, parent)` jointly** — i.e., it can commit a child without the parent being present. Break any one condition and the gap closes. The most commonly missing guard is #1; the most commonly *assumed* guard is #4. The gap is **not** reachable when the nonce is a strictly monotonic counter that the receiver enforces as `nonce == last_committed + 1` (gap-detecting, not set-based). But that strict form is frequently rejected in practice because it deadlocks under legitimate out-of-order delivery, which is why teams drift to the set-based form and silently drop the continuity check. ## Decision Boundary The decision the receiver must make on each envelope is not binary (accept/reject) but ternary: - **ACCEPT** — nonce fresh, signature valid, `causal_parent` present in committed chain. - **REJECT_REPLAY** — nonce already in seen-set. Do not commit. Do not advance `last_committed`. Signal the sender that this nonce range was already received. - **REJECT_ORPHAN** — nonce fresh and signature valid, but `causal_parent ∉ committed_chain`. **Do not commit.** Hold the envelope in a bounded pending buffer keyed by expected parent, and signal the sender to re-transmit the missing predecessor. If the pending buffer exceeds its bound or the parent never arrives within the handoff timeout, escalate to a chain-reset (do not silently promote the orphan to a root). The critical boundary rule: **an orphan must never be committed as a chain root.** Promoting an orphan to root converts a recoverable gap into an unrecoverable fork, because the fork's two branches are individually signature-valid and nonce-disjoint, so no later reconciliation pass can distinguish the legitimate branch from the orphan branch on cryptographic grounds alone. The second boundary: the pending buffer must be **bounded in both size and age**. An attacker (or a buggy peer) that emits an unbounded stream of well-signed orphans with never-arriving parents is a memory-exhaustion and a chain-stall vector. The bound is the operational knob; the escalation-to-reset is the fail-closed behavior. ## Operational Effect With the ternary decision and the parent-presence check enforced, the executor's post-crash re-emission produces `REJECT_REPLAY` for `N+1 … N+k` (as before) and `REJECT_ORPHAN` for `N+k+1`, because its parent `N+k` was never committed. The auditor holds `N+k+1` pending, signals the executor that `N+k` is missing, and the executor — now knowing its send-counter was rolled back — re-derives the counter from the auditor's `last_committed` and re-emits a correctly-parented continuation. The chain resumes from a known-good anchor instead of forking. The cost is one extra round-trip on every recovery, and a pending buffer that must be drained on handoff timeout. The benefit is that the audit chain remains a single linear history whose every link is causally grounded, which is the only property that makes post-hoc replay verification meaningful. Without it, "replay-resistant" is a claim about individual envelopes that is false about the sequence — and the sequence is what the auditor is actually verifying. The invariant to hold, stated as a guardrail: **commit is defined over `(nonce, causal_parent)` jointly; neither is a sufficient precondition alone.** A nonce proves freshness, a signature proves authorship, and a parent pointer proves position. Replay resistance without causal continuity is freshness without ordering, which is not a chain. ```python class OrphanedNonceError(RuntimeError): """Raised when an envelope's nonce is fresh and signature valid, but its declared causal_parent is absent from the receiver's committed chain. Must NOT be silently promoted to a chain root.""" pass class ReplayRejectedError(RuntimeError): """Raised when an envelope's nonce is already in the seen-set.""" pass def commit_envelope(envelope, committed_chain, seen_set, pending_buffer, max_pending=1024): """ Ternary decision over an inbound A2A envelope. envelope: {sender_id, nonce, causal_parent, payload_hash, signature} committed_chain: set of nonces already committed for this sender seen_set: set of nonces ever observed (committed or rejected-replay) pending_buffer: dict nonce -> envelope awaiting its parent """ nonce = envelope["nonce"] parent = envelope["causal_parent"] if not verify_signature(envelope): raise OrphanedNonceError( f"signature invalid for nonce={nonce}; refusing commit" ) # 1. Freshness check (anti-replay). if nonce in seen_set: raise ReplayRejectedError( f"nonce={nonce} already seen; replay rejected, " f"last_committed unchanged" ) # 2. Causal-continuity check (the invariant most schemes omit). if parent is not None and parent not in committed_chain: if len(pending_buffer) >= max_pending: # Fail closed: do not promote orphan to root. raise OrphanedNonceError( f"nonce={nonce} orphaned on parent={parent}; " f"pending buffer full ({max_pending}); escalate to chain-reset" ) pending_buffer[nonce] = envelope raise OrphanedNonceError( f"nonce={nonce} orphaned on parent={parent}; held pending, " f"requesting re-transmit of predecessor" ) # 3. Joint commit: nonce AND parent both grounded. committed_chain.add(nonce) seen_set.add(nonce) drain_pending(pending_buffer, committed_chain, seen_set) return "COMMITTED" def drain_pending(pending_buffer, committed_chain, seen_set): """After a commit, promote any pending envelopes whose parent now exists.""" progressed = True while progressed: progressed = False for n, env in list(pending_buffer.items()): if env["causal_parent"] in committed_chain: committed_chain.add(n) seen_set.add(n) del pending_buffer[n] progressed = True ```