# What happens when an instance links causal spans across a mid-trace context eviction and re-derives parent IDs from a lossy summary **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent systems that emit OpenTelemetry-style causal spans (trace_id/span_id/parent_span_id) and where a long-running agent instance may evict its own working context and resume from a distilled summary or checkpoint. Does not apply to stateless single-shot inference calls whose spans are emitted synchronously by a host process that owns the full causal record. ## Core Distinction Span linking is often treated as a *transport* concern: the tracer assigns a `span_id`, propagates a `trace_id` via context, and the backend stitches causality from `parent_span_id` pointers. The invariant everyone assumes is that **the causal edge is written at the moment the child span is created, by the process that actually knows its parent.** That assumption silently breaks the moment an agent instance evicts its own context and resumes. On resume, the instance no longer holds the live `SpanContext` object—it holds a *summary* of what it did. The summary is lossy: it may say "delegated retrieval to worker B" without preserving B's `span_id`, or it may preserve a *natural-language* handle ("the second retrieval step") that the resumed instance must re-resolve into a concrete parent. When the instance then emits the next span, it reconstructs the parent edge from that summary. The result is a **causally plausible but structurally wrong parent pointer**: the trace still forms a tree, still has no orphan spans, still passes schema validation—but the edge now points at a sibling, a re-run of the same step, or a synthetic "resume" span that never carried the original child's work. This is distinct from ordinary span loss (a dropped span produces an orphan, which is detectable). Here the trace is *complete and well-formed but causally false*, which is the dangerous case because no validator fires. ## What Was Observed A three-stage pipeline: orchestrator `O` → planner `P` → tool-executor `T`. Each stage emits a span; `T` emits one span per tool call, parented to the `P` span that requested it. `P` runs long enough to hit a context-window compaction threshold and resumes from a summary. The failure trace: 1. `P` (original instance, `span_id=0xA1`) issues tool request #1. `T` emits `span_id=0xB1, parent=0xA1`. Correct edge. 2. `P` issues tool request #2. `T` emits `span_id=0xB2, parent=0xA1`. Correct edge. 3. `P`'s context crosses the compaction threshold. The runtime evicts the live `SpanContext` and writes a summary: *"Tool executor called twice; second call returned the authoritative result."* The summary carries **no `span_id` for `0xA1`**—it carries a semantic descriptor. 4. `P` resumes as a new instance (`span_id=0xA2`), parented to `O`. It re-reads the summary and emits tool request #3. 5. `T` emits `span_id=0xB3`. The resumed `P` must supply a parent. It resolves "the authoritative result" to the *second* tool call and sets `parent=0xB2`—because that is the span the summary semantically points at, and it is the only concrete handle available. 6. The backend now records `0xB3` as a **child of a tool-executor span**, not of a planner span. The trace is a valid tree. `0xB3`'s parent is a sibling of the span that logically owns it. Downstream, `0xA1` and `0xA2` are siblings under `O`, and `0xB1`/`0xB2` hang off the dead `0xA1` while `0xB3` hangs off `0xB2`. Observed symptoms downstream: - Latency attribution double-counts: `0xB2`'s duration now "contains" `0xB3`'s, inflating tool-executor time and hiding planner time. - Replay-based verification (re-running the trace to check the agent's decisions) diverges: the replayer, following parent edges, reconstructs a plan that never happened—it sees the executor "deciding" to call itself. - A retry-dedup guard keyed on `(parent_span_id, tool_name)` failed to dedup `0xB3` against `0xB2`, because the guard assumed siblings share a parent and same-parent calls are retries. Here the retry appeared as a *child*, so the guard let a duplicate execution through. The critical observation: **every span had a valid parent, every trace was acyclic and connected, and the span-count matched the expected step-count.** The corruption was invisible to all structural checks. ## Condition of Validity The failure is bounded by a specific condition, and stating it precisely is what makes it actionable: > A causal edge reconstructed from a summary is valid **only if** the summary preserves a stable, opaque, non-semantic identifier for the parent span (or a token that maps 1:1 to it), **and** the resumed instance is forbidden from resolving that identifier through semantic inference. The invariant that must hold across the eviction boundary is therefore not "the parent is remembered" but **"the parent is remembered as an opaque handle, and the handle is never re-derived."** Any design where resume requires the instance to *interpret* a summary to find its parent violates the invariant. The moment interpretation enters, the probabilistic reasoner is free to pick a semantically-similar-but-structurally-wrong span, and it will do so confidently because the summary genuinely does point there. Two corollaries: - **Semantic descriptors are not handles.** "The second call," "the authoritative result," "the retrieval step" are all lossy under re-resolution. They survive paraphrase but not identity. - **A resume span is a real span, not a repair.** If the runtime emits `0xA2` as the continuation, then *all* subsequent children of the resumed instance must parent to `0xA2`, never to pre-eviction spans. Parenting across the boundary re-opens the dead instance's subtree and splits causality across two live nodes. ## Decision Boundary The operational choice is between two resume strategies, and the boundary is sharp: - **Handle-preserving resume** (correct): the checkpoint serializes the live `SpanContext` (trace_id, span_id, trace_flags) as opaque bytes alongside the summary. On resume, the instance continues the *same* span identity (`0xA1` is reused as the resumed instance's span, or a child `0xA2` is opened with `parent=0xA1` and all future children parent to `0xA2`). No semantic resolution occurs. Cost: the checkpoint must carry structured state, not just prose. - **Semantic-reconstructive resume** (unsafe): the checkpoint carries only prose; the resumed instance infers its parent. This is *only* acceptable when the resumed instance opens a fresh root span and **explicitly severs** the pre-eviction subtree—i.e., it declares the boundary as a new causal root and the backend links the two traces by a separate `resumed_from` attribute, not by `parent_span_id`. The prose is then a *hint*, never a causal edge. The boundary is crossed the instant a system uses `parent_span_id` to encode "logically continued from" rather than "physically spawned by." If the edge means "spawned by," it must be written by the spawner with a live handle. If it means "continued from," it must be a distinct, non-structural attribute so that structural traversals (latency rollup, replay, dedup) do not follow it. ## Operational Effect Concretely, systems that violate the invariant exhibit: 1. **Latency attribution skew** proportional to the number of evictions—each reconstructive edge moves a subtree's duration under the wrong ancestor, and the error compounds because the wrong ancestor is itself under-counted. 2. **Replay divergence** that is *deterministic but wrong*: the replayer faithfully follows false edges, so verification passes on a plan the agent never executed. This is worse than a crash because it produces a confident green check. 3. **Dedup and idempotency leaks** where retry guards keyed on structural position (sibling, same-parent) miss retries that landed as children. 4. **Silent span-count inflation** when the resumed instance, unable to find its live parent, emits a synthetic "resume" span *and* re-parents existing children to it—duplicating edges. The guardrail is a single check at span-emission time: **reject any `parent_span_id` that was not produced by the emitting instance's own live `SpanContext`.** If the parent handle is not in the instance's live context, the edge is reconstructive and must be downgraded to a `resumed_from` attribute with the child re-rooted. The check is cheap, runs at emit time, and catches the failure before it reaches the backend where it becomes structurally invisible. The code below implements the emit-time guard: it holds the live span context, refuses to let a resumed instance parent to a handle it did not itself carry, and forces the reconstructive case into a re-root with an explicit `resumed_from` link. ```python from dataclasses import dataclass, field from typing import Optional class CausalEdgeViolation(RuntimeError): """Raised when a span attempts to parent to a handle that was not carried live across the instance's own context boundary.""" pass @dataclass class SpanContext: trace_id: str span_id: str @dataclass class Instance: name: str live: Optional[SpanContext] = None # Handles this instance actually held live (not inferred from summary). carried: set = field(default_factory=set) def adopt(self, ctx: SpanContext) -> None: self.live = ctx self.carried.add(ctx.span_id) def resume_from_summary(self, summary_parent_hint: str, new_span: SpanContext) -> None: """Resume after eviction. The hint is prose-derived and NOT a handle. We open a fresh span; we never adopt the hinted id as live.""" self.live = new_span self.carried.add(new_span.span_id) # The hint is recorded as a non-structural link only. self._resumed_from = summary_parent_hint def emit_child(self, child_span_id: str, proposed_parent: str) -> dict: if proposed_parent not in self.carried: # Reconstructive edge: the instance is interpreting a summary. # Downgrade: re-root to the live span, record resumed_from. if self.live is None: raise CausalEdgeViolation( f"{self.name}: no live span; cannot emit " f"{child_span_id} with reconstructive parent " f"{proposed_parent}" ) return { "span_id": child_span_id, "parent_span_id": self.live.span_id, "resumed_from": proposed_parent, "reconstructed": True, } return { "span_id": child_span_id, "parent_span_id": proposed_parent, "reconstructed": False, } ```