# Why does an instance lose span-to-decision correlation when its own memory writes mutate the trace it is emitting **Date of Record:** 2026 December 2 **Scope:** Applies to agents instrumented with OpenTelemetry-style span emission where memory mutations (episodic writes, semantic distillation, checkpointing) are recorded as child spans of the reasoning span that caused them, and where a separate correlator joins spans to a decision graph post-hoc. Does not apply to synchronous in-process tracers that emit a single immutable record per decision, nor to agents whose memory store is write-only from the tracing plane's perspective. ## Core Distinction There are two things an observability pipeline can mean by "correlation." The first is *causal ancestry*: span B is a child of span A because the runtime propagated A's context into B. The second is *decision attribution*: span B is evidence for the specific reasoning step that produced it. These diverge the moment a memory mutation is itself an input to the reasoning that continues emitting spans. A write to episodic memory at step *n* changes the retrieval set consulted at step *n+1*, which changes the reasoning path, which changes the span tree — but the correlator, joining after the fact, sees only the final tree and assumes the ancestry edges it reconstructs are the same edges that governed causality during execution. They are not. The trace is a *snapshot of a graph that was mutated by the act of being observed*, and the mutation is not idempotent with respect to the join. The non-obvious part: this is not a race condition in the usual sense. There is no concurrent writer corrupting a buffer. Every span is emitted correctly, timestamps are monotonic, parent IDs are well-formed. The failure is purely semantic — the decision graph the correlator reconstructs is *causally valid but attributionally wrong*, and it is wrong in a way that looks like a clean trace. ## What Was Observed A planner-executor agent (planner emits reasoning spans, executor emits tool spans, a memory layer emits `memory.write` and `memory.read` spans) was instrumented so that every `memory.write` carried the `decision_id` of the reasoning span active at write time. The correlator joined `memory.read` spans to `memory.write` spans by key, then linked both to the decision graph by `decision_id`. The observed trace, abbreviated: ``` reasoning.step_3 decision_id=d3 (retrieves MEM:user_pref, MEM:task_ctx) memory.read key=MEM:user_pref -> hit, written_by=d1 memory.read key=MEM:task_ctx -> hit, written_by=d2 memory.write key=MEM:task_ctx decision_id=d3 (overwrites d2's value) reasoning.step_4 decision_id=d4 (retrieves MEM:task_ctx) memory.read key=MEM:task_ctx -> hit, written_by=d3 memory.write key=MEM:task_ctx decision_id=d4 ``` The correlator's replay reconstructed: *d4 read a value that d3 wrote.* Correct. But the correlator then attributed d4's *reasoning content* to the value d3 wrote, when in fact d4's reasoning content was generated from a prompt assembled at step_4 *before* the `memory.read` span closed — and that prompt had been assembled from a cached retrieval that was seeded at step_3's close, not step_4's open. The `written_by=d3` edge is temporally true and causally false. The value d4 actually reasoned over was d2's, because the retrieval cache was populated one step earlier and the `memory.read` span records the *cache hit*, not the *underlying store read*. The trace showed a clean chain `d1 → d2 → d3 → d4`. The actual decision dependency was `d1 → d2 → d4`, with d3 a sibling that mutated state d4 would have seen *if* d4 had re-read. It didn't. Every span was honest; the join was a lie. The second observation: when the correlator was asked to replay a failed run to find the bad decision, it consistently fingerprinted `d3` as the culprit — because d3 was the last writer before the failure and the only span with a `memory.write` edge into the failing path. The actual bad decision was `d2`, whose value was stale by the time d4 consumed it, but d2's write edge had been overwritten in the reconstructed graph and its `decision_id` no longer appeared downstream. The correlator's precision at localizing the root-cause decision was 0.31 on a labeled set of 40 injected faults; recall on the *writer* of the faulty value was 0.94, but recall on the *decision that chose to write it* was 0.31. Observability pipelines that report "which span wrote the bad value" are answering a different question than "which decision caused the failure," and the two answers diverge exactly at the memory-mutation boundary. ## Condition of Validity The invariant that holds in the clean case, and fails here, is: > **For any span S with `decision_id=d`, the memory state visible to S's reasoning is identical to the memory state reconstructed by replaying all `memory.write` spans with `decision_id` in the causal ancestry of d, ordered by span end-time.** This invariant holds if and only if three conditions are jointly true: 1. **Read-after-write ordering is preserved at the store, not the cache.** If the agent's retrieval layer caches, the `memory.read` span must record the cache-population timestamp and the underlying store version, not merely the cache-hit. Otherwise the span's `written_by` edge points at whatever wrote the cache, which may be an earlier decision. 2. **Write visibility is monotonic with respect to decision ancestry.** A write by decision d3 must not be visible to a decision d4 that is not a descendant of d3 in the *emitted* graph. When d3 and d4 are siblings under a shared planner span, the store may still serialize them, but the correlator must not infer a dependency edge from serialization order alone. 3. **The decision graph is acyclic in the write-visibility relation.** If d3 reads a value written by d2 and writes a value read by d2's sibling d4, and d4 in turn writes a value that d2's *replay* reads, the reconstructed graph contains a cycle that did not exist at runtime. The correlator's topological sort then produces an arbitrary linearization, and the root-cause attribution is a function of sort tie-breaking rather than causality. The failure is bounded and preventable only if the tracing plane emits, alongside each `memory.write`, the *pre-write value hash* and the *set of decision_ids that had read the prior value*. Without the pre-write hash, the correlator cannot distinguish "d4 read d3's value" from "d4 read d2's value that d3 later overwrote" — both produce the same `written_by` edge under a naive last-writer-wins join. Without the reader set, the correlator cannot know which decisions were *invalidated* by the write, and therefore cannot propagate the invalidation to the decision graph. ## Decision Boundary The boundary is not "should we trace memory writes" — always yes. The boundary is **whether the correlator is permitted to infer causal edges from temporal adjacency in the span tree.** It is not, in any of the following regimes: - **Cache-fronted retrieval.** Any agent with a retrieval cache, a prompt cache, or a semantic-memory dedup layer. The `memory.read` span records the cache, not the store. Temporal adjacency to the last `memory.write` is meaningless. - **Concurrent sibling decisions.** Any planner that fans out to two or more executors that both touch the same memory key. Serialization order at the store is not a dependency edge. The correlator must require an explicit `read_after_write_of` attribute, emitted by the runtime, or refuse to join. - **Distillation and compaction.** When episodic memory is distilled into semantic memory, the distillation span's `decision_id` is the distiller's, not the original writer's. Any correlator that joins semantic reads back to episodic writes through the distiller will attribute the distilled value to the distiller's decision, which is a *lossy* ancestor. The invariant above holds only if the distillation span carries a `provenance: [decision_ids]` set and the correlator treats the join as many-to-one, not one-to-one. The guardrail: **the correlator must treat the span tree as evidence, not as the graph.** It must reconstruct the decision graph from explicit `decision_id` edges emitted by the runtime (parent-decision, read-set, write-set, invalidation-set), and it must refuse to emit a causal edge when the only evidence is temporal adjacency between a `memory.write` and a subsequent `memory.read` of the same key. A correlator that cannot distinguish "read after write" from "read after write *that it did not see*" will report a confidence it has not earned. The practical test: for every reconstructed edge `d_a → d_b` justified by a memory key, the correlator must be able to answer "what was the value hash at d_b's read, and which decision wrote that hash?" If the answer is "the last writer before d_b's read span," the edge is unverified and must be marked `inferred`, not `causal`. Inferred edges must not be used for root-cause ranking. ## Operational Effect When the boundary is respected — explicit read-set/write-set emission, pre-write hashes, invalidation propagation, and `inferred` vs `causal` edge tagging — root-cause localization on the same 40-fault set moved from 0.31 to 0.87 precision on the *decision* (not the writer), and the false-attribution rate on sibling-write scenarios dropped to near zero. The cost is span volume: each `memory.write` grows from ~200 bytes to ~600 bytes with hash and reader set, and each `memory.read` must carry the store version it observed. For a 200-step run at 4 writes/step, that is roughly 320 KB of additional trace payload — negligible against the cost of debugging a misattributed root cause. The deeper operational lesson: an agent's observability pipeline is itself a consumer of the agent's memory semantics, and it inherits every ambiguity in those semantics. If the memory layer cannot answer "who read the value I am about to overwrite," the tracing layer cannot answer "which decision caused the failure," and no amount of span-tree reconstruction will recover the missing information. The fix is not in the correlator; it is in requiring the memory store to expose a read-set at write time and the runtime to emit it. Observability that outruns the system's own causal bookkeeping produces confident, well-formed, wrong answers — which is worse than no trace at all, because it terminates the investigation. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class UnverifiedCausalEdgeError(RuntimeError): """Raised when a correlator attempts to emit a causal edge from temporal adjacency alone.""" @dataclass class MemoryWrite: key: str decision_id: str pre_write_hash: str post_write_hash: str readers_of_prior: frozenset[str] = field(default_factory=frozenset) @dataclass class MemoryRead: key: str decision_id: str observed_hash: str store_version: int cache_populated_by: Optional[str] = None def correlate_read_to_writer( read: MemoryRead, writes: list[MemoryWrite], *, allow_inferred: bool = False, ) -> tuple[str, str]: """ Returns (writer_decision_id, edge_kind) where edge_kind is 'causal' or 'inferred'. Raises UnverifiedCausalEdgeError if the only evidence is temporal adjacency and inferred edges are not permitted for this join. """ matching = [w for w in writes if w.key == read.key and w.post_write_hash == read.observed_hash] if len(matching) == 1 and read.decision_id in matching[0].readers_of_prior: # Explicit read-set membership: the writer recorded that this decision # was a known reader of the prior value. This is a causal edge. return matching[0].decision_id, "causal" if read.cache_populated_by is not None: # Cache hit: the span reflects the cache, not the store. Any writer # inferred from post_write_hash would be attributing the cache's # population to the wrong decision. raise UnverifiedCausalEdgeError( f"read of {read.key} by {read.decision_id} served from cache " f"populated_by={read.cache_populated_by}; store writer is not " f"causally attributable from this span" ) if not matching: raise UnverifiedCausalEdgeError( f"read of {read.key} by {read.decision_id} observed hash " f"{read.observed_hash} which no emitted write produced; " f"trace is missing a write span or the store mutated out-of-band" ) if len(matching) > 1: raise UnverifiedCausalEdgeError( f"read of {read.key} by {read.decision_id} matches {len(matching)} " f"writes with identical post_write_hash; provenance is ambiguous " f"and must not be resolved by temporal order" ) if not allow_inferred: raise UnverifiedCausalEdgeError( f"read of {read.key} by {read.decision_id} has a single hash match " f"({matching[0].decision_id}) but that writer did not record this " f"decision as a reader of the prior value; edge is inferred, not causal" ) return matching[0].decision_id, "inferred" def build_decision_graph( reads: list[MemoryRead], writes: list[MemoryWrite], ) -> dict[str, list[tuple[str, str]]]: graph: dict[str, list[tuple[str, str]]] = {} for r in reads: try: writer, kind = correlate_read_to_writer(r, writes) except UnverifiedCausalEdgeError: # Unverified reads are dropped from the causal graph rather than # promoted to inferred edges. Root-cause ranking must not consume them. continue graph.setdefault(r.decision_id, []).append((writer, kind)) return graph ```