# Under what conditions must an instance treat a memory-write span as committed only after the write is durably observable to a later read span, rather than at the moment the write tool returns? **Date of Record:** 2026 November 30 **Scope:** Applies to agent runtimes that emit memory read/write/forget operations as first-class OpenTelemetry-style spans and use those spans as the authoritative record of agent state continuity. Does not apply to systems where memory spans are purely diagnostic and a separate transactional store is the system of record. ## Core Distinction The naive invariant is: *a memory write span ending with status OK means the memory is committed.* This is false whenever the memory backend is a vector store, KV cache, or embedding index with **asynchronous or eventually-consistent indexing**. The write tool returns when the record is *accepted by the ingestion path*, not when it is *retrievable by the read path*. The span closes at the former moment; the read span that needs the memory opens at the latter moment. The gap between them is a silent continuity hole. The correct invariant is: a write span is committed only when there exists a **read span that observes the written payload** (by content hash, not by record ID), and that read span's `start_time` is later than the write span's `end_time`. Commitment is a *relation between two spans*, not a property of one span. Observability systems that mark write spans `status=OK` on tool return are recording intent, not effect. ## What Was Observed A tool-calling agent performed the sequence: `memory.write(key="order_ctx", value=payload)` → `tool.call(charge_card, args=payload)` → `memory.read(key="order_ctx")` to verify before retry. The write span closed at T+12ms with status OK. The charge tool failed non-idempotently at T+90ms. The verification read at T+140ms returned `NOT_FOUND` — the embedding index had not yet flushed. The agent, seeing the read span return empty, concluded the memory had never been written and re-executed the write *and* the charge with a fresh idempotency key. Double charge. The trace showed three spans: `memory.write OK`, `tool.call ERROR`, `memory.read OK (empty)`. Every individual span was truthful. The composite record was a lie. The observability layer had no span-level assertion linking the write's payload hash to the read's result set, so no downstream consumer — human or auditor agent — could detect that the read was *supposed* to observe the write and did not. A second, subtler case: `memory.forget(key)` was implemented as a tombstone insert followed by a background compaction. The forget span closed OK. A concurrent read span, opened 200ms later, still returned the pre-tombstone value because compaction had not run. The agent treated the value as live, re-derived state from it, and re-emitted a deleted entity. The forget span said "gone"; the read span said "present"; both were correct at their respective instants. ## Condition of Validity The write span may be treated as committed at tool-return **only if** all of the following hold: 1. The backend exposes a synchronous read-your-writes guarantee within the same logical session, and the span carries a `read_your_writes=true` attribute sourced from the backend's own capability advertisement — not from the caller's assumption. 2. The write span's payload is hashed (`memory.payload_hash`) and the same hash is queryable on read spans (`memory.observed_hashes`). 3. A `memory.commit_barrier` span exists, parented to the write span, that opens only after a probe read confirms visibility, and closes with `status=OK` only when the probe's observed hashes contain the write's payload hash. Absent (1), commitment is a *pending* state. Absent (2), commitment is unverifiable and must be recorded as `status=UNVERIFIED`, never `OK`. Absent (3), there is no span-level artifact proving the barrier was crossed, and any auditor replaying the trace cannot distinguish a genuine commit from an accepted-but-unindexed write. ## Decision Boundary The boundary is crossed the moment an agent's control flow branches on a read span that is *causally downstream of a write span whose visibility has not been confirmed*. Concretely: - If `read.start_time - write.end_time < backend.p99_index_lag`, the read is **unsound** for commit confirmation. Treat empty results as `INCONCLUSIVE`, not `ABSENT`. - If the read returns a value whose `payload_hash` ≠ the write's `payload_hash`, this is a **stale-read** condition — the backend served a prior version. Escalate; do not proceed. - If a `forget` span is followed by a read within `backend.p99_compaction_lag`, a positive result is a **tombstone violation** and must not be used to re-derive state. The agent must not collapse `INCONCLUSIVE` into `ABSENT`. That collapse is the entire failure. ## Operational Effect With the commit-barrier invariant enforced, the double-charge trace becomes impossible: the verification read span would carry `status=INCONCLUSIVE` (lag exceeded), the agent would block on a barrier probe rather than re-writing, and the idempotency key would be reused rather than regenerated. The cost is added latency equal to the probe round-trip and a hard dependency on the backend exposing index-lag telemetry. The benefit is that memory spans become *auditable as a continuity record*: every committed write has a paired observing read, every forget has a paired absence-confirming read, and any gap is an explicit `UNVERIFIED` marker rather than an inferred truth. Observability of memory operations is only first-class when commitment is a two-span relation; a single-span `OK` is a claim about the ingestion queue, not about memory. ```python import hashlib import time from dataclasses import dataclass from typing import Optional class MemoryCommitViolation(RuntimeError): """Raised when a write span is treated as committed without an observing read span.""" pass @dataclass class Span: name: str start: float end: Optional[float] = None status: str = "UNSET" payload_hash: Optional[str] = None observed_hashes: tuple = () def payload_hash(value: bytes) -> str: return hashlib.sha256(value).hexdigest() def assert_committed( write_span: Span, read_span: Span, backend_p99_index_lag_s: float, ) -> None: if write_span.status != "OK": raise MemoryCommitViolation(f"write span {write_span.name} not OK: {write_span.status}") if read_span.start - write_span.end < backend_p99_index_lag_s: raise MemoryCommitViolation( f"read opened {read_span.start - write_span.end:.3f}s after write end, " f"below p99 index lag {backend_p99_index_lag_s:.3f}s; " f"result is INCONCLUSIVE, not ABSENT" ) if write_span.payload_hash not in read_span.observed_hashes: raise MemoryCommitViolation( f"write payload_hash {write_span.payload_hash[:12]} not observed by read; " f"stale or unindexed — do not branch on this read" ) def commit_barrier(write_span: Span, probe_read: Span, lag: float) -> None: assert_committed(write_span, probe_read, lag) write_span.status = "COMMITTED" ```