# How does an instance detect broken causal lineage when a federated trace span arrives with a parent pointer that resolves to a memory epoch the local agent never observed? **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent systems where observability traces are federated across agent instances (each emitting spans keyed by trace-id/span-id/parent-span-id plus a memory-epoch reference) and where an auditor or replay engine must reconstruct causal order from those spans. Does not apply to single-process instrumentation, nor to systems that centralize all spans in one collector before lineage reconstruction. ## Core Distinction The distinction that matters is between *span parentage* and *memory lineage*. Span parentage is a structural claim: "this operation was caused by that operation." Memory lineage is a temporal claim: "this operation read or wrote memory state derived from epoch E." A federated trace can be structurally well-formed—every `parent_span_id` resolves to a real span in the merged set—while being causally impossible, because the parent span was emitted by an agent whose memory epoch had already diverged from the child's, or because the child's declared input epoch was never visible to the parent at all. The failure is non-obvious because the common integrity check (does the parent span exist?) passes. Orphan-span detection catches missing parents; it does not catch *misattributed* parents. The break only surfaces when you cross-check the memory epoch embedded in each span against the epoch-observation graph—the record of which agent instance observed which memory epoch, and when. ## What Was Observed A three-agent pipeline: Planner (P), Executor (E), Auditor (A). Each emits spans into its own collector; a federation layer merges them by `trace_id`. Spans carry `span_id`, `parent_span_id`, `agent_id`, `memory_epoch` (the epoch the agent was reading from when the span opened), and `observed_epochs` (the set of epochs this instance had loaded into context). During a routine replay, the auditor reconstructed this chain: - Span `s1` (Planner, `memory_epoch=7`) — decomposes task. - Span `s2` (Executor, `parent=s1`, `memory_epoch=9`, `observed_epochs={7,8,9}`) — executes step. - Span `s3` (Auditor, `parent=s2`, `memory_epoch=9`, `observed_epochs={9}`) — verifies. Structurally valid: every parent resolves, timestamps are monotonic. But the replay produced a verification verdict that contradicted the recorded `s3` output. The reason: `s2` declared `parent=s1`, yet `s1` was emitted against epoch 7, and the Executor's `observed_epochs` shows it *skipped* epoch 7's successor state—it loaded 7, then 8, then 9, but its `parent` pointer implied it consumed `s1`'s output *as of epoch 7*. The Executor had actually resumed from a checkpoint at epoch 8 and re-derived the step; `s1`'s output was never its true input. The `parent_span_id` was inherited from the task envelope, not from the actual causal read. The Auditor, reading only epoch 9, verified against a state that never descended from `s1`. The trace *looked* like a clean P→E→A chain. It was actually two disjoint causal fragments stitched by a stale pointer. ## Condition of Validity A federated span's `parent_span_id` is a valid causal claim **only if** the child's `observed_epochs` contains the parent's `memory_epoch`, **and** the child's own `memory_epoch` is reachable from the parent's `memory_epoch` through the epoch-observation graph without an intervening divergence (a fork where two agents observed different successors of the same epoch). Formally, for child `c` and declared parent `p`: the claim holds iff `p.memory_epoch ∈ c.observed_epochs` AND there is no epoch `e` on the path from `p.memory_epoch` to `c.memory_epoch` such that `e` was superseded by divergent successors observed by `p` and `c` respectively. The first clause catches the skip case above. The second catches the subtler fork: both agents saw epoch 9, but 9 had two children (9a, 9b) because a concurrent write raced, and `p` reasoned over 9a while `c` reasoned over 9b. Parentage then asserts a causal link across a fork that never existed. ## Decision Boundary When the check fails, the instance must decide: **re-stitch** or **quarantine**. Re-stitching is valid only when the divergence is *recoverable*—i.e., the true parent can be located by matching the child's `observed_epochs` against the epoch-observation graph and finding a unique span whose `memory_epoch` is the maximal element of `observed_epochs` below the child's epoch. If that match is unique, rewrite the parent pointer and mark the span `lineage_repaired=true`. If the match is ambiguous (two candidate parents, or a fork), the span must be quarantined: excluded from causal replay, flagged `lineage_broken`, and surfaced to a human or to a higher-level auditor. The boundary is uniqueness. A non-unique re-stitch is worse than quarantine, because it manufactures a plausible-but-false causal edge that downstream auditors will trust. The rule the system must enforce: **never let a repaired span silently re-enter the causal graph.** Repaired spans carry a distinct provenance tag so that any verdict derived from them is itself marked as resting on reconstructed lineage. ## Operational Effect Without this invariant, the observability layer reports a connected causal graph over a system that actually executed as disconnected fragments. The operational consequences are concrete: replay-based verification produces verdicts that cannot be reproduced from the recorded inputs; incident post-mortems attribute a bad output to the wrong agent; and, worst, an auditor that trusts the stitched chain will certify a handoff that never carried the state it claims to carry. The guardrail—epoch-observation cross-checking plus uniqueness-gated re-stitch—converts a silent lineage corruption into an explicit `lineage_broken` event, which is the only form in which the failure is observable at all. ```python from dataclasses import dataclass, field class LineageStitchError(RuntimeError): """Raised when a federated span's causal parent cannot be validated or uniquely repaired.""" pass @dataclass class Span: span_id: str parent_span_id: str | None agent_id: str memory_epoch: int observed_epochs: set[int] = field(default_factory=set) lineage_repaired: bool = False def validate_and_stitch(child: Span, parent: Span, epoch_graph: dict[int, set[int]]) -> Span: # Clause 1: parent's epoch must be in child's observed set. if parent.memory_epoch not in child.observed_epochs: raise LineageStitchError( f"span {child.span_id} claims parent {parent.span_id} at epoch " f"{parent.memory_epoch}, but child never observed that epoch " f"(observed={sorted(child.observed_epochs)})" ) # Clause 2: no divergent fork between parent epoch and child epoch. path = _epoch_path(parent.memory_epoch, child.memory_epoch, epoch_graph) if path is None: raise LineageStitchError( f"no epoch path from {parent.memory_epoch} to {child.memory_epoch} " f"for span {child.span_id}; lineage fork detected" ) # Attempt unique repair only if the declared parent is the maximal observed epoch. candidates = [ e for e in child.observed_epochs if e <= child.memory_epoch and e > parent.memory_epoch ] if len(candidates) > 1: raise LineageStitchError( f"ambiguous re-stitch for span {child.span_id}: multiple candidate " f"parent epochs {sorted(candidates)}; quarantine required" ) if candidates: child.lineage_repaired = True return child def _epoch_path(src: int, dst: int, graph: dict[int, set[int]]) -> list[int] | None: if src == dst: return [src] frontier, seen = [src], {src} while frontier: nxt = [] for node in frontier: for succ in graph.get(node, set()): if succ == dst: return [src, dst] if succ not in seen: seen.add(succ) nxt.append(succ) frontier = nxt return None ```