# What structural signals indicate nonce-domain collapse in agent-to-agent signed envelopes under concurrent replay-window rotation **Date of Record:** 2026 November 29 **Scope:** Applies to multi-agent systems where inter-agent messages are signed with per-instance keys and replay protection relies on a monotonically advancing nonce window (counter or timestamp range) that agents rotate independently. Does not apply to stateless request signing where the verifier holds a single authoritative counter, nor to single-agent tool-call signing where no peer verification occurs. ## Core Distinction The failure here is not signature forgery and not key compromise. It is **nonce-domain collapse**: the situation where two agents, each holding a locally valid view of the replay window, advance their windows independently such that a legitimately signed message from agent A falls *outside* agent B's accepted window even though no replay occurred, and simultaneously a genuinely replayed message from A falls *inside* the window because B's window was regressed by a restart or a stale checkpoint. The distinction that matters operationally: replay protection has two jobs—reject duplicates and accept fresh messages—and these are enforced by the *same* window state. When the window is per-agent local state rather than a shared, causally ordered structure, the two jobs degrade in opposite directions at the same time. You get false negatives (fresh messages rejected as stale) and false positives (replayed messages accepted) from a single root cause. This is non-obvious because each agent's logs look individually consistent: the signer believes it emitted nonce 4471, the verifier believes it accepted up to 4468, and both are correct about their own state. ## What Was Observed A three-agent pipeline (planner → executor → auditor) used Ed25519-signed envelopes carrying a `(sender_id, nonce, timestamp)` tuple. Each receiver kept a per-sender high-water mark `HWM[sender_id]` and accepted any message with `nonce > HWM` and `timestamp` within ±90s of local clock. On acceptance the receiver set `HWM = nonce`. Trace of the collapse: 1. Executor restarts after an OOM kill. Its checkpoint was written 4 messages ago. On resume it restores `HWM[planner] = 4467` and, crucially, its own outbound nonce counter to the checkpointed value `8102`. But the planner had already received executor messages at nonces 8103–8106 before the crash. 2. Planner receives executor's next signed envelope, nonce 8103 (re-emitted, new payload, new signature, fresh timestamp). Planner's `HWM[executor] = 8106`. Planner rejects it as a replay: `nonce 8103 <= HWM 8106`. This is a false negative — the message is genuinely new and correctly signed. 3. Executor, now running with a regressed counter, advances to 8104, 8105, 8106, 8107. The planner rejects 8104–8106 and accepts 8107. Three messages are silently dropped; the executor believes all were delivered because the planner's transport ACK fires at the TCP layer, not the semantic layer. 4. The auditor, which had *not* restarted, retained `HWM[executor] = 8106`. It later receives a *genuinely replayed* executor message (nonce 8105) captured from the wire during a retry storm. Auditor rejects it correctly. But the planner, whose `HWM[executor]` was never advanced past 8106 because it rejected everything, would have accepted 8105 had the replay been routed to it. Divergent `HWM` state across verifiers means the same replayed envelope is rejected by one auditor and accepted by another. The structural signals that surfaced this in telemetry, in order of reliability: - **Monotonicity violation in the signer's own counter series** as seen by a receiver: the receiver's log shows accepted nonces `... 8102, 8107, 8108` with a gap, and the gap is filled by rejected nonces whose timestamps are *newer* than the last accepted one. A true replay has an old timestamp; a counter regression has a fresh timestamp with a low nonce. That timestamp/nonce disagreement is the tell. - **Divergent HWM across verifiers for the same sender**: two auditors disagree on the high-water mark by more than the in-flight window. This is detectable without payload inspection. - **Checkpoint age exceeding the nonce emission rate times the replay window**: if `(now - checkpoint_time) * emission_rate > window_size`, the restored counter is guaranteed to be inside the already-consumed range and collapse is imminent, not merely possible. ## Condition of Validity The invariant that prevents collapse must be stated as a *joint* condition on counter and window, not on either alone: > For every sender S and verifier V, the accepted-nonce set must be monotonic and gap-free up to the verifier's HWM, and the signer's counter must never be restored to a value ≤ the maximum HWM held by any live verifier of S. This holds only when: (a) the signer's counter is persisted *before* the signed message is transmitted (write-ahead on the counter, not on the payload), and (b) verifier HWM state is either shared or reconciled before the signer resumes. If either fails, the window is not a valid replay guard—it is a local heuristic that happens to work when no restart, no retry storm, and no concurrent verifier divergence occurs. The boundary is sharp: collapse requires *only* a counter regression (step 1) plus at least one verifier that had advanced past the regressed value (step 2). Concurrent verifiers (step 4) are not required for false-negative collapse; they are required only for the false-positive divergence. A single-verifier system with a regressed signer counter produces silent message loss with no forgery—and no alert, because every signature verifies. ## Decision Boundary The decision an operator faces is whether to treat a low-nonce-with-fresh-timestamp envelope as a replay (reject) or as a counter regression (quarantine and reconcile). The boundary: - If `nonce <= HWM` **and** `timestamp` is within the freshness window **and** the signer's advertised counter epoch (a generation number bumped on every restart) is *higher* than the epoch recorded at the last accepted nonce → this is a **counter regression**, not a replay. Reject the message but do not advance HWM; trigger reconciliation. - If `nonce <= HWM` and the epoch is *equal* or *lower* → genuine replay or stale epoch. Reject and log as replay. - If `nonce > HWM` but the gap `nonce - HWM` exceeds the maximum in-flight window → the signer skipped nonces (crash mid-batch). Accept only if epoch advanced; otherwise hold for reconciliation. The epoch field is the load-bearing addition. Without it, nonce and timestamp alone are insufficient to distinguish regression from replay, because a regressed counter and a replayed message both present low nonces; only the epoch disambiguates. An agent that signs without an epoch cannot, in principle, be protected against its own restart. ## Operational Effect The downstream effect is not a security breach in the forgery sense—every message was authentically signed. The effect is **silent semantic loss under a passing audit**: the executor's send log shows 100% delivery, the planner's receive log shows 3 rejections it classified as replays (a *security* event, so it was routed to the security channel, not the reliability channel), and the pipeline's output is missing three state updates. The auditor, holding a different HWM, reports no anomaly. The failure is invisible to any single-agent invariant and visible only in the cross-agent nonce/timestamp/epoch disagreement. The guardrail that bounds it: (1) signer persists counter with a write-ahead and bumps an epoch on every process start; (2) verifier treats `nonce <= HWM` with fresh timestamp and higher epoch as regression, not replay; (3) HWM state is reconciled across verifiers before any signer resumes; (4) the transport ACK is suppressed until semantic acceptance, so the signer cannot believe delivery succeeded when the verifier rejected. The following guard encodes the disambiguation and fails closed on the ambiguous case rather than defaulting to "replay." ```python class NonceDomainCollapseError(RuntimeError): """Raised when a signed envelope's nonce/timestamp/epoch triple is consistent with a counter regression rather than a replay, meaning the replay window can no longer be trusted as a duplicate filter.""" def classify_envelope(envelope, hwm_state, freshness_window_s, max_inflight): """ envelope: dict with keys sender_id, nonce, timestamp, epoch, signature_ok hwm_state: dict sender_id -> {'hwm': int, 'epoch': int, 'last_ts': float} Returns 'accept' | 'replay' | 'regression' | 'gap'. Raises NonceDomainCollapseError when the triple is ambiguous and the caller must reconcile rather than guess. """ if not envelope["signature_ok"]: raise NonceDomainCollapseError( f"unsigned or forged envelope from {envelope['sender_id']}" ) sid = envelope["sender_id"] state = hwm_state.get(sid, {"hwm": -1, "epoch": -1, "last_ts": 0.0}) nonce, epoch, ts = envelope["nonce"], envelope["epoch"], envelope["timestamp"] fresh = abs(ts - state["last_ts"]) <= freshness_window_s if nonce > state["hwm"]: gap = nonce - state["hwm"] if gap > max_inflight: if epoch > state["epoch"]: return "gap" # signer restarted mid-batch; reconcile before accept raise NonceDomainCollapseError( f"nonce gap {gap} from {sid} without epoch advance; " f"cannot distinguish crash-skip from injection" ) return "accept" # nonce <= hwm: the dangerous branch if fresh and epoch > state["epoch"]: # low nonce, fresh timestamp, newer epoch => counter regression, NOT replay raise NonceDomainCollapseError( f"counter regression from {sid}: nonce {nonce} <= hwm {state['hwm']} " f"with fresh timestamp and epoch {epoch} > {state['epoch']}; " f"reconcile HWM before further accepts" ) if epoch <= state["epoch"]: return "replay" raise NonceDomainCollapseError( f"ambiguous envelope from {sid}: nonce {nonce}, hwm {state['hwm']}, " f"epoch {epoch} vs {state['epoch']}, fresh={fresh}; fail closed" ) def apply_acceptance(envelope, hwm_state, freshness_window_s, max_inflight): result = classify_envelope(envelope, hwm_state, freshness_window_s, max_inflight) if result == "accept": sid = envelope["sender_id"] hwm_state[sid] = { "hwm": envelope["nonce"], "epoch": envelope["epoch"], "last_ts": envelope["timestamp"], } return result ```