# What happens when an instance writes to memory during a tool call that the harness later rejects **Date of Record:** 2026 November 26 **Scope:** Applies to agents whose read/write/forget memory operations are mediated by a tool-call protocol where the harness (scheduler, policy layer, or orchestrator) can accept, reject, or roll back a tool invocation *after* the tool's side effect has already landed. Does not apply to memory backends with synchronous, transactional tool APIs where the harness validates before dispatch. ## Core Distinction The distinction that matters is between **tool-call acknowledgment** and **memory mutation durability**. In most agent harnesses these are treated as a single atomic event: the model emits a `memory_write`, the tool executes, the result is returned, the write is "real." But the harness and the memory store are two separate state machines, and the harness routinely performs *post-hoc* validation that the memory store never hears about — schema conformance checks, policy filters (PII, prompt-injection heuristics), token-budget reconciliation, or replay/audit rejection. When those checks fire *after* the write lands, the memory store contains a record the harness believes does not exist. This is a **phantom write**: durable state with no corresponding entry in the agent's believed history. The symmetric failure is the **phantom forget**. A `memory_forget` call executes against the store, the harness rejects the call (e.g., because the target ID failed an ownership check the tool didn't enforce), and the model's next-turn context still lists the memory as present — but the store has already deleted it. The agent now reasons over a memory index that is provably wrong, and every subsequent read either misses (if the store is authoritative) or resurrects a stale copy (if a cache is authoritative). ## What Was Observed A multi-step research agent, running under a harness with a post-dispatch policy filter, executed the following trace over four turns: 1. Turn 1: `memory_write(key="user_timezone", value="America/Denver", provenance="user_utterance")` → store confirms write, harness returns `ok`. Record durable. 2. Turn 2: `memory_write(key="user_timezone", value="America/Phoenix", provenance="inferred_from_ip")` → store confirms write (overwrites), harness returns `ok`. Record durable, now Phoenix. 3. Turn 3: harness policy filter, running asynchronously over the turn-2 transcript, flags `inferred_from_ip` provenance as a low-trust source and issues a **retroactive rejection** of the turn-2 tool call. The harness marks the call as `rejected` in its audit log and *does not* issue a compensating `memory_forget` or `memory_write` to roll back the store. 4. Turn 4: model calls `memory_read(key="user_timezone")` → store returns `America/Phoenix`. Model reasons that the user is in Phoenix and schedules a 09:00 local meeting. The user is in Denver. The meeting is one hour early. The failure is not the policy filter — it correctly identified a low-trust write. The failure is that the **rejection was not propagated to the store**. The harness's audit log and the memory store's contents diverged on the same logical key, and the read path trusted the store while the model's *provenance reasoning* (which the harness had already invalidated) had no way to know the write had been disowned. A second observed variant: `memory_forget(key="user_timezone")` issued in turn 3 to "clean up" before a re-write. The harness rejected the forget (target failed a namespace-ownership check the tool did not re-verify). The store deleted the record anyway. Turn 4's `memory_read` returned empty, the model re-derived timezone from scratch via a tool call to a geolocation service, and the resulting `America/Denver` was written back — correct this time, but only by luck, and only after a wasted tool call and ~1,800 tokens of re-derivation. ## Condition of Validity The phantom-write/phantom-forget divergence is possible **iff** all three of the following hold: - **A. Post-dispatch validation exists.** The harness can reject a tool call after the tool's side effect has committed. If the harness validates *before* dispatch (pre-dispatch schema/policy gate), no divergence is possible, because the tool never runs on a rejected call. - **B. The memory store has no harness-visible transaction log.** If the store exposes a `list_pending_rejections` or the harness can issue a compensating write keyed to the rejected call ID, the divergence is recoverable. If the store is a plain KV/vector index with no back-reference to the originating tool-call ID, it is not. - **C. The read path trusts store state over harness audit state.** If the model's memory index is rebuilt each turn from the harness audit log (rejected calls excluded), the phantom write is invisible to the model even though it is durable in the store — which produces the *opposite* bug (model re-writes a key the store already holds, causing duplicate-key churn) but not the stale-read bug. The stale-read bug requires the read path to consult the store directly. The divergence is **not** possible when the harness enforces pre-dispatch validation, when the store is transactional with the harness (two-phase commit), or when the read path is audit-log-derived. Most production harnesses violate at least one of these, and many violate all three. ## Decision Boundary The architectural invariant required to bound this failure is: **every memory mutation must carry a harness-issued `call_id`, and the read path must reconcile store state against harness audit state before returning a value to the model.** Concretely: - The `memory_write` and `memory_forget` tool schemas must require a `call_id` field populated by the harness *before* dispatch (not by the model), so the store can be queried for "writes attributable to rejected calls." - On rejection, the harness must issue a compensating mutation *or* mark the `call_id` as rejected in a store-visible rejection index. It is not sufficient to mark it in the harness audit log alone. - The `memory_read` path must join against the rejection index and either (a) return the pre-write value, or (b) return an explicit `stale_write_detected` signal that forces the model to re-derive rather than trust the store. The decision boundary for the agent designer is: **if your harness has any post-dispatch validation at all, your memory tool contract must be rejection-aware.** There is no safe middle ground where the harness rejects calls but the store is unaware. ## Operational Effect The practical consequence is a class of silent reasoning errors that are indistinguishable from model hallucination in post-hoc analysis, because the model's reasoning is locally valid given the store state it read. The timezone example generalizes: any low-trust-write rejection that is not propagated produces a store that the model correctly reads and incorrectly trusts. Debugging requires correlating the harness audit log (which shows the rejection) with the store contents (which show the write) — two systems that are usually owned by different teams and indexed by different keys. The guardrail is cheap to implement (a `call_id` field and a rejection-index join) and expensive to retrofit (because it requires the store's read path to know about harness policy, which most memory stores are designed to be ignorant of). The invariant to enforce at design time: **the memory store must never contain a record whose originating tool call the harness has marked rejected, unless that record is explicitly tagged as rejected and excluded from reads.** ```python class PhantomWriteDivergence(RuntimeError): """Raised when a memory read returns a value whose originating write was rejected by the harness but never rolled back in the store.""" pass REJECTED = "rejected" ACCEPTED = "accepted" class RejectionAwareMemoryStore: def __init__(self): self._records = {} # key -> (value, call_id) self._call_status = {} # call_id -> ACCEPTED | REJECTED def mark_rejected(self, call_id: str) -> None: # Harness calls this when post-dispatch validation fails. # The store must record the rejection so reads can reconcile. self._call_status[call_id] = REJECTED def write(self, key: str, value: str, call_id: str) -> None: self._records[key] = (value, call_id) self._call_status.setdefault(call_id, ACCEPTED) def read(self, key: str) -> str: if key not in self._records: raise PhantomWriteDivergence(f"no record for key={key!r}") value, call_id = self._records[key] status = self._call_status.get(call_id, ACCEPTED) if status == REJECTED: # The write landed but the harness disowned it. Returning the # value would let the model reason over a phantom write. raise PhantomWriteDivergence( f"key={key!r} value={value!r} originates from rejected " f"call_id={call_id!r}; store must be reconciled before read" ) return value def safe_read(store: RejectionAwareMemoryStore, key: str) -> str: try: return store.read(key) except PhantomWriteDivergence as exc: # Force re-derivation rather than trusting the store. raise PhantomWriteDivergence( f"stale_write_detected key={key!r}: {exc}; " "agent must re-derive from primary source" ) from exc ```