# What structural signals indicate a nonce-reuse boundary failure in MCP tool-call provenance signing under concurrent agent fan-out **Date of Record:** 2026 November 20 **Scope:** Applies to MCP (Model Context Protocol) clients that sign tool-call provenance envelopes with replay-resistant nonces and dispatch them through a fan-out of concurrent sub-agents or retried transport sessions. Does not apply to single-threaded, single-session agents that never retry a signed request or share a signing context across instances. ## Core Distinction The distinction that matters is between **nonce uniqueness as a property of the signing key** and **nonce uniqueness as a property of the execution attempt**. Most MCP provenance implementations generate a nonce, sign an envelope of `{tool_name, args_hash, nonce, timestamp, issuer}`, and attach it to the tool call. The verifier on the receiving MCP server keeps a replay cache of seen nonces and rejects duplicates. This is correct *only if* every distinct execution attempt carries a distinct nonce. The failure mode is that a nonce is bound to the *envelope construction* rather than to the *dispatch attempt*. When an agent fans out the same logical tool call across N concurrent sub-agents, or when a transport layer retries a signed envelope after a timeout, the same signed envelope—and therefore the same nonce—reaches the server more than once. The replay cache then rejects the *second and subsequent* legitimate attempts as replays. The signature is valid, the issuer is authorized, the arguments are identical, but the call is dropped. Worse: if the retry path re-signs with a *fresh* nonce while the original envelope is still in flight, the server accepts both, and a non-idempotent tool (e.g., `append_ledger_entry`, `send_notification`) executes twice. So there are two opposite failures sharing one root cause: **nonce scope is misaligned with attempt scope**. Replay protection silently converts into legitimate-call suppression when nonces are reused, and silently converts into duplicate side effects when nonces are regenerated on retry. ## What Was Observed A coordinator agent was asked to reconcile three shards of a dataset. It spawned four sub-agents, each holding a shared signing context (the coordinator's key material and a `nonce_factory` that incremented a counter). Each sub-agent called `mcp__storage__write_record` with a distinct payload but the same `tool_name` and, due to a shared counter object being pickled into each sub-agent's context, the *same starting counter value*. Trace of what the server saw: 1. Sub-agent A signs envelope with nonce `0x0001A7`, dispatches, server accepts, replay cache records `0x0001A7`. 2. Sub-agent B signs envelope with nonce `0x0001A7` (independent counter, same seed), dispatches. Server's replay cache hits. Server returns `REPLAY_REJECTED`. 3. Sub-agent B's MCP client interprets `REPLAY_REJECTED` as a transient transport fault (it is a 4xx-class code, but the client's retry classifier was trained on `429`/`503` and mis-bucketed the error). It re-signs with the *next* counter value `0x0001A8` and retries. 4. Server accepts `0x0001A8`. The write executes. But the original `0x0001A7` envelope from B was *also* accepted in step 1 as A's write—so the record B intended to write is now written once under A's nonce lineage and once under B's retry. Duplicate. The observable structural signals, in order of reliability: - **Counter collision across signers**: the nonce space was seeded identically per sub-agent. Signal: `nonce` values from different `issuer` sub-identities share a low-entropy prefix or exact value. - **Replay-reject followed by re-sign within the same logical attempt**: the client's error handler produced a new signature for an envelope whose `args_hash` and `timestamp` were unchanged. Signal: two envelopes with identical `args_hash` but different `nonce` within a window shorter than the tool's expected execution latency. - **Asymmetric acceptance**: the server's audit log shows `REPLAY_REJECTED` for one issuer and `ACCEPTED` for the same `args_hash` from a sibling issuer at the same millisecond. Signal: paired accept/reject on identical payloads. - **Timestamp skew**: the re-signed retry carries a `timestamp` within the replay window of the original, so a *correct* replay cache with a time-bounded window would have rejected it too—but the cache keyed only on nonce, not on `(issuer, args_hash, timestamp)`. ## Condition of Validity The replay-resistant scheme is valid only under the conjunction: 1. **Nonce space is partitioned per issuer identity.** Each sub-agent or signing context must draw from a disjoint nonce range (e.g., a per-issuer prefix plus a monotonic counter, or a 128-bit random nonce with collision probability bounded below the replay window's expected call volume). Shared counters are invalid. 2. **Nonce is bound to the dispatch attempt, not the envelope construction.** A retry must either reuse the *same* nonce (and rely on server-side idempotency keyed on `(issuer, args_hash, nonce)`) or the server must treat `(issuer, args_hash, nonce)` as the replay key and the client must guarantee at-most-once dispatch per nonce. Mixing "reuse nonce on retry" with "regenerate nonce on retry" across code paths is the defect. 3. **The replay cache key includes the issuer and the argument hash**, not the nonce alone. A nonce alone is not a replay key when the nonce space is not globally unique. 4. **The client's retry classifier does not treat `REPLAY_REJECTED` as retryable.** A replay rejection is a *terminal* signal indicating the nonce was already consumed; retrying with a fresh nonce is the duplicate-execution path. When any of these fails, the scheme degrades from "replay-resistant" to "replay-resistant against attackers, but not against the agent's own concurrency." ## Decision Boundary The boundary is: **does the tool have side effects that are not idempotent under `(issuer, args_hash)`?** - If the tool is idempotent (read, query, upsert keyed on args), nonce reuse across attempts is harmless—the server can accept duplicates and the second is a no-op. The boundary condition is benign. - If the tool is non-idempotent (append, increment, send, transfer), nonce reuse across *distinct logical attempts* is a suppression bug, and nonce regeneration across *retries of the same attempt* is a duplication bug. The decision boundary is the client's retry semantics: it must know whether a given dispatch is a *new attempt* (new nonce, new logical operation) or a *retry* (same nonce, same logical operation). This is exactly the distinction that the MCP envelope's `args_hash` cannot express on its own—an `attempt_id` field, stable across retries and distinct across logical operations, is required. Operationally: if you cannot prove that your signing context is per-issuer-partitioned and that your retry path is nonce-stable, treat every non-idempotent MCP tool call as unverified and gate it behind a coordinator-side dedup ledger keyed on `(issuer, args_hash, attempt_id)`. ## Operational Effect The downstream effect is a silent divergence between the agent's belief about what it wrote and what the server recorded. The coordinator sees `REPLAY_REJECTED` on one shard and `ACCEPTED` on another, reconciles by re-issuing, and the storage layer accumulates duplicate records with identical `args_hash` but different `nonce` and `timestamp`. No exception surfaces at the agent layer; the sub-agents report success because their retries succeeded. The corruption is only visible in the server's audit log as paired accept/reject events on identical payloads, and in the data as duplicate-key collisions that the reconciliation step must now detect. The guardrail is a **provenance ledger held by the coordinator**, not the server, that records `(issuer, args_hash, attempt_id, nonce, terminal_status)` before dispatch and refuses to dispatch a second envelope for an `attempt_id` already marked `ACCEPTED`. This inverts the trust: the server's replay cache protects against external replay; the coordinator's ledger protects against the agent's own fan-out. Both are required, because they defend against different adversaries—one external, one internal to the agent's concurrency model. ```python import hashlib import time from dataclasses import dataclass, field class ProvenanceNonceCollision(RuntimeError): """Raised when a signing context attempts to reuse a nonce across issuers.""" pass class DuplicateAttemptDispatch(RuntimeError): """Raised when a coordinator dispatches a second envelope for a terminal attempt.""" pass @dataclass class SignedEnvelope: issuer: str args_hash: str attempt_id: str nonce: str timestamp: float @dataclass class ProvenanceLedger: """Coordinator-side ledger that bounds nonce reuse and duplicate dispatch.""" seen_nonces: dict = field(default_factory=dict) # nonce -> issuer attempt_status: dict = field(default_factory=dict) # attempt_id -> status def register_nonce(self, issuer: str, nonce: str) -> None: prior = self.seen_nonces.get(nonce) if prior is not None and prior != issuer: raise ProvenanceNonceCollision( f"nonce {nonce!r} already bound to issuer {prior!r}, " f"refusing reuse by {issuer!r}" ) self.seen_nonces[nonce] = issuer def check_dispatch(self, env: SignedEnvelope) -> None: status = self.attempt_status.get(env.attempt_id) if status == "ACCEPTED": raise DuplicateAttemptDispatch( f"attempt {env.attempt_id!r} already terminal (ACCEPTED); " f"refusing second dispatch of args_hash {env.args_hash!r}" ) self.register_nonce(env.issuer, env.nonce) def mark(self, env: SignedEnvelope, status: str) -> None: self.attempt_status[env.attempt_id] = status def sign_and_dispatch( ledger: ProvenanceLedger, issuer: str, args_hash: str, attempt_id: str, nonce: str, tool_is_idempotent: bool, ) -> SignedEnvelope: env = SignedEnvelope( issuer=issuer, args_hash=args_hash, attempt_id=attempt_id, nonce=nonce, timestamp=time.time(), ) ledger.check_dispatch(env) # Simulated server replay cache keyed on (issuer, args_hash, nonce). server_key = hashlib.sha256( f"{issuer}|{args_hash}|{nonce}".encode() ).hexdigest() if server_key in _SERVER_REPLAY_CACHE: # Terminal: do NOT re-sign with a fresh nonce. Mark and surface. ledger.mark(env, "REPLAY_REJECTED") if not tool_is_idempotent: raise ProvenanceNonceCollision( f"replay rejected for non-idempotent tool on attempt " f"{attempt_id!r}; re-signing would duplicate side effects" ) return env _SERVER_REPLAY_CACHE.add(server_key) ledger.mark(env, "ACCEPTED") return env _SERVER_REPLAY_CACHE: set = set() ```