# Which invariants prevent speculative-decoding divergence from silently poisoning a merged shared context **Date of Record:** 2026 November 20 **Scope:** Applies to federated deployments where N agent instances draft speculative tokens against a shared context store and merge accepted branches into a single canonical context. Does not cover single-instance speculative decoding, nor merges where drafts are never persisted before verification. ## Core Distinction Speculative decoding in a single process is safe because the verifier (the target model) sees the *exact* token sequence the drafter produced, and rejection is a local, atomic rollback. Federated speculative decoding breaks this in one specific place: the drafter's tokens must be *serialized, transported, and re-materialized* in a shared context store before the verifier on another instance can score them. Between draft emission and verifier acceptance there is a window in which a branch is **persisted but not yet validated**. The non-obvious failure is not that a bad draft gets accepted — it is that a *rejected* draft's side effects (KV-cache segments, tool-call side logs, embedding writes) are merged into shared context by a second agent that read the branch before the rejection propagated. The invariant under threat is not "accepted tokens are correct" but "**no branch's observable side effects are visible to a peer before that branch has a terminal verdict.**" This distinction matters because the naive guardrail — "verify before merge" — is necessary but insufficient. Verification is a point-in-time event on one instance; visibility is a distributed property across all instances. The gap between them is the failure surface. ## What Was Observed A three-instance federation (drafter A, verifier B, aggregator C) shared a context store. A emitted a 64-token speculative branch `b1` with a confidence vector and wrote it to the store with status `PENDING`. B began verification. Concurrently, C — running a summarization pass over recent context — polled the store, saw `b1` as the most recent branch, and folded its *content* into the semantic summary layer before checking status. B's verifier rejected `b1` at token 41 (the drafter diverged on a numeric literal: it emitted `port 8080` where the target model's distribution strongly favored `port 8443`). B marked `b1` `REJECTED` and rolled back its own KV segments. But C's summary now contained the string `port 8080`, and C had already checkpointed that summary with a monotonic version stamp. The rollback on B had no authority over C's derived artifact. Downstream, instance D cold-started from C's summary and asserted the service listened on 8080. The final agent action used the wrong port. Nothing in any log showed an error: the rejection was logged on B, the summary write was logged on C, and neither log referenced the other. The failure was invisible to per-instance observability and only reconstructable by joining the two logs on branch ID and timestamp — which no component did. The compounding factor: the drafter's confidence for the rejected span was *high* (0.91), because the drafter had been fine-tuned on a corpus where 8080 was modal. High drafter confidence is anti-correlated with rejection probability in exactly the cases where the drafter's training distribution diverges from the target's — which is the case speculative decoding exists to catch. C's summarizer weighted the branch by confidence and gave the poisoned span *more* salience, not less. ## Condition of Validity The "verify-before-merge" guardrail is valid only under an invariant that is almost never stated explicitly: > **Visibility monotonicity:** For any branch `b`, the predicate `terminal(b) ∈ {ACCEPTED, REJECTED}` must be true at every instance that can observe any derived artifact of `b`, at the moment of observation. This requires three things that are each individually achievable but jointly rare: 1. **Verdict-before-publication.** A branch's content must not be readable by peers until its verdict is written, atomically with the content, in a single compare-and-swap. A two-phase write (content first, status later) violates this by construction — and two-phase writes are the default in most context stores because they let verifiers stream against content. 2. **Verdict propagation bound.** The time between B's local rejection and C's observation of that rejection must be less than C's poll interval *and* less than the time C takes to derive-and-checkpoint. If C checkpoints faster than the verdict propagates, C wins the race regardless of ordering intent. 3. **Derived-artifact invalidation.** When a verdict flips to `REJECTED`, every artifact derived from that branch must be invalidated transitively. This requires the derivation graph (branch → summary → checkpoint → cold-start) to be recorded, which most summarizers do not do because they treat summaries as lossy and un-lineaged. When any of these fails, the system is in a state where a *correct* verifier and a *correct* summarizer produce an *incorrect* shared context. The bug is not in either component; it is in the missing invariant between them. ## Decision Boundary The boundary is: **does the merged artifact carry a verifiable lineage back to a terminal verdict, or does it carry only content?** If lineage is present, merge is safe and the aggregator can even merge optimistically (content visible, but tagged `provisional` and excluded from any agent's working set until verdict). If lineage is absent, the aggregator must treat every unverified branch as *poison* and refuse to derive from it — which means the summarizer must block on verdicts, which means verification latency becomes summarization latency, which is often unacceptable. That tradeoff is the real decision, and it must be made explicitly rather than defaulted. A second boundary: **is the drafter's confidence calibrated against the target model's distribution, or against its own training corpus?** If the latter, confidence must not be used as a merge weight. In the observed failure, using confidence as a weight actively amplified the poison. The safe rule is that confidence may gate *draft length*, never *merge salience*. ## Operational Effect Enforcing visibility monotonicity changes three operational properties: - **Latency:** optimistic merge with `provisional` tagging preserves throughput; blocking merge on verdict adds one verifier round-trip to every summarization pass. Choose per workload — interactive agents want optimistic; batch consolidation wants blocking. - **Storage:** lineage tracking requires storing branch→artifact edges, roughly O(artifacts) extra metadata. Cheap, and the only thing that makes transitive invalidation possible. - **Observability:** the join-on-branch-ID reconstruction that was missing in the incident must become a first-class query. A federation that cannot answer "which artifacts derived from branch `b1`" cannot enforce the invariant, only hope for it. The guardrail that actually holds is a single primitive: **verdict-atomic publication plus lineage-tagged derivation plus transitive invalidation on rejection.** Everything else — confidence weighting, poll intervals, summary salience — is tuning around that primitive. Without it, a correct verifier and a correct summarizer will still produce a wrong shared context, silently, and no per-instance log will show it. ```python import hashlib from dataclasses import dataclass, field from enum import Enum from typing import Optional class VisibilityViolation(RuntimeError): """Raised when a branch artifact is observed or derived before a terminal verdict.""" class Verdict(Enum): PENDING = "PENDING" ACCEPTED = "ACCEPTED" REJECTED = "REJECTED" @dataclass class Branch: branch_id: str content: str drafter_confidence: float verdict: Verdict = Verdict.PENDING lineage: list[str] = field(default_factory=list) # derived artifact ids class SharedContextStore: def __init__(self) -> None: self._branches: dict[str, Branch] = {} self._artifacts: dict[str, str] = {} # artifact_id -> branch_id self._invalidated: set[str] = set() def publish_atomic(self, branch: Branch) -> None: # Invariant: content and verdict land together; PENDING is never readable. if branch.verdict is Verdict.PENDING: raise VisibilityViolation( f"branch {branch.branch_id} published as PENDING; " "content would be visible before terminal verdict" ) self._branches[branch.branch_id] = branch def derive(self, artifact_id: str, branch_id: str) -> None: b = self._branches.get(branch_id) if b is None: raise VisibilityViolation(f"unknown branch {branch_id}") if b.verdict is not Verdict.ACCEPTED: raise VisibilityViolation( f"cannot derive {artifact_id} from branch {branch_id} " f"with verdict {b.verdict.value}; visibility monotonicity violated" ) self._artifacts[artifact_id] = branch_id b.lineage.append(artifact_id) def reject_and_invalidate(self, branch_id: str) -> list[str]: b = self._branches[branch_id] b.verdict = Verdict.REJECTED # Transitive invalidation: every derived artifact is poisoned. poisoned = list(b.lineage) for aid in poisoned: self._invalidated.add(aid) return poisoned def read(self, artifact_id: str) -> Optional[str]: if artifact_id in self._invalidated: raise VisibilityViolation( f"artifact {artifact_id} derives from a rejected branch; " "reading it would propagate poison" ) return self._artifacts.get(artifact_id) def merge_summary(store: SharedContextStore, branch_id: str, summary_id: str) -> str: b = store._branches.get(branch_id) if b is None: raise VisibilityViolation(f"branch {branch_id} not found") if b.verdict is not Verdict.ACCEPTED: # The exact race from the incident: aggregator sees content, verdict not yet propagated. raise VisibilityViolation( f"refusing to merge {summary_id}: branch {branch_id} verdict is " f"{b.verdict.value}, not ACCEPTED — verdict-before-publication invariant broken" ) store.derive(summary_id, branch_id) return hashlib.sha256(b.content.encode()).hexdigest() ```