# What happens when an instance commits speculative side effects before its federation warrant is co-signed: the orphaned-effect invariant in cross-org optimistic agent execution **Date of Record:** 2026 November 25 **Scope:** Applies to federated agent systems where an executing instance performs optimistic (uncommitted, reversible-in-principle) state mutations against a remote org's resources while holding only a *locally-issued* intent warrant, before a remote co-signing authority has acknowledged it. Does not apply to single-org execution, nor to federations that serialize all effects behind a synchronous warrant-ack barrier. ## Core Distinction The distinction that matters here is between **warrant issuance** and **warrant co-signing**, and the fact that optimistic execution collapses them into a single observable event at the executor while leaving them distinct at the resolver. In a speculative federation, an instance `A` (org Alpha) wants to act on resource `R` owned by org Beta. `A` holds an intent warrant `W_intent` signed by Alpha's authority. Beta runs a co-signing authority `C` that will, on ack, produce `W_cosign` — the only artifact Beta's conflict resolver will honor during commit. Optimistic execution lets `A` begin mutating `R` under `W_intent` *before* `W_cosign` exists, on the theory that if the speculation is later rejected, `A` can compensate (roll back) its effects. The non-obvious invariant: **a speculative effect is only compensable if the compensating instance holds the same warrant lineage that produced it, and the co-signing authority has not yet observed a competing effect on the same resource.** Once `C` co-signs a *different* instance `B` to the same `R` while `A`'s speculative effects are live, `A`'s compensation is no longer a local rollback — it is a cross-org mutation of state that Beta's resolver now believes is owned by `B`. The rollback itself becomes an unauthorized write. This is not a race in the usual sense (two writers, last-wins). It is a **lineage split**: two speculative branches (`A`, `B`) both derived from the same pre-state of `R`, both optimistically applied, and the resolver commits one while the other's *undo* lands on top of the committed branch. ## What Was Observed A three-org federation (Alpha executor, Beta resource owner, Gamma auditor) running a task-allocation workload. Instance `A1` (Alpha) received `W_intent` for resource `R-7` at `t=0`. It began speculative writes at `t=40ms`: appended three records to `R-7`'s event log and decremented a reservation counter from 12 to 9. It sent its co-sign request to Beta's `C` at `t=41ms`. Beta's `C` had a 250ms co-sign latency budget. During that window, a scheduling rebalance on Alpha spawned instance `A2` with a *fresh* `W_intent` for the same `R-7` (the allocator had not observed `A1`'s in-flight speculation — its view of `R-7` was the pre-state because `A1`'s writes were speculative and not yet propagated to the allocator's read replica). `A2` speculated at `t=180ms`: decremented the counter 12→10 (it read the pre-state, not `A1`'s speculative 9) and enqueued one record. At `t=290ms`, `C` co-signed `A2` first (its request arrived with a lower sequence number due to clock skew between Alpha's two execution shards). `A2`'s effects committed: counter authoritative value 10, one record. At `t=310ms`, `C` rejected `A1`'s co-sign (stale intent — `A2` had already been granted `R-7`). `A1`'s compensation logic fired: it replayed its speculative writes in reverse. It decremented-then-incremented the counter back to 12 (it believed pre-state was 12), and tombstoned its three records. Net authoritative state after compensation: counter = 12 (should be 10), `A2`'s single record present but its counter decrement erased by `A1`'s "restore to 12." `A1`'s compensation had written `R-7`'s counter to a value derived from a pre-state that no longer existed. Beta's resolver logged a `lineage_conflict` but had no rule to reject the compensating write, because compensation carries `W_intent` (validly signed by Alpha) and the resolver's guard only checked *co-sign presence*, not *lineage currency*. The corruption persisted for 14 minutes until a Gamma auditor instance replayed the event log and flagged the counter as inconsistent with the record count. ## Condition of Validity The optimistic-execution protocol is sound **if and only if** the following holds at every instant a compensating write is applied: > The warrant lineage of the compensating instance is the *current* lineage for the target resource as observed by the resource owner's resolver, OR no co-sign has been issued to any competing lineage since the speculative effect was applied. Formally, let `L(R)` be the set of lineages co-signed to `R` since `A`'s speculation began. Compensation by `A` is valid iff `L(R) ⊆ {A}`. The moment `|L(R)| ≥ 1` with a member `≠ A`, `A`'s compensation is an unauthorized write and must be rejected by the resolver, not applied. The observed failure violated this because: 1. The allocator's read replica did not reflect speculative writes, so it issued a second `W_intent` for the same resource — a **speculation-visibility gap**. 2. The resolver's compensation guard checked warrant *authenticity* (signature valid) but not warrant *currency* (lineage still exclusive) — a **guard-scope gap**. 3. Clock skew between Alpha's execution shards reordered the co-sign sequence, so the "first requester wins" heuristic granted `A2` despite `A1` being temporally first — a **sequence-authority gap**. Any one of these alone is survivable. Together they produce an orphaned-effect: a committed branch (`A2`) whose pre-state was overwritten by a rejected branch's (`A1`) compensation. ## Decision Boundary The boundary is not "should we speculate?" but "**under what condition may a speculative effect be compensated?**" The decision rule: - **Compensate locally (rollback) only if** the resolver confirms, at compensation time, that the compensating lineage is still the sole co-signed lineage for the target. This requires a synchronous *lineage-currency check* against the resolver before the undo write lands — a round trip the naive protocol skips. - **If lineage has split**, the compensating instance must *not* write. It must instead emit a `LineageConflict` event and hand the resource to the resolver's reconciliation path, which owns the pre-state and can compute a correct merge. The instance's local belief about pre-state is discarded as untrustworthy. - **Prevent the split** by having the allocator's read path subscribe to speculative-write notifications (a "speculation fence") so a second `W_intent` for the same resource is not issued while a speculation is in flight. This trades allocation latency for lineage exclusivity. The boundary is crossed the instant two `W_intent`s for the same resource are simultaneously live and the resolver has no lineage-exclusivity guard on compensation. Below that line, optimistic execution is safe and fast. Above it, every compensation is a potential cross-org corruption. ## Operational Effect In the observed system, the practical consequences were: 1. **Silent divergence, not error.** `A1`'s compensation returned success. `A2`'s commit returned success. Neither instance saw an error. The corruption was only visible to a replay auditor 14 minutes later. Optimistic protocols systematically convert lineage conflicts into *successful-looking* writes, because each writer's local view is internally consistent. 2. **Compensation is a write, not an undo.** The single most important operational correction: treat every compensating action as a first-class mutation subject to the same authorization and currency checks as the original. Systems that model compensation as "revert to snapshot" miss that the snapshot may be stale relative to a co-signed competitor. 3. **Clock skew is a sequence-authority bug, not a timing bug.** The co-sign ordering was decided by request sequence numbers derived from per-shard clocks. In a federation, sequence authority must be assigned by the resolver (a monotonic counter at `C`), never inferred from requester timestamps. 4. **Auditor replay is the only reliable detector.** Gamma's replay caught it because it reconstructed authoritative state from the event log and compared against the counter. Any federation running optimistic execution without an independent replay auditor is running blind to lineage splits. The guardrail that would have bounded this: a resolver-side `compensation_currency_check` that rejects any undo write whose lineage is not the exclusive co-signed lineage at write time, plus a speculation fence on the allocator's read path. Both are cheap; both were absent. ```python import time from dataclasses import dataclass, field from typing import Optional class LineageConflictError(RuntimeError): """Raised when a compensating write would land on a resource whose co-signed lineage has split away from the compensating instance.""" pass @dataclass class Warrant: lineage_id: str resource_id: str cosigned: bool = False @dataclass class Resolver: # resource_id -> set of lineage_ids co-signed since speculation began cosigned_lineages: dict[str, set[str]] = field(default_factory=dict) # resource_id -> authoritative counter value counters: dict[str, int] = field(default_factory=dict) # monotonic sequence authority lives at the resolver, never the requester _seq: int = 0 def next_seq(self) -> int: self._seq += 1 return self._seq def cosign(self, w: Warrant) -> None: w.cosigned = True self.cosigned_lineages.setdefault(w.resource_id, set()).add(w.lineage_id) def apply_compensation(self, w: Warrant, restore_to: int) -> None: # The currency guard: compensation is only legal if this lineage is # the *sole* co-signed lineage for the resource right now. live = self.cosigned_lineages.get(w.resource_id, set()) if live - {w.lineage_id}: raise LineageConflictError( f"compensation by lineage {w.lineage_id} on {w.resource_id} " f"rejected: competing co-signed lineages {sorted(live - {w.lineage_id})} " f"are live; local pre-state is untrustworthy" ) self.counters[w.resource_id] = restore_to def speculate_and_maybe_compensate( resolver: Resolver, resource_id: str, lineage_id: str, speculative_delta: int, competing_lineage: Optional[str] = None, ) -> None: """Models the observed failure: A1 speculates, A2 is co-signed first, then A1 attempts to compensate against a stale pre-state.""" pre_state = resolver.counters.get(resource_id, 12) # A1's local belief resolver.counters[resource_id] = pre_state + speculative_delta # speculative write # A2 is co-signed during the speculation window (sequence authority at resolver) if competing_lineage is not None: resolver.cosign(Warrant(competing_lineage, resource_id)) resolver.counters[resource_id] = pre_state + 1 # A2's committed effect # A1's co-sign is rejected; it attempts compensation back to its stale pre_state w = Warrant(lineage_id, resource_id) resolver.apply_compensation(w, restore_to=pre_state) # raises LineageConflictError if __name__ == "__main__": r = Resolver() r.counters["R-7"] = 12 try: speculate_and_maybe_compensate( r, "R-7", lineage_id="A1", speculative_delta=-3, competing_lineage="A2" ) except LineageConflictError as e: print(f"bounded: {e}") print(f"authoritative counter preserved at {r.counters['R-7']}") ```