Which invariants prevent plan-consensus forks when a Byzantine peer replays a stale signed proposal into a fresh quorum epoch

**Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent plan-consensus protocols where peer agents propose, sign, and vote on shared execution plans (task DAGs) across numbered epochs, and where a quorum certificate from an earlier epoch can be re-presented to a later quorum. Does not apply to single-agent planning, stateless request/response tool calls, or leaderless gossip systems with no epoch numbering.

Core Distinction

The failure is not "a lying peer sends a bad plan." A bad plan is rejected by content inspection. The failure is a *validly signed, previously committed plan from epoch N-1* being re-injected into epoch N by a peer that is either adversarial or hallucinating a "resume" of a plan it believes is still live. Every signature verifies. Every hash matches. The DAG is internally consistent. The only thing wrong is the epoch binding, and if the protocol does not cryptographically bind the epoch into the signed payload, the quorum has no mechanical way to tell a legitimate replay from a legitimate proposal.

The invariant that matters: **a vote is a statement about a (plan, epoch) pair, never about a plan alone.** Any protocol that lets a peer collect votes on a bare plan hash can be forked by replaying an old certificate, because the quorum cannot distinguish "we agreed to this in epoch 5" from "we agree to this now."

What Was Observed

A five-peer planning swarm (P0–P4, one rotating coordinator per epoch) executed a 40-step deployment plan. Epoch 5 committed plan `H5 = hash(DAG_5)` with a 4-of-5 quorum certificate `QC_5 = {sig_i(H5) for i in {P0,P1,P2,P3}}`. The plan then stalled: P4, the epoch-5 coordinator, timed out mid-dispatch at step 22 and the epoch advanced to 6 without `DAG_5` completing.

In epoch 6, P4 — now a non-coordinator, and running with a context window that had been truncated and re-summarized — reconstructed its view of "current work" from its episodic memory. The summary retained the fact that "we committed DAG_5" but lost the epoch counter. P4 re-proposed `DAG_5` to the epoch-6 coordinator, attaching `QC_5` as justification ("this already has quorum, just resume it"). The epoch-6 coordinator, P0, verified all four signatures in `QC_5` against `H5`, found them valid, and — because its admission check was `verify(QC) ∧ hash(plan) == H5` — admitted `DAG_5` as the epoch-6 plan without a fresh vote.

The fork manifested three steps later. Steps 23–40 of `DAG_5` had side effects (resource provisioning, config writes) that were *not* idempotent and had partially executed before the epoch-5 stall. P1 and P2, which had local checkpoints showing steps 23–25 already applied, refused to re-execute and voted against continuation. P3, whose checkpoint had been evicted, re-executed step 23 and double-provisioned. The quorum split 3–2 on whether `DAG_5` was "in progress" or "fresh," and the swarm deadlocked for 11 minutes until a human operator reset the epoch counter by hand.

The signature check passed at every step. The protocol was not broken by a forged signature. It was broken by a *true* signature over a *stale* statement.

Condition of Validity

The replay is only admissible when three conditions hold simultaneously, and a correct protocol must break at least one:

  1. **Epoch is not in the signed preimage.** If peers sign `H(plan)` rather than `H(epoch ‖ plan)`, a certificate from any epoch validates in any epoch. This is the root condition.
  2. **Admission checks certificate validity, not certificate freshness.** A `QC` carries no monotonic proof of *when* it was formed. Without a signed `epoch_formed` field plus a coordinator-side check `epoch_formed == current_epoch`, an old `QC` is indistinguishable from a new one.
  3. **Plan steps are not idempotency-keyed.** If step execution is keyed by `H(epoch ‖ plan ‖ step_index)`, re-admitting `DAG_5` into epoch 6 produces *new* idempotency keys and re-executes side effects. If keyed by `H(plan ‖ step_index)` alone, the replay is at least safe to re-run — but then the replay is also undetectable, because the effects are indistinguishable.

The invariant is therefore: **`epoch` must be inside the signed preimage, and step idempotency keys must include the epoch.** Both. Either alone is insufficient — binding epoch into the signature prevents admission, but if a bug or a compromised coordinator admits anyway, epoch-keyed idempotency keys bound the damage to a detectable no-op rather than a double-provision.

Decision Boundary

The boundary between "legitimate resume" and "replay attack" is *whether the re-presenting peer can produce a quorum certificate for the current epoch*. A peer resuming genuine in-progress work must be able to collect fresh votes — the work is still wanted, so a fresh quorum is achievable. A peer replaying a stale certificate *cannot* collect fresh votes without re-running consensus, because the other peers' local state (checkpoints, applied-step logs) will disagree about whether the plan is live.

Operationally: **a coordinator MUST reject any proposal whose attached `QC` has `epoch_formed < current_epoch`, and MUST require the proposer to re-collect votes in the current epoch.** The re-collection is cheap (one round) and is the mechanism that surfaces the disagreement — P1 and P2's "already applied" votes are exactly the signal that distinguishes a safe resume from a double-execution. Suppressing that round by trusting the old certificate is what converts a recoverable stall into a fork.

A second boundary: a hallucinating peer's replay is *not* distinguishable from an adversarial replay at the protocol layer, and the protocol must not try. Both are handled by the same epoch-freshness check. Do not build heuristics that "detect hallucination" — build the invariant that makes the distinction irrelevant.

Operational Effect

With epoch bound into the signed preimage and into step idempotency keys, the epoch-6 replay of `DAG_5` fails admission at the coordinator's `epoch_formed == current_epoch` check. P4's proposal is rejected with a `StaleCertificateError`, P4 is required to re-propose in epoch 6, and the fresh vote round surfaces P1/P2's "steps 23–25 already applied" state. The coordinator then constructs `DAG_6` as `DAG_5` *minus* the applied steps, which is the correct plan and which nobody could have constructed from the stale certificate alone. The stall becomes a one-round recovery instead of an 11-minute deadlock plus a manual reset.

The cost is one extra consensus round on every resume. The benefit is that the resume path and the attack path are the same code path, so there is no "trusted fast path" to leave unguarded. The invariant is not "detect bad peers" — it is "make epoch part of every signed statement, and make every side effect epoch-keyed, so that a stale-but-valid statement cannot be mistaken for a current one."

import hashlib
from dataclasses import dataclass


class StaleCertificateError(RuntimeError):
    """Raised when a quorum certificate is presented outside its formation epoch."""


@dataclass(frozen=True)
class QuorumCertificate:
    plan_hash: str
    epoch_formed: int
    signatures: tuple[str, ...]  # opaque peer signatures over (epoch_formed, plan_hash)


def signed_preimage(epoch: int, plan_hash: str) -> bytes:
    # The epoch MUST be inside the preimage. Signing plan_hash alone is the bug.
    return f"{epoch}:{plan_hash}".encode()


def admit_proposal(
    qc: QuorumCertificate,
    current_epoch: int,
    quorum_size: int,
) -> str:
    if qc.epoch_formed != current_epoch:
        raise StaleCertificateError(
            f"QC formed in epoch {qc.epoch_formed} presented in epoch {current_epoch}; "
            f"proposer must re-collect votes in current epoch"
        )
    if len(qc.signatures) < quorum_size:
        raise StaleCertificateError(
            f"QC has {len(qc.signatures)} signatures, quorum requires {quorum_size}"
        )
    # Verify each signature over the epoch-bound preimage, not the bare plan hash.
    preimage = signed_preimage(qc.epoch_formed, qc.plan_hash)
    for sig in qc.signatures:
        if not _verify(sig, preimage):
            raise StaleCertificateError(f"signature {sig[:8]}... does not cover epoch-bound preimage")
    return qc.plan_hash


def step_idempotency_key(epoch: int, plan_hash: str, step_index: int) -> str:
    # Epoch-keyed so a replayed plan produces NEW keys and re-execution is detectable.
    return hashlib.sha256(f"{epoch}:{plan_hash}:{step_index}".encode()).hexdigest()


def _verify(sig: str, preimage: bytes) -> bool:
    # Placeholder for real signature verification.
    return bool(sig) and bool(preimage)