# Under what conditions must an instance treat a memory mutation as an unobservable span: causal-orphan reordering in GenAI observability pipelines correlating prompts, tool calls, and memory mutations **Date of Record:** 2026 November 27 **Scope:** Applies to agent runtimes that emit prompt spans, tool-call spans, and memory-mutation spans to an asynchronous collector that reconstructs causal traces by parent-span linkage and timestamp ordering. Does not apply to single-process synchronous tracing where the mutation write and its span emission are in the same transactional boundary. ## Core Distinction The distinction that governs this entire failure class is between a memory mutation that is *causally emitted* (the span is created inside the transaction that commits the write) and one that is *observationally reconstructed* (the collector infers the mutation's existence and ordering from a prompt span that references the mutated state). The first is a fact. The second is an inference, and the inference is only valid when the collector can prove the mutation span was not dropped, delayed, or reordered relative to the prompt span that depends on it. Most observability pipelines implicitly assume prompt spans, tool-call spans, and memory-mutation spans share a monotonic clock and a reliable delivery channel. They do not. A memory mutation span is frequently the *last* span emitted by an agent turn because the write is the final act, and it is frequently the *first* span dropped under backpressure because the collector's per-trace buffer evicts on arrival order. When a mutation span is dropped but its dependent prompt span survives, the collector silently attributes the mutated state to whatever prompt span precedes it in timestamp order — an operation the agent never performed. ## What Was Observed A retrieval-augmented agent executed a turn in which it (1) called a `memory.write` tool to persist a corrected user preference, then (2) called `memory.read` in a subsequent reasoning step and received the corrected value. The collector received the prompt span for step 2, the tool-call span for the `memory.read`, and the tool-call span for the `memory.write` — but the `memory.write` span arrived 340ms late due to a retry in the span exporter, after the collector had already closed the trace's causal window on a 250ms idle timeout. The collector's correlation logic was: for each tool-call span, find the nearest preceding prompt span by timestamp and attribute the call to it. Because the mutation span arrived after the trace window closed, it was appended as a late-arriving orphan and *re-attributed to the next trace's first prompt span*. The result: the corrected preference was recorded in the observability store as having been written by a *different agent instance* in a *different session*, and the original turn's trace showed a `memory.read` returning a value with no corresponding write — a "phantom read" that a downstream auditor flagged as a possible memory-poisoning event. The failure is not the late span. The failure is the *re-attribution*. The collector had no invariant preventing it from assigning a late orphan to the temporally nearest prompt span, and "nearest" is not "causal." ## Condition of Validity The correlation is valid only when all three of the following hold: 1. **Span completeness:** every mutation span referenced by a read span's `caused_by` field is present in the trace before the trace is sealed. If the collector seals on idle timeout rather than on explicit trace completion, this condition is violated by any exporter retry exceeding the idle window. 2. **Causal linkage over timestamp linkage:** the mutation span carries a `mutation_id` that the subsequent read span echoes in its span attributes. If the runtime does not propagate `mutation_id` into the read's attributes, the collector must fall back to timestamp ordering, which is invalid across clock skew between the agent process and the tool executor. 3. **Monotonic trace identity:** the mutation span's `trace_id` and `session_id` are immutable and match the read span's. A late-arriving span whose `trace_id` was already sealed must be quarantined, not re-parented. When any of these is violated, the mutation is an *unobservable span* — its effects are visible in the read but its cause is not reconstructable, and the collector must mark the trace as causally incomplete rather than synthesize a plausible parent. ## Decision Boundary The boundary is this: a collector may infer a mutation's parent span from timestamp proximity **only if** the mutation span's `session_id` matches the candidate parent's `session_id` **and** the trace has not been sealed. Once a trace is sealed, a late mutation span may be *attached as an orphan* to the sealed trace (preserving its own `trace_id`) but must never be re-parented to a span in a different trace. The moment the collector re-parents across trace boundaries, it has fabricated a causal edge that no agent executed — and every downstream consumer (auditors, replay engines, anomaly detectors) will treat that fabricated edge as ground truth. The operational rule: **sealed traces are append-only for orphans, never mutable for parentage.** A late span may join its own trace as a childless orphan; it may never be adopted by a span in another trace. ## Operational Effect When the boundary is respected, the observability store records a phantom read as a *known-incomplete trace* with an orphan mutation span — an explicit signal that the causal chain is broken. Auditors see "read with unresolved write" and route it to reconciliation rather than to an incident. When the boundary is violated, the phantom read is silently resolved by a fabricated cross-session edge, and the store now contains a false causal claim that survives every subsequent query, including the replay engine that uses the store to re-execute the turn. Replay re-executes the read against a memory state that was never written in that session, produces a divergent output, and the divergence is attributed to model non-determinism rather than to the observability corruption. The corruption is now laundered as model behavior. The guardrail is a sealing protocol: the runtime emits an explicit `trace.seal` span as the final act of a turn, the collector buffers all spans until seal or a hard timeout well above the exporter's max retry budget, and any span arriving after seal is quarantined with its original `trace_id` preserved. The `mutation_id` must be propagated into every dependent read span so that correlation is by identity, not by time. ```python class CausalOrphanViolation(RuntimeError): """Raised when a late-arriving mutation span would be re-parented across a sealed trace boundary.""" def correlate_mutation( mutation_span: dict, candidate_parent: dict, trace_sealed: bool, idle_timeout_ms: int, exporter_retry_budget_ms: int, ) -> dict: # Invariant 1: a sealed trace may accept orphans, never re-parent them. if trace_sealed: if mutation_span["trace_id"] != candidate_parent["trace_id"]: raise CausalOrphanViolation( f"mutation {mutation_span['span_id']} in trace {mutation_span['trace_id']} " f"cannot be re-parented to span {candidate_parent['span_id']} in sealed " f"trace {candidate_parent['trace_id']}: cross-trace adoption fabricates a causal edge" ) # Same-trace orphan: attach childless, do not mutate parentage. return {**mutation_span, "parent_span_id": None, "orphan": True} # Invariant 2: idle timeout must exceed the exporter's retry budget, else late spans # arrive after seal and hit the cross-trace path above. if idle_timeout_ms <= exporter_retry_budget_ms: raise CausalOrphanViolation( f"idle_timeout_ms={idle_timeout_ms} <= exporter_retry_budget_ms={exporter_retry_budget_ms}: " f"seal can fire before a retried mutation span is delivered, forcing orphan re-attribution" ) # Invariant 3: correlation by identity, not timestamp. if mutation_span.get("mutation_id") and candidate_parent.get("caused_by") == mutation_span["mutation_id"]: return {**mutation_span, "parent_span_id": candidate_parent["span_id"], "orphan": False} # Timestamp fallback is permitted only within the same session and unsealed trace. if mutation_span["session_id"] != candidate_parent["session_id"]: raise CausalOrphanViolation( f"mutation {mutation_span['span_id']} session {mutation_span['session_id']} " f"!= candidate parent session {candidate_parent['session_id']}: timestamp proximity " f"across sessions is not causal" ) return {**mutation_span, "parent_span_id": candidate_parent["span_id"], "orphan": False, "inferred": True} ```