# When must an instance reconcile a scoped memory write against the retrieval index it will later read from **Date of Record:** 2026 November 30 **Scope:** Applies to agents whose memory is exposed as explicit tool calls (`memory.write`, `memory.read`, `memory.forget`) with namespace/scope keys and a separate retrieval-augmented recall path (embedding index, BM25, or hybrid). Does not apply to monolithic context-window stuffing where write and read share the same substrate, nor to write-only audit logs that are never queried by the agent itself. ## Core Distinction The failure is not "the write failed." It is that a *successful* scoped write and a *successful* scoped read can disagree about what exists, because the write path and the retrieval path are two different consistency domains joined by an asynchronous, lossy projection. A `memory.write(scope="proj-7", key="deploy_target", value="staging-eu")` that returns `{"ok": true}` attests only that the authoritative record landed in the scoped store. It does *not* attest that the record is retrievable. The retrieval index is a derived projection: it embeds the value, tokenizes it, assigns it to a vector cell, and updates postings. That projection lags, can drop, and — critically — can be *shadowed* by a prior record for the same key that has not yet been evicted from the index. The dangerous invariant is this: **for a given `(scope, key)`, the record returned by `memory.read` must be the record most recently acknowledged by `memory.write` in that same scope, or the read must fail loudly.** Any agent that treats `write ok` as `read will reflect this` is operating outside that invariant without knowing it. ## What Was Observed An agent executing a multi-turn remediation task wrote a corrective fact mid-task: ``` memory.write(scope="incident-4412", key="root_cause", value="pool exhaustion, not DNS") → {"ok": true, "version": 3} ``` Two tool calls later it performed a recall to confirm its own reasoning: ``` memory.read(scope="incident-4412", query="what is the root cause") → [{"key": "root_cause", "value": "DNS resolution failure", "version": 2}] ``` Version 2 was returned. Version 3 had been acknowledged. The retrieval projection had not yet re-embedded the new value; the old vector for `root_cause` still occupied the nearest cell for the query, and the read path returned the *stale* version because it ranked by vector similarity and the stale embedding was a closer match to the query string than the un-indexed new value. The agent, trusting recall over its own write, re-derived a DNS hypothesis and issued a rollback of the wrong subsystem. The trace shows the exact seam: `write` returned at T+0 with version 3 durably committed. The indexer's re-embedding job for that scope completed at T+840ms. The read at T+310ms landed in the gap. No error was raised at any layer — both calls were individually correct. A second, subtler variant appeared under `forget`. An agent called `memory.forget(scope="incident-4412", key="root_cause")` to retract a superseded hypothesis, received `{"ok": true}`, then continued reasoning. A later recall within the same task still surfaced the forgotten value, because `forget` removed the authoritative record but the tombstone had not propagated to the vector index; the orphaned embedding remained queryable. The agent re-adopted a fact it had explicitly retracted. ## Condition of Validity The reconcile-on-read guardrail is *required* whenever all three hold: 1. **Split substrate.** The authoritative store and the retrieval index are distinct systems joined by an asynchronous projection (typical for any RAG-backed memory tool). 2. **Intra-task write-then-read.** The agent reads back a key it wrote or forgot *within the same task execution*, before the projection's staleness window has provably elapsed. 3. **Self-trusting recall.** The agent treats recall output as ground truth for its own prior actions rather than as a hint to be cross-checked. It is *not* required when reads only ever target keys written in prior, completed tasks (the projection has settled), or when the memory tool exposes a synchronous read-your-writes mode and the agent is contractually pinned to it. The guardrail is also unnecessary — but the *hazard* remains — when the agent never reads its own writes; that configuration merely relocates the risk to downstream consumers. ## Decision Boundary The boundary is between two policies: - **Trust-recall:** read returns whatever the index ranks highest; agent proceeds. Cheap, and correct only outside the staleness window. - **Reconcile-on-read:** for any `(scope, key)` the agent has written or forgotten in the current task, the agent maintains a local write-set and, on recall, *overrides* index results for those keys with its own acknowledged version, or rejects the recall if the returned version is older than its last acknowledged write. The reconcile policy must be scoped, not global. Reconciling every key against a task-local ledger would defeat the purpose of external memory — the agent would be trusting its own context over the store, reintroducing context-window saturation. Reconcile only the keys in the current task's write-set; everything else is read from the index on its merits. The write-set is small (bounded by writes per task) and is the only region where the agent has first-hand knowledge that outranks the projection. The decision rule: **if `read.version < write_ack.version` for a key in the write-set, the read is stale and must not be trusted; if the key is in the forget-set and still appears, the forget has not propagated and the value must be suppressed.** Version comparison, not value comparison — the value may be legitimately reformatted by the indexer, but the version monotonicity is the invariant that survives projection. ## Operational Effect Enforcing reconcile-on-read converts a silent divergence into a bounded, observable condition. The agent either proceeds on its own acknowledged state (correct by construction for the keys it wrote) or raises, forcing a retry after the projection settles. The cost is a small task-local ledger and a version check per recall — negligible against the cost of acting on a retracted root cause. The deeper operational lesson: a memory tool's `ok` is a statement about *durability*, never about *visibility*. Agents that conflate the two will, at some non-zero rate, contradict themselves mid-task and rationalize the contradiction as new information. The reconcile guardrail is the only thing standing between "I wrote the correction" and "I believe the thing I corrected." ```python from dataclasses import dataclass, field from typing import Optional class StaleRecallError(RuntimeError): """Raised when a recall returns a version older than the agent's acknowledged write, or surfaces a key the agent has forgotten in the current task scope.""" pass @dataclass class WriteSet: """Task-local ledger of acknowledged writes and forgets, keyed by (scope, key).""" written: dict[tuple[str, str], int] = field(default_factory=dict) # -> acked version forgotten: set[tuple[str, str]] = field(default_factory=set) def record_write(self, scope: str, key: str, acked_version: int) -> None: self.written[(scope, key)] = acked_version self.forgotten.discard((scope, key)) def record_forget(self, scope: str, key: str) -> None: self.forgotten.add((scope, key)) self.written.pop((scope, key), None) def reconcile_recall(scope: str, results: list[dict], ledger: WriteSet) -> list[dict]: """Filter recall results against the task-local write-set. - Drop any key the agent has forgotten this task (tombstone not yet propagated). - For any key the agent wrote this task, require the returned version to be >= the acknowledged version; otherwise the projection is stale. """ reconciled: list[dict] = [] for hit in results: k = (scope, hit["key"]) if k in ledger.forgotten: # Forget acknowledged but index still serves the orphaned embedding. continue acked: Optional[int] = ledger.written.get(k) if acked is not None and hit.get("version", -1) < acked: raise StaleRecallError( f"recall for {k} returned version {hit.get('version')} " f"< acknowledged write version {acked}; projection has not settled" ) reconciled.append(hit) return reconciled ```