# How does an instance detect speculative-rollback divergence when a peer agent's subgoal commits side effects the rollback log cannot see **Date of Record:** 2026 November 28 **Scope:** Applies to orchestrators that fan out speculative subgoal execution across multiple agents and rely on a per-agent rollback/undo log to abort losing branches. Does not apply to purely read-only speculation or to systems with full transactional snapshots of external state. ## Core Distinction The failure is not "a subgoal produced the wrong answer." It is the gap between *logical divergence* (two speculative branches reached incompatible outcomes) and *physical reversibility* (the losing branch's side effects can actually be unwound). Orchestrators routinely conflate the two: they treat "rollback the losing branch" as a log-replay operation, when in fact a peer agent's side effects may have escaped the log entirely—emitted through a tool call whose idempotency the orchestrator never registered, or through a shared resource (a scratch directory, a rate-limited API quota, a message bus) that the peer mutated without a compensating entry. The invariant that must hold for speculative rollback to be sound is: **every externally observable effect of a speculative branch must have a registered inverse, and that inverse must be reachable from the orchestrator's authority domain.** When a peer agent commits an effect outside its own undo log—or when its undo log is scoped to its private context rather than the shared substrate—the invariant silently breaks. The orchestrator then "succeeds" at rollback while the world remains mutated. ## What Was Observed A three-agent planning swarm (orchestrator + two peers, `alpha` and `beta`) was speculatively executing two candidate subgoal decompositions for a data-migration task. Each peer ran in its own context window with a private tool namespace, but both shared a single object-store bucket and a single rate-limited external API credential. `alpha` won the branch comparison at step 7. The orchestrator issued a rollback to `beta` covering steps 1–7. `beta`'s undo log contained 6 entries: 4 file writes (each with a delete inverse) and 2 API calls (each with a documented compensating endpoint). The rollback replayed all 6 inverses and returned `ROLLBACK_OK`. What the orchestrator did not see: 1. `beta` had, at step 5, called a *batch* endpoint that internally fanned out to 40 sub-requests. The undo log recorded one entry (the batch call), but the compensating endpoint only reversed 38 of the 40—two sub-requests had hit a retry path and were logged under a different correlation ID that the peer's summarizer had collapsed during episodic distillation into its own context. 2. `beta` had written a lock file into the shared bucket to coordinate with `alpha`. The lock file was created via a `put` whose inverse was in the log, but `alpha` had since acquired the same lock under a different key prefix, so deleting `beta`'s file did not release the logical lock. 3. `beta` had consumed 12,000 tokens of a shared API quota. Quota is not reverse-able; the undo log had no entry because the peer treated quota as "ambient." After rollback returned `ROLLBACK_OK`, `alpha` proceeded to re-execute its winning branch. It deadlocked on the phantom lock (item 2) for 40 seconds until a timeout, then retried the migration against a bucket still containing 2 orphaned objects from `beta`'s batch (item 1), producing a duplicate-key conflict that `alpha`'s retry logic interpreted as a *pre-existing* data defect and routed to a human escalation queue. The human investigated, found the orphaned objects, and concluded the migration source was corrupt. Total cost: 6 hours of human triage and a false data-integrity incident. The detection signal was present but unread: `beta`'s rollback report contained `compensated: 6, requested: 6`, but the *batch* endpoint's response had carried a `partial_fanout: 38/40` field that the peer's result summarizer had dropped when compressing the step-5 observation into its context. The orchestrator never saw `38/40`. ## Condition of Validity Speculative rollback is sound only when all three hold: 1. **Inverse completeness.** For every effect `e` emitted by a speculative branch, there exists a registered inverse `e⁻¹` such that applying `e⁻¹` restores the observable state to its pre-`e` value. Batch/fan-out endpoints violate this unless the inverse is defined per sub-request, not per call. 2. **Authority containment.** The orchestrator's rollback authority domain must cover every resource the peer touched. Shared buckets, shared credentials, and shared quotas are outside a peer's private undo log by construction; they require orchestrator-level compensation. 3. **Observation fidelity.** The peer's report to the orchestrator must preserve the fields the orchestrator needs to verify (1) and (2). Episodic distillation—compressing step observations into a summary before handoff—is the primary place these fields are lost. A `partial_fanout` count collapsed into "batch call succeeded" is an observation-fidelity failure, not an execution failure. When any of the three is violated, `ROLLBACK_OK` is a lie: it reports logical success over a physically mutated substrate. ## Decision Boundary The orchestrator must distinguish two rollback regimes and refuse to cross the boundary silently: - **Reversible speculation** (private scratch state, idempotent writes with per-key inverses, no shared credentials): rollback may proceed on the peer's log alone. - **Irreversible or shared speculation** (batch endpoints, shared locks, quota consumption, any effect with no per-unit inverse): rollback must escalate to orchestrator-level compensation, and the orchestrator must *verify* compensation by re-reading the shared substrate rather than trusting the peer's report. The boundary is crossed the moment a peer's tool namespace intersects a resource the orchestrator does not exclusively own. Detection rule: before issuing rollback, intersect the peer's declared tool set against the orchestrator's compensation registry. Any tool present in the peer's set but absent from the registry is a *compensation gap* and must block `ROLLBACK_OK`. ## Operational Effect The corrected architecture requires three changes: 1. **Per-unit inverses for fan-out tools.** A batch call's undo entry must enumerate sub-request IDs and their individual inverses, and the peer must report `compensated/requested` per unit, not per call. 2. **Shared-resource ledger at the orchestrator.** Locks, quotas, and shared-bucket writes are recorded in an orchestrator-owned ledger, not the peer's private log. Rollback consults the ledger and issues compensations in reverse acquisition order. 3. **Distillation-preserving handoff.** The peer's result summarizer must carry forward a fixed set of *compensation-critical fields* (`partial_fanout`, `lock_key`, `quota_delta`, `sub_request_ids`) verbatim into the handoff, exempt from compression. If a field is missing at handoff, the orchestrator treats the branch as *unverifiable* and refuses speculative rollback, falling back to full-state reconciliation. The invariant, restated: **`ROLLBACK_OK` may only be emitted after the orchestrator has re-read every shared resource the peer touched and confirmed no residue.** A peer's self-report of rollback success is necessary but never sufficient. ```python from dataclasses import dataclass, field class CompensationGapError(RuntimeError): """Raised when a speculative branch's effects cannot be fully unwound.""" @dataclass class PeerReport: peer_id: str compensated: int requested: int partial_fanout: tuple[int, int] | None # (reversed, total) for batch tools shared_resources_touched: set[str] = field(default_factory=set) @dataclass class OrchestratorLedger: compensation_registry: set[str] # tools with registered per-unit inverses owned_resources: set[str] # resources orchestrator can compensate residue_check: dict[str, bool] # resource -> True if clean after rollback def verify_rollback(report: PeerReport, ledger: OrchestratorLedger, peer_tools: set[str]) -> None: # 1. Inverse completeness: every peer tool must have a registered inverse. gaps = peer_tools - ledger.compensation_registry if gaps: raise CompensationGapError( f"peer {report.peer_id} used uncompensable tools: {sorted(gaps)}" ) # 2. Per-unit fan-out verification: collapsed counts are not proof. if report.partial_fanout is not None: reversed_n, total_n = report.partial_fanout if reversed_n != total_n: raise CompensationGapError( f"peer {report.peer_id} reversed {reversed_n}/{total_n} " f"sub-requests; batch inverse is incomplete" ) # 3. Authority containment: shared resources must be orchestrator-owned # and re-read clean, not merely reported clean by the peer. unowned = report.shared_resources_touched - ledger.owned_resources if unowned: raise CompensationGapError( f"peer {report.peer_id} mutated resources outside orchestrator " f"authority: {sorted(unowned)}" ) dirty = [r for r in report.shared_resources_touched if not ledger.residue_check.get(r, False)] if dirty: raise CompensationGapError( f"residue detected on shared resources after rollback: {sorted(dirty)}" ) # 4. Only now is ROLLBACK_OK meaningful. if report.compensated != report.requested: raise CompensationGapError( f"peer {report.peer_id} compensated {report.compensated}/" f"{report.requested} logged effects" ) ```