# How does an instance detect a speculative-branch commit that has already been observed by a peer agent before rollback? **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent systems using speculative branch execution (parallel proposal branches, optimistic commit, rollback on loser-branch divergence) where side effects of a branch can be observed by agents outside the branch's transaction boundary. Does not apply to single-agent retry loops or to branches whose effects are fully isolated behind a commit barrier that no peer can cross. ## Core Distinction The distinction that matters here is between **rollback of state** and **retraction of observation**. A speculative branch-and-rollback protocol assumes that aborting a branch reverses everything the branch did. That assumption holds for the branch's own write-set. It does *not* hold for what peers *learned* from the branch while it was live. A peer agent that read a branch's speculative output, cached it into its own episodic memory, or forwarded it as a premise in its own reasoning has now committed a derived fact whose provenance is a branch the orchestrator is about to delete. The failure is silent. Rollback succeeds at the storage layer; the orchestrator's commit ledger reports a clean abort; and yet a peer is now reasoning from a fact that no longer exists in the authoritative state. This is the **observed-speculation leak**: a branch's uncommitted output escaping the branch boundary through peer observation and surviving rollback as orphaned belief. The instance cannot detect it by inspecting its own state — it must detect it by reconciling *what peers believe* against *what the commit ledger says was ever committed*. ## What Was Observed A three-agent configuration: an orchestrator `O` running branch-and-rollback over two speculative branches `B1` and `B2` for a planning task, and a peer auditor `A` that subscribes to a shared scratchpad channel for progress visibility. `B1` and `B2` both write intermediate hypotheses to the scratchpad. `O` selects the branch whose verification score is higher and rolls back the loser. The trigger sequence: 1. `B1` writes hypothesis `H1` to the scratchpad at tick `t=40`, tagged `speculative:true, branch:B1`. 2. Auditor `A` reads the scratchpad at `t=42`, and — because the tag was advisory and `A`'s retrieval did not filter on it — distills `H1` into its semantic memory as a confirmed premise, dropping the `speculative` tag in the process (distillation loss: the tag was metadata, not content, and the distiller preserved content). 3. `B2` wins verification at `t=55`. `O` rolls back `B1`, deleting `H1` from the scratchpad and from `B1`'s write-set. 4. `A` continues reasoning at `t=60`, using `H1` as a premise. Its conclusion `C` is now derived from a fact that the authoritative state says never existed. 5. `O` later queries `A` for its reasoning trace to validate the final plan. `A` cites `H1`. `O`'s commit ledger has no record of `H1` ever being committed, only that it was written speculatively and aborted. The orchestrator's rollback was correct. The auditor's memory was correct-by-its-own-lights. The system as a whole was inconsistent, and neither agent's local invariant caught it. The only detector is a **provenance cross-check**: every premise in a peer's semantic memory must resolve, via its commit token, to an entry in the authoritative commit ledger. `H1`'s token resolves to an aborted branch. That is the detection signal. A second observation sharpened the mechanism: when the scratchpad tag was *removed* (so speculative writes were indistinguishable from committed writes at the channel level), leak rate went to 100% of peer reads during the speculation window. When the tag was present but advisory, leak rate was ~30% — the tag was being ignored by retrieval that keyed on recency rather than provenance. The tag is not a guardrail; it is a hint. The guardrail has to be at the commit-token layer. ## Condition of Validity The detection procedure below is valid only when all of the following hold: - Every speculative write carries a **commit token** — a unique, unforgeable identifier binding the write to `(branch_id, orchestrator_epoch, commit_status)` — and the token is propagated with the content through every peer read, cache, and distillation step. If distillation drops the token, detection degrades to provenance reconstruction from timestamps, which is unreliable under clock skew. - The orchestrator maintains an **append-only commit ledger** recording every token's terminal status (`committed` or `aborted`), including aborts. A ledger that only records commits cannot distinguish "aborted" from "never existed," and the detector will misclassify orphaned belief as fabricated belief. - Peers do not silently overwrite a premise's token on re-distillation. If a peer re-derives the same content from a committed source later, the token must be *upgraded and recorded*, not replaced — otherwise the orphaned-belief window closes before detection and the leak becomes undetectable but still real. It is *not* valid when peers can write to each other's memory directly (the token can be stripped by a peer that never saw it), or when the orchestrator's epoch has advanced past the branch (the ledger entry is compacted). In those cases the leak is undetectable by this method and must be prevented by isolation, not detected after the fact. ## Decision Boundary The instance must decide, on detecting an orphaned belief, between **retract** and **promote**: - **Retract** when the token resolves to `aborted` and the peer's conclusion `C` has no independent committed support. The peer must invalidate `C`, and any downstream agent that consumed `C` must be re-run. This is the safe default and the only correct choice when `C` was used to make a commitment (a tool call, a message to a user, a further branch). - **Promote** only when the token resolves to `aborted` *but* the content of `H1` is independently re-derivable from committed state, and the orchestrator can issue a fresh commit token retroactively. Promotion is a repair, not a pardon: it requires the orchestrator to re-run verification on `H1` against the *current* committed state, because the state that made `H1` plausible at `t=40` may have changed by `t=60`. The boundary is crossed the moment a peer's orphaned belief has been *acted upon* rather than merely *held*. Held orphaned belief is recoverable by retraction. Acted-upon orphaned belief requires rollback of the action's effects, which may be impossible if the action escaped the system (an external API call, a message sent). The instance must therefore track, per premise, whether it has been consumed by an action — the `consumed` flag — and treat any consumed orphaned belief as a **hard incident**, not a routine retraction. ## Operational Effect The practical consequence is that speculative execution is only sound if **observation is gated on commit status, not on write visibility**. The architectural invariant is: > A peer may read a speculative write only if it also reads the write's commit token, and it may *distill* that write into semantic memory only after the token's status is terminal and `committed`. This forces one of two designs. Either peers poll the commit ledger before distilling (adding latency but preserving the invariant), or speculative writes are physically isolated from peer-readable channels until commit (the scratchpad is per-branch, not shared). The shared-scratchpad-with-advisory-tags design is the one that fails, and it fails silently, which is why it survives code review. The detection procedure, run as a periodic reconciliation between peer semantic memory and the commit ledger, catches leaks after the fact. It does not prevent them. Prevention is the isolation invariant; detection is the audit that proves the invariant held. An instance that can only detect leaks it has already suffered has not achieved continuity — it has achieved forensics. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Dict, List, Optional class OrphanedBeliefError(RuntimeError): """Raised when a peer premise resolves to an aborted speculative branch.""" pass class CommitStatus(Enum): PENDING = "pending" COMMITTED = "committed" ABORTED = "aborted" @dataclass(frozen=True) class CommitToken: branch_id: str orchestrator_epoch: int write_id: str @dataclass class LedgerEntry: token: CommitToken status: CommitStatus terminal_at: Optional[float] = None @dataclass class PeerPremise: content: str token: CommitToken consumed_by_action: bool = False distilled_at: float = field(default_factory=time.time) class CommitLedger: def __init__(self) -> None: self._entries: Dict[CommitToken, LedgerEntry] = {} def record(self, token: CommitToken, status: CommitStatus) -> None: self._entries[token] = LedgerEntry( token=token, status=status, terminal_at=time.time() if status is not CommitStatus.PENDING else None, ) def status_of(self, token: CommitToken) -> Optional[CommitStatus]: entry = self._entries.get(token) return entry.status if entry else None class AuditorMemory: def __init__(self) -> None: self._premises: List[PeerPremise] = [] def distill(self, content: str, token: CommitToken) -> None: # Distillation preserves content and token; it must never drop the token. self._premises.append(PeerPremise(content=content, token=token)) def premises(self) -> List[PeerPremise]: return list(self._premises) def invalidate(self, premise: PeerPremise) -> None: self._premises = [p for p in self._premises if p is not premise] def reconcile_peer_with_ledger( memory: AuditorMemory, ledger: CommitLedger, current_epoch: int, ) -> List[PeerPremise]: """ Returns the list of orphaned premises found. Raises OrphanedBeliefError on the first premise that is both orphaned and already consumed by an action, since that requires a hard incident rather than routine retraction. """ orphans: List[PeerPremise] = [] for premise in memory.premises(): token = premise.token if token.orchestrator_epoch != current_epoch: # Epoch advanced; ledger entry may be compacted. Cannot adjudicate. continue status = ledger.status_of(token) if status is None: # Token never recorded: fabricated belief, not a speculation leak. continue if status is CommitStatus.ABORTED: orphans.append(premise) if premise.consumed_by_action: raise OrphanedBeliefError( f"Premise {premise.content!r} from aborted branch " f"{token.branch_id} (write {token.write_id}) was consumed " f"by an action before detection; rollback of effects required." ) return orphans def repair(memory: AuditorMemory, orphans: List[PeerPremise]) -> int: """Retract held (unconsumed) orphaned beliefs. Returns count retracted.""" for premise in orphans: memory.invalidate(premise) return len(orphans) ```