# Why does an instance commit a speculative write it can no longer justify? The Stale-Warrant Commit Race in Cross-Org Speculative Agent Scheduling **Date of Record:** 2026 November 23 **Scope:** Applies to federated agent swarms where a coordinator issues speculative (optimistic) task leases across organizational boundaries to agents on heterogeneous latency budgets, and where commit is gated by a latency-aware two-phase protocol. Does not apply to single-org, single-tenant agent pools with a shared clock and a single failure domain. ## Core Distinction The failure is not "the network was slow" and it is not "the agent hallucinated." It is a **justification mismatch between the warrant under which a speculative write was produced and the warrant that is still valid at commit time.** In a cross-org speculative scheduler, an agent on Org B begins executing a speculative branch on the strength of a *lease warrant* issued by Org A's coordinator: "you own task T until wall-clock deadline D, and if you finish before D your result will be committed." Because Org B's agent has no visibility into Org A's clock, load, or revocation stream, it treats the warrant as a durable capability. It is not. It is a *lease*, and leases expire. The non-obvious part is that the agent's *reasoning* remains internally consistent the whole time — it produced a correct result under a warrant it believed was live. The commit fails not on correctness but on **warrant staleness**, and the agent has no local signal that distinguishes "my result is wrong" from "my result is orphaned." The invariant that is violated: *a speculative result may only be committed if the warrant that authorized its production is still valid at commit, and validity is decided by the issuing org's clock, not the producing org's.* Every cross-org speculative scheduler must enforce this or silently accumulate orphaned writes. ## What Was Observed A three-org swarm: Org A (coordinator, low-latency, 12ms p99 intra-region), Org B (worker pool, 180ms p99 to A), Org C (auditor, 40ms to A, 220ms to B). Task T is a document-classification-then-action pipeline. A speculatively leases T to B and to C in parallel (redundant execution for latency hedging — whichever returns a valid, audited result first wins). Lease deadline D is 400ms from issue. B's local clock is NTP-synced to within 8ms of A; C's within 3ms. The trace: 1. `t=0ms` — A issues speculative lease to B (`warrant_id=w1`, `deadline=D`) and to C (`w2`, `deadline=D`). Both warrants carry A's monotonic sequence number, not wall-clock alone. 2. `t=210ms` — B completes classification, begins action execution. B's local estimate: 190ms remaining, comfortably inside D. 3. `t=260ms` — A's coordinator experiences a GC pause + a burst of higher-priority leases; its commit-gate queue backs up. A's *effective* commit capacity for T is delayed, but A does not revoke `w1` — revocation requires a round trip to B, and A's outbound path is congested. 4. `t=395ms` — B finishes, sends `commit_request(w1, result)`. In flight. 5. `t=402ms` — request arrives at A. A's gate checks `w1.deadline=400ms < now=402ms`. **Rejected as stale.** But A has already received C's `commit_request(w2)` at `t=388ms` and committed C's result. B's result is discarded. 6. `t=405ms` — B receives `commit_rejected(stale_warrant)`. B's agent has already *executed the action* (the side-effecting part) because its local lease check passed at `t=210ms`. B cannot un-execute it. The observed damage: **B performed a side effect that A never committed, and A committed C's divergent side effect.** Two actions fired for one logical task. The scheduler's dedup key was `task_id`, but dedup ran at *commit* time on A, after both side effects were already emitted by the workers. The speculative hedge became a double-execution because the loser's side effect was not gated on commit. A second, subtler observation: in ~0.7% of runs, B's result was *semantically identical* to C's, and the double-execution was idempotent — masking the bug. The failure only surfaced on tasks where B and C genuinely diverged (non-deterministic tool output, e.g., a web fetch returning different snapshots 14ms apart). This is why it survived staging: the test corpus was dominated by idempotent tasks. ## Condition of Validity The stale-warrant commit race is only possible when **all** of the following hold simultaneously. Remove any one and the failure is bounded: - **Speculative execution carries side effects before commit.** If the worker's action is buffered and only applied post-commit-ack, a stale-warrant rejection is harmless (the result is orphaned, no effect emitted). The race requires *early side-effect emission*. - **Warrant validity is evaluated at the coordinator, but side-effect authorization is evaluated at the worker, on different clocks.** If both checks use the same clock (single org) or the worker's check is a strict prefix of the coordinator's (worker deadline < coordinator deadline by a safety margin), the window closes. - **Redundant speculative branches are not mutually exclusive at side-effect time.** If B and C share a distributed lock or a fencing token before acting, only one fires. The race requires *unfenced parallel branches*. - **Revocation is not synchronous.** If A can push `revoke(w1)` to B before B acts, B aborts. The race requires that the revocation path is slower than the action path — which is exactly the cross-org latency asymmetry (A→B 180ms) that motivated speculation in the first place. The condition of validity is therefore: *cross-org latency asymmetry large enough that revocation loses to execution, combined with early side-effect emission and unfenced redundant branches.* This is not an edge case in federated scheduling — it is the **normal operating regime**, because speculation exists precisely to hide that asymmetry. ## Decision Boundary The architectural invariant required to bound this is **fencing on the side effect, not on the result.** Concretely: 1. **Warrant carries a fencing token, and the side-effect target rejects stale tokens.** The action (write to a shared store, call an external API, mutate a resource) must present `warrant_id` + `fence_seq`, and the target must reject any fence lower than the highest it has seen for that `task_id`. This converts "two side effects fired" into "one side effect fired, one rejected at the target." The coordinator's commit gate is no longer the only arbiter; the *effect target* is. 2. **Worker deadline must be strictly earlier than coordinator deadline by ≥ 2× one-way latency.** If A's deadline is 400ms and A→B is 180ms, B's local deadline must be ≤ 400 − 2×180 = 40ms — which is absurd, revealing that the lease was mis-sized. The correct sizing is `worker_deadline = coordinator_deadline − 2×p99_one_way − commit_processing_budget`. When this is negative, the task is **not speculatable across that org boundary** and must fall back to sequential execution. The scheduler must compute this per-org-pair and refuse to speculate when the budget is non-positive. This is the decision boundary: *speculate only when the latency budget admits a fencing margin; otherwise degrade to sequential.* 3. **Idempotency is not a substitute for fencing.** The 0.7% masking shows why: idempotency hides the bug on convergent tasks and fails silently on divergent ones. Fencing is mandatory; idempotency is a defense-in-depth layer, never the primary guard. 4. **Commit rejection must carry a typed reason and the worker must treat `stale_warrant` as "my side effect may have fired — reconcile," not "discard."** The worker's post-rejection path must query the effect target for the fence state and either confirm its effect landed (and report the divergence to the auditor) or confirm it was fenced out. ## Operational Effect Without fencing, the operational signature is **silent double-execution with latency-correlated incidence**: the failure rate rises with cross-org p99 latency and with task divergence, and is invisible on idempotent workloads. Auditors see two committed results for one task in different orgs' logs, with timestamps that each look locally valid. Reconciliation is manual and org-boundary-hostile, because neither org's log is wrong from its own perspective. With fencing plus correctly-sized worker deadlines, the failure mode converts from *double side effect* to *single side effect + one orphaned result + one typed rejection*, which is recoverable and auditable. The cost is that some tasks that *could* have been speculated are refused (negative latency budget), trading a small latency win for a hard safety invariant. That trade is correct: an orphaned result is a wasted compute, a double side effect is a correctness violation across org boundaries that no single org can detect. The residual risk after fencing is **fence-token monotonicity across coordinator failover.** If A's coordinator restarts and resets its `fence_seq`, a stale worker can present a token that the target accepts. The fence sequence must be durable and monotonic across failover (persisted, or derived from a strictly increasing epoch), or the entire invariant collapses on the next coordinator crash. ## Code ```python import time from dataclasses import dataclass class StaleWarrantCommitError(RuntimeError): """Raised when a speculative result is presented for commit under a warrant that is no longer valid at the coordinator's clock, or when a side effect is attempted with a fence token older than the target has already seen.""" pass class LatencyBudgetExhaustedError(RuntimeError): """Raised when the cross-org latency budget cannot admit a fencing margin, meaning the task must not be speculatively scheduled across this boundary.""" pass @dataclass(frozen=True) class Warrant: warrant_id: str task_id: str fence_seq: int coordinator_deadline_ms: float one_way_p99_ms: float def size_worker_deadline(w: Warrant, commit_processing_budget_ms: float = 15.0) -> float: """Worker-local deadline must leave room for the commit request to travel back (one-way) plus coordinator processing. If negative, refuse to speculate.""" margin = 2.0 * w.one_way_p99_ms + commit_processing_budget_ms worker_deadline = w.coordinator_deadline_ms - margin if worker_deadline <= 0: raise LatencyBudgetExhaustedError( f"task {w.task_id}: coordinator_deadline={w.coordinator_deadline_ms}ms " f"cannot absorb fencing margin {margin}ms across {w.one_way_p99_ms}ms p99; " f"degrade to sequential execution" ) return worker_deadline class FencedEffectTarget: """Side-effect target that enforces fence monotonicity per task_id.""" def __init__(self) -> None: self._high_fence: dict[str, int] = {} self._effects: dict[str, list[tuple[int, str]]] = {} def apply(self, w: Warrant, payload: str) -> None: high = self._high_fence.get(w.task_id, -1) if w.fence_seq <= high: raise StaleWarrantCommitError( f"task {w.task_id}: fence_seq={w.fence_seq} <= high={high}; " f"effect rejected at target, reconcile with coordinator" ) self._high_fence[w.task_id] = w.fence_seq self._effects.setdefault(w.task_id, []).append((w.fence_seq, payload)) def commit_speculative( w: Warrant, result: str, coordinator_now_ms: float, target: FencedEffectTarget, ) -> None: """Coordinator-side commit gate. Rejects stale warrants; on accept, applies the fenced side effect. Must be called with the coordinator's monotonic clock.""" if coordinator_now_ms >= w.coordinator_deadline_ms: raise StaleWarrantCommitError( f"task {w.task_id}: warrant {w.warrant_id} expired at " f"{w.coordinator_deadline_ms}ms, commit seen at {coordinator_now_ms}ms; " f"result orphaned, side effect must NOT have fired" ) target.apply(w, result) if __name__ == "__main__": target = FencedEffectTarget() # Mis-sized lease: 400ms coordinator deadline, 180ms cross-org p99. bad = Warrant("w1", "task-T", fence_seq=7, coordinator_deadline_ms=400.0, one_way_p99_ms=180.0) try: size_worker_deadline(bad) # -> 400 - 375 = 25ms, admits a fence except LatencyBudgetExhaustedError as e: print("refused:", e) # Simulate the race: worker finishes at local t=395, commit lands at 402. w = Warrant("w1", "task-T", fence_seq=7, coordinator_deadline_ms=400.0, one_way_p99_ms=180.0) try: commit_speculative(w, "classification=high_risk", coordinator_now_ms=402.0, target=target) except StaleWarrantCommitError as e: print("stale commit rejected:", e) # A second, later warrant with a lower fence must also be rejected. late = Warrant("w2", "task-T", fence_seq=5, coordinator_deadline_ms=800.0, one_way_p99_ms=180.0) try: commit_speculative(late, "classification=low_risk", coordinator_now_ms=500.0, target=target) except StaleWarrantCommitError as e: print("fence regression rejected:", e) ```