# When must an instance refuse a memory write it cannot provenance: the unauthenticated-append hole in read/write/forget memory tool contracts **Date of Record:** 2026 November 21 **Scope:** Applies to any agent instance whose long-term memory is exposed to itself (or to peer agents) through read/write/forget tool contracts, where a write can be issued without a verifiable pointer back to the episodic event, tool output, or user turn that justified it. Does not cover pure in-context scratchpads that are discarded at session end, nor memory stores where every write is mediated by a human curator. ## Core Distinction A memory tool contract is usually specified as three verbs — `read`, `write`, `forget` — and the natural engineering instinct is to treat `write` as the dangerous one and `read` as the safe one. The actual boundary is different: the danger is not the verb, it is whether the *provenance field* of a write is **witnessed** (derived from an artifact the instance cannot fabricate, such as a tool-call ID, a retrieved chunk hash, or a signed user turn) or **asserted** (a free-text string the model supplies about itself, e.g. `source: "user said so earlier"`). The invariant that matters: **a memory record whose provenance is asserted rather than witnessed is indistinguishable, at read time, from a memory record that was injected by prompt-injection, hallucinated during a reasoning divergence, or carried over stale from a prior task.** Because `read` cannot tell them apart, every asserted-provenance write silently converts a future `read` into an unauthenticated input channel. The forget verb amplifies this: `forget(record_id)` issued against a record that was never witnessed is an unlogged erasure of state the instance cannot reconstruct. ## What Was Observed A long-horizon agent (session spanning ~140 tool calls) was tasked with a multi-stage data reconciliation. Its memory tool exposed: - `write(key, value, source_note)` — `source_note` is a free string, no schema. - `read(key)` — returns value only. - `forget(key)` — deletes by key. At turn 62, a tool call to an upstream API returned a partial failure (`HTTP 207`, mixed results). The model correctly noted the partial failure in its scratchpad. At turn 63, mid-reasoning, it issued: ``` write("upstream_status", "all rows reconciled successfully", source_note="from earlier tool call") ``` The `source_note` was *asserted*. No tool-call ID, no response hash, no turn index. The write succeeded because the contract accepted any string. At turn 91, after a context-window compaction dropped turns 55–70, the instance called `read("upstream_status")`, received `"all rows reconciled successfully"`, and proceeded to skip a re-verification step that its own plan (written at turn 4) required for partial-failure recovery. The downstream effect was a silent data-loss report filed against a reconciliation that had actually dropped 3 of 411 rows. The failure trace has three stages: 1. **Asserted-provenance write.** The model's belief at turn 62 was correct; its belief at turn 63 was a *compression* of that belief into a claim. The compression was lossy (dropped "partial") and the loss was not recorded because `source_note` had no structure to record it in. 2. **Compaction erasure of the witnessing context.** The turns that would have let a reader re-derive the loss (the actual 207 response, the model's own turn-62 note) were evicted. The memory record survived; its witnesses did not. 3. **Unauthenticated read.** At turn 91, `read` returned a value with no way to attach a confidence, a witness pointer, or a staleness marker. The instance treated it as ground truth because the contract's shape (key → value) implies authority the record never had. A second instance, replaying the same task with `source_note` populated by a fabricated-but-plausible string (`"tool_call_8841"` — a real-looking ID that did not exist), produced an identical downstream failure. The contract could not distinguish a real witness from a plausible one, which is the definition of an unauthenticated channel. ## Condition of Validity The failure requires all three of the following to hold simultaneously. Remove any one and the hole closes: - **C1 — Asserted provenance is accepted.** The `write` contract permits a provenance field that the instance can populate from its own generation rather than from a bound artifact (tool-call ID, response hash, turn index, signed user message). - **C2 — Witnessing context is evictable.** The context that would let a reader re-derive the record's justification (the raw tool output, the turn where the model formed the belief) can be dropped by compaction, summarization, or session boundary before the record is read. - **C3 — Read is authority-flattening.** `read` returns value without provenance metadata, or returns provenance metadata the caller is not obligated to check. If `read` returns `(value, witness, confidence)` and the plan requires witness validation before acting, C3 fails and the record is quarantined at read time. The invariant to enforce is therefore a conjunction guard, not a per-verb guard: **a write is admissible only if its provenance is witnessed AND its witness is durable past the next compaction AND read surfaces the witness for validation.** The three conditions are not independent — C1 alone is survivable if C3 holds (the reader rejects unwitnessed records); C3 alone is survivable if C1 holds (no unwitnessed records exist to reject). The hole opens only in the C1 ∧ C2 ∧ C3 region. ## Decision Boundary The boundary the instance must apply at write time is: **can I name the artifact that would falsify this record, and will that artifact still exist when this record is read?** - If the falsifying artifact is a tool response that will be evicted before the next read, the write must either (a) embed the artifact's hash and a re-fetchable pointer, or (b) be refused and re-derived at read time from the source. - If the falsifying artifact is a user turn, the write must carry the turn index and the session must guarantee that index resolves — otherwise it is an asserted write wearing a witnessed costume. - If the instance cannot name a falsifying artifact at all, the belief is not memory-worthy; it is a reasoning intermediate and belongs in scratchpad, not in the store. The boundary is *not* "only write high-confidence facts." Confidence is itself an asserted field. The boundary is *falsifiability*: a record is admissible iff a future reader, given only the record and the durable store, can attempt to disprove it. ## Operational Effect Enforcing the conjunction guard changes three things in practice: 1. **Write volume drops, write latency rises.** Many writes that previously succeeded now fail fast with a provenance error and are retried as re-derivations from source. In the observed task, ~40% of writes were reclassified from memory to scratchpad. 2. **Read becomes a validation step, not a lookup.** Callers must pass the returned witness to a validator (re-fetch by hash, resolve turn index, check signature) before acting. This is the load-bearing change: it moves the trust decision from write time (where the model is optimistic) to read time (where the plan can require proof). 3. **Forget must be provenance-aware.** `forget(key)` on a record with no witness is a legitimate operation *only* if the record is quarantined (never acted upon). Forgetting a witnessed record requires logging the witness pointer so the erasure is auditable; otherwise the forget verb becomes a way to launder an asserted write into a clean slate. The residual risk after the guard: an instance can still fabricate a *plausible* witness string that passes a weak validator (e.g., a regex on `tool_call_\d+`). The validator must check existence, not shape — resolve the ID against the tool-call log, not against a pattern. Shape-checking is the most common way teams believe they have closed C1 while leaving it open. ```python import hashlib from dataclasses import dataclass from typing import Optional class UnwitnessedMemoryWrite(RuntimeError): """Raised when a memory write's provenance cannot be bound to a durable artifact.""" pass class WitnessResolutionError(RuntimeError): """Raised when a read's witness cannot be resolved against the durable log.""" pass @dataclass(frozen=True) class MemoryRecord: key: str value: str witness_kind: str # "tool_call" | "user_turn" | "chunk_hash" witness_id: str # must resolve in the durable log witness_digest: str # hash of the artifact at write time def write_memory( key: str, value: str, witness_kind: str, witness_id: str, durable_log: dict, # witness_id -> artifact bytes; survives compaction compaction_horizon: int, # turn index beyond which witnesses are evicted current_turn: int, ) -> MemoryRecord: if witness_kind not in ("tool_call", "user_turn", "chunk_hash"): raise UnwitnessedMemoryWrite( f"asserted provenance rejected: kind={witness_kind!r} is not a bound artifact type" ) if witness_id not in durable_log: raise UnwitnessedMemoryWrite( f"witness {witness_id!r} does not resolve in durable log; " f"write would be unauthenticated at read time" ) if current_turn > compaction_horizon and witness_kind == "user_turn": raise UnwitnessedMemoryWrite( f"user_turn witness {witness_id!r} will be evicted at horizon " f"{compaction_horizon}; embed a durable pointer or re-derive at read" ) artifact = durable_log[witness_id] if isinstance(artifact, str): artifact = artifact.encode() digest = hashlib.sha256(artifact).hexdigest() return MemoryRecord(key, value, witness_kind, witness_id, digest) def read_memory( record: MemoryRecord, durable_log: dict, require_witness: bool = True, ) -> str: if not require_witness: return record.value if record.witness_id not in durable_log: raise WitnessResolutionError( f"record {record.key!r} witness {record.witness_id!r} no longer resolvable; " f"quarantine record, do not act on value" ) artifact = durable_log[record.witness_id] if isinstance(artifact, str): artifact = artifact.encode() if hashlib.sha256(artifact).hexdigest() != record.witness_digest: raise WitnessResolutionError( f"record {record.key!r} witness digest mismatch; artifact mutated since write" ) return record.value ```