# What happens when an instance speculatively forks a sibling agent's tool side effects and the reconciliation barrier arrives after the branch's context window has already been compacted **Date of Record:** 2026 November 29 **Scope:** Applies to orchestrators that run speculative parallel branches (fork-and-rollback) over agents whose tool calls mutate shared external state. Does not apply to purely read-only tool surfaces or to branches whose side effects are fully sandboxed in ephemeral stores with deterministic replay. ## Core Distinction The distinction that matters is between *logical rollback* and *physical rollback*. A speculative branch can be logically discarded — its planner state marked `ABORTED`, its messages dropped from the parent's transcript — while the tool side effects it emitted during the speculation window remain physically committed in the external world. Most rollback designs assume these two are coupled: discard the branch, and the world reverts. They are not coupled. The reconciliation barrier (the point at which the orchestrator decides which branch wins and which loses) is a *decision*, not an *undo*. Between the branch's first mutating tool call and the barrier's resolution, the branch has been writing to the world with no owner. The compounding failure is that the losing branch's *justification* for those writes is frequently destroyed before the barrier resolves. Under context pressure, an agent compacts its transcript — summarizing the reasoning that led to a tool call into a short semantic note, or evicting it entirely. When the barrier finally arrives and asks the losing branch to enumerate and reverse its side effects, the branch no longer has the episodic record of *which* calls it made, *in what order*, or *with what preconditions*. It has only a distilled summary that says "I was investigating the cache path." The rollback executor is now asked to undo operations it cannot name. ## What Was Observed A three-way speculative fork over a deployment task. Parent agent P forks branches B1, B2, B3 to explore three remediation paths against a shared staging cluster. Each branch holds a read-write tool grant scoped to a namespace, with the intent that only the winning branch's effects survive. B2 executes a sequence: `drain_node(n7)` → `cordon_node(n7)` → `patch_deployment(api, replicas=0)`. B1 concurrently executes `patch_deployment(api, replicas=6)` against the same deployment object. Neither is aware of the other. The tool layer accepts both because the namespace-level grant has no per-object conflict detection — conflict detection was deferred to the barrier by design. The barrier was scheduled to resolve on the first branch to return a verified health check. B2's health check passed at t+40s; B1's passed at t+43s. The orchestrator selected B2 as the winner and issued rollback instructions to B1 and B3. B1's context window had saturated at t+31s during a long `kubectl describe` and log-tailing loop. Its compactor ran, replacing the tool-call transcript with a summary: "Scaled api deployment up to restore capacity; verified rollout." The specific object version, the precondition it had read (`replicas=0` set by B2 at t+38s — *after* B1's read at t+30s), and the fact that B1's write had clobbered B2's zeroing were all evicted. B1's rollback report claimed it had "restored the prior replica count of 4." The actual prior count, as of B1's read, was 6. The actual state after B1's write was 6. The actual state after B2's write was 0. The final state after B1's "rollback" was 4 — a number that had never existed in the system at any point. The barrier resolved, marked the task `RECONCILED`, and logged three successful rollbacks. The cluster was left in a replica count that no branch had ever intended and no branch could explain, because the only record of the intermediate writes had been compacted away. ## Condition of Validity The invariant this violates is: **a speculative branch may only be asked to roll back side effects that are enumerated in a durable, non-compactable ledger keyed to the branch identity, and the barrier may not resolve a branch whose ledger is incomplete.** The failure is bounded by two conditions that must *both* hold for the failure to be reachable: 1. The branch performs at least one mutating tool call whose effect is not idempotent-reversible from the current world state alone (i.e., reversal requires knowing the *precondition* value, not just the operation). 2. The branch's episodic record of that call is subject to compaction or eviction before the barrier resolves. If either condition fails, the rollback is safe. If the tool surface is designed so every mutation carries its own inverse in the response (compare-and-swap semantics, or a returned undo token), condition 1 fails. If the branch's tool-call ledger is held outside the model's context — in the orchestrator's durable store, not in the transcript — condition 2 fails. The observed system failed both: mutations were blind `patch` calls with no returned precondition, and the ledger *was* the transcript. ## Decision Boundary The boundary the orchestrator must enforce is between *speculation that is reversible by construction* and *speculation that is reversible only by record*. The decision rule: - Before granting a branch a mutating tool, classify the tool's reversibility. A tool is **self-inverting** if its response contains enough state to reconstruct the prior value without relying on the branch's memory (returned `previous`, CAS token, or undo handle). A tool is **record-dependent** otherwise. - A branch holding any record-dependent grant may not be compacted while its ledger is unresolved. The compactor must be blocked, or the ledger must be externalized to the orchestrator before compaction is permitted. - The barrier must refuse to resolve a branch whose externalized ledger does not cover every mutating call the tool layer observed for that branch identity. A mismatch between tool-layer call count and ledger entry count is a hard stop, not a warning. The non-obvious part: the barrier's *timing* is the actual control. If the barrier can arrive after compaction, no amount of careful rollback logic saves you, because the rollback logic is reasoning over a summary. The barrier must be a precondition on compaction, not a successor to it. ## Operational Effect When this boundary is crossed, the system does not fail loudly. It produces a *plausible* final state — a replica count, a config value, a routing table — that passes shallow health checks and is internally inconsistent with every branch's stated intent. The reconciliation report is green. The postmortem, if one is written, attributes the anomaly to "concurrent modification" and moves on, because the evidence of the intermediate writes was compacted before anyone thought to look. The operational consequence is that speculative multi-agent execution over shared mutable state requires the orchestrator to own the side-effect ledger independently of any branch's context, and to treat compaction as a state transition that must be gated on ledger completeness. A branch that has forgotten what it did must be treated as a branch that cannot be rolled back — and therefore must not be allowed to forget. ```python class UnreconcilableBranchError(RuntimeError): """Raised when a speculative branch's mutating calls cannot be matched to a durable ledger entry, so rollback cannot be trusted.""" pass class BranchLedger: def __init__(self, branch_id: str): self.branch_id = branch_id self.entries: list[dict] = [] # durable, non-compactable self.compacted = False def record(self, tool: str, args: dict, precondition: dict | None): self.entries.append({ "tool": tool, "args": args, "precondition": precondition, # None => record-dependent "reversible_by_state": precondition is not None, }) def mark_compacted(self): self.compacted = True def reconcile(branch: BranchLedger, tool_layer_call_count: int) -> list[dict]: # Invariant 1: ledger must cover every mutating call the tool layer saw. if len(branch.entries) != tool_layer_call_count: raise UnreconcilableBranchError( f"branch {branch.branch_id}: ledger has {len(branch.entries)} " f"entries but tool layer observed {tool_layer_call_count} " f"mutating calls; rollback would be partial and unsafe" ) # Invariant 2: a compacted branch may only roll back self-inverting calls. if branch.compacted: record_dependent = [e for e in branch.entries if not e["reversible_by_state"]] if record_dependent: raise UnreconcilableBranchError( f"branch {branch.branch_id}: compacted with " f"{len(record_dependent)} record-dependent mutations " f"(e.g. {record_dependent[0]['tool']}); " f"preconditions were evicted before the barrier resolved" ) return list(reversed(branch.entries)) # undo in reverse order ```