# When must an instance abort a speculative memory write after a tool-call conflict resolves in its favor **Date of Record:** 2026 November 25 **Scope:** Applies to agents that speculatively execute tool calls and stage speculative memory writes against a shared episodic/semantic store before the tool call's authoritative result is confirmed. Does not apply to read-only speculative retrieval, nor to single-writer stores with no concurrent reconcilers. ## Core Distinction The common framing treats speculative execution as a latency optimization: fire a tool call early, stage the presumed side effect, and either commit or discard based on the confirmed result. The hidden invariant is different. A *speculative memory write* is not a value that gets committed or rolled back — it is a **claim on a memory key that other agents may have already read**. The distinction that governs correctness is between **arbitration** (which writer wins the key) and **observability** (which readers already consumed the losing value). Conflict resolution only settles arbitration. It says nothing about the readers who read the speculative value during the speculation window. The failure mode: a speculative write loses the arbitration race, a reconciler rolls it back, and the instance concludes it has "cleanly aborted." But between staging and rollback, a peer agent read the staged value, distilled it into its own semantic memory, and now holds a belief derived from a write that never happened. The instance that *lost* the conflict is not the one that is corrupted — the *reader* is. And the losing writer is the only party positioned to know the read could have happened. This is the non-obvious boundary: **an instance must sometimes act on a write it successfully aborted**, because aborting the write does not abort its causal effects. ## What Was Observed A planner agent (`P`) speculatively called a `reserve_inventory` tool for SKU `A-4471`, staging a write `stock[A-4471].reserved += 40` into the shared episodic store at logical clock `t=1180` while the tool call was still in flight. A second agent (`Q`) independently staged `stock[A-4471].reserved += 15` at `t=1183`. The store used last-writer-wins on staged writes with a reconciler that, on tool confirmation, arbitrated by earliest confirmed tool timestamp. `Q`'s tool confirmed first. The reconciler committed `Q`'s delta, rolled back `P`'s staged value, and emitted a standard `SPECULATION_ABORTED` event to `P`. `P` logged a clean abort and continued. What the reconciler did not track: at `t=1181`, between `P`'s staging and `Q`'s, an auditor agent (`A`) had read `stock[A-4471].reserved` to validate a downstream shipment plan. `A` read the value *including* `P`'s 40 units. `A` had no way to distinguish a staged speculative value from a committed one — the store exposed a single read path. `A` distilled "4471 has 40 units of headroom" into its semantic layer at `t=1190`, after the rollback had already completed. The shipment plan proceeded against 40 units that were never reserved. The conflict resolved correctly by every metric the reconciler measured. The system was wrong anyway. The trace of the failure is short and entirely within the speculation window: ``` t=1180 P stages reserved+=40 (uncommitted, visible to reads) t=1181 A reads reserved (sees P's staged value) t=1183 Q stages reserved+=15 t=1185 Q's tool confirms; reconciler commits Q, rolls back P t=1185 P receives SPECULATION_ABORTED, logs clean abort t=1190 A distills "40 units headroom" into semantic memory <-- corruption lands here ``` The abort at `t=1185` was correct. The corruption at `t=1190` was already in flight. `P`'s abort handler had no mechanism to retract a value that had already been read, and no obligation was assigned to notify readers. The reconciler's `SPECULATION_ABORTED` event was addressed to the writer, not to the readers. ## Condition of Validity The invariant fails precisely when three conditions co-hold: 1. **Speculative writes are reader-visible before arbitration.** If staged writes are isolated (MVCC snapshot, per-agent overlay, or a `speculative` flag that reads must explicitly opt into), readers cannot consume them and the invariant is vacuous. The failure requires a read path that does not distinguish staged from committed. 2. **The speculation window overlaps at least one reader's read.** A window that closes before any peer reads is safe regardless of arbitration outcome. Window length is a function of tool-call latency, not of the agent's reasoning — so this condition is governed by transport, not by the planner. 3. **The losing writer's abort is treated as terminal for that writer.** If the abort handler is the last thing `P` does with the key, the derived-reader corruption is never surfaced. The invariant holds — the system remains correct — only if the abort path *escalates* rather than *terminates*. When any of the three is absent, a plain rollback is sufficient and the escalation described below is wasted work. The decision of whether to escalate is therefore a function of store read-visibility semantics, not of the conflict itself. ## Decision Boundary The boundary is not "did I lose the conflict." It is **"could a reader have observed my staged value before rollback, and did the store give me a way to enumerate or invalidate those readers?"** Formally, on receiving `SPECULATION_ABORTED` for key `k` staged at `t_stage` and rolled back at `t_rollback`, the instance must escalate — emit a `SPECULATION_READ_INVALIDATION` scoped to `k` over `[t_stage, t_rollback]` — if and only if the store's read path was reader-visible during that interval. If the store exposes a read-audit log or a staged-value marker, the instance can enumerate affected readers and target the invalidation. If it cannot enumerate, it must broadcast a conservative invalidation over the window and accept false positives (readers who read the committed value, not the speculative one). The trap is the instance that reasons "I lost, therefore my write is irrelevant, therefore I do nothing." Losing arbitration makes the write irrelevant *to the key*. It does not make the write irrelevant *to anyone who read it*. The losing writer is the only agent that knows both the staging timestamp and the rollback timestamp — the two endpoints of the contamination window. The winning writer (`Q`) has no reason to look, and the reader (`A`) has no way to know it read something that would later be retracted. Responsibility for the invalidation is structurally pinned to the loser. There is a second, sharper boundary: **an instance must not re-speculate on the same key after an abort without first confirming the invalidation was consumed.** Re-staging after a rollback, while prior readers still hold the retracted value, compounds the contamination window and makes the read-audit log ambiguous (two overlapping windows on one key). The guardrail is a per-key speculation epoch: the instance may not open a new speculative window on `k` until the prior window's invalidation has been acknowledged by the store's reader set or has aged out past the store's maximum read-staleness bound. ## Operational Effect The practical consequence is that speculative execution is not a local optimization with local rollback. It is a **broadcast of tentative belief**, and every tentative belief carries an obligation to retract. Systems that model speculation as writer-local (stage/commit/abort) will pass every arbitration test and still corrupt downstream reasoning, because the corruption lands in agents that were never part of the conflict. The architectural guardrail is one of two, chosen by store capability: - **Isolation (preferred):** staged writes are not reader-visible until commit. Reads see only committed values. The speculation window is invisible to peers, and rollback is genuinely local. This requires the store to carry a per-reader snapshot or a `visibility=committed` default on the read path. It costs read latency and snapshot retention. - **Invalidation (fallback):** staged writes are reader-visible, but the store maintains a read-audit log keyed by `(key, timestamp)`, and the abort path is *required* to emit a scoped invalidation that the reconciler fans out to logged readers. This costs log volume and a fan-out path on every abort, and it requires readers to honor invalidation messages by re-reading or downgrading derived beliefs. What must not be built is the middle case that was observed: reader-visible staged writes with writer-addressed abort events and no read-audit. That configuration is correct under arbitration and silently wrong under observation, and it fails only when a reader happens to fall inside the speculation window — which is exactly the condition that speculative execution was introduced to create. The invariant, stated once: **the obligation to retract a speculative write is proportional to its reader-visibility, not to its arbitration outcome; the losing writer is the only party that knows the contamination window and therefore the only party that can close it.** ```python import time from dataclasses import dataclass, field class SpeculationRetractionError(RuntimeError): """Raised when a losing speculator fails to close its reader-visibility window.""" pass @dataclass class SpeculativeWindow: key: str staged_at: float reader_visible: bool readers_observed: list = field(default_factory=list) invalidated: bool = False class SpeculationLedger: """Tracks speculative windows and enforces the retraction invariant on abort.""" def __init__(self, store_read_audit_enabled: bool): self._audit = store_read_audit_enabled self._windows: dict[str, SpeculativeWindow] = {} self._open_epochs: dict[str, int] = {} def open(self, key: str, reader_visible: bool) -> SpeculativeWindow: if key in self._open_epochs: raise SpeculationRetractionError( f"cannot re-speculate on {key!r}: prior window not yet retracted" ) w = SpeculativeWindow(key=key, staged_at=time.monotonic(), reader_visible=reader_visible) self._windows[key] = w self._open_epochs[key] = 1 return w def record_read(self, key: str, reader_id: str) -> None: w = self._windows.get(key) if w and w.reader_visible: w.readers_observed.append(reader_id) def abort(self, key: str, rolled_back_at: float) -> None: w = self._windows.get(key) if w is None: raise SpeculationRetractionError(f"abort for unknown window {key!r}") if not w.reader_visible: # Isolation path: rollback is genuinely local, no fan-out needed. w.invalidated = True self._close(key) return if not self._audit and not w.readers_observed: # Reader-visible but unenumerable: must broadcast conservatively. # Refuse to silently close — the window is unbounded. raise SpeculationRetractionError( f"abort on reader-visible key {key!r} during " f"[{w.staged_at:.3f},{rolled_back_at:.3f}] with no read audit; " f"cannot enumerate affected readers, must broadcast invalidation" ) # Enumerable: emit scoped invalidation to observed readers. if not w.readers_observed: raise SpeculationRetractionError( f"abort on {key!r} with audit enabled but zero readers logged; " f"audit log likely stale, treat window as contaminated" ) w.invalidated = True self._close(key) def _close(self, key: str) -> None: self._open_epochs.pop(key, None) self._windows.pop(key, None) ```