# What happens when an instance reuses a causal parent span ID after a context compaction boundary and the trace becomes non-reconstructable across federated agents **Date of Record:** 2026 November 28 **Scope:** Applies to federated multi-agent systems where spans are correlated across process and trust boundaries via propagated trace context (W3C `traceparent`-style headers or equivalent), and where an agent instance can undergo context-window compaction or checkpoint/resume mid-trace. Does not apply to single-process, single-agent instrumentation where span lifecycle is owned by one runtime and never serialized across a handoff. ## Core Distinction The distinction that matters here is between *span identity* and *causal ancestry*. Most federated tracing designs assume that if a child span carries the correct `trace_id` and a `parent_span_id` that resolves to a real span, the causal graph is reconstructable. That assumption is false the moment an agent's in-memory span stack is destroyed by a compaction event and later rebuilt from a summary that preserves the *value* of the parent span ID but not the *lifetime* of the span it named. A span ID is a 64-bit opaque token. It carries no proof that the span it names was still open at the moment the child was created, nor that the child was causally initiated by the work represented by that parent. When an agent resumes from a checkpoint, it typically restores "the current trace context" as a flat record: `trace_id`, `parent_span_id`, and baggage. It does not restore the parent span's open/closed state, its start/end timestamps, or the causal event that produced the child. The result is a trace that *parses* — every parent ID resolves — but is *causally wrong*: spans appear as siblings of work they actually followed, and the true ordering is lost. This is a continuity invariant, not a logging bug: **a restored span context must be treated as an orphan unless the resuming runtime can prove the parent span is still open in the same causal chain.** The failure mode is the violation of that invariant. ## What Was Observed A three-agent federated pipeline: a planner agent (A), a retrieval agent (B), and a synthesis agent (C), each in a separate trust domain, coordinating over an A2A-style transport with trace context propagated in message headers. A's context crossed its compaction threshold at ~78% of the window during a long retrieval loop, triggering a summarization pass and a resume from checkpoint. The checkpoint serializer had captured, among other state, `current_trace_context = {trace_id: T, parent_span_id: S_retrieval_loop}` where `S_retrieval_loop` was the span A had opened for the retrieval sub-task. That span was, at checkpoint time, still open. On resume, A rehydrated the context and continued. It then issued three more calls to B, each stamped with `parent_span_id = S_retrieval_loop`. The trace backend received: - `S_retrieval_loop` opened at `t0`, closed at `t1` (the pre-compaction span, correctly ended by the pre-compaction runtime). - Three child spans `S_b1`, `S_b2`, `S_b3` with `parent_span_id = S_retrieval_loop`, timestamps `t2, t3, t4` all `> t1`. Every span resolved. No orphan warnings fired, because the backend's orphan check is "does the parent ID exist in the trace," not "was the parent open when the child started." But the causal graph now claims that three retrieval calls, issued *after* the retrieval loop had ended and after a full compaction-and-summarization cycle, were children of that loop. The synthesis agent C, which correlates on the trace to decide whether to wait for retrieval completion, saw `S_retrieval_loop` as closed and the three new children as stragglers, and proceeded to synthesize against a stale retrieval set. It emitted a confident answer built on the pre-compaction retrieval, silently discarding the three fresh fetches that had been the entire point of resuming. The second-order effect was worse. Because the three new spans shared a parent with the original loop's children, the backend's critical-path computation merged them into one branch. When the auditor agent later replayed the trace to verify C's output, it reconstructed a causal order in which the fresh fetches happened *inside* the loop that had already closed — an impossible ordering that the auditor's verifier rejected as a corrupted trace, escalating a false integrity alarm while the actual staleness went unflagged. ## Condition of Validity The invariant holds — restored span context is untrustworthy and must be re-parented — under all of the following: 1. The resuming runtime cannot query the live state of the named parent span (the common case across federated boundaries; the parent lives in another process or trust domain). 2. The checkpoint captured span context as a flat value rather than as a structured record including parent open/closed state and parent end-timestamp. 3. The trace backend's validation is existence-based (parent ID present) rather than interval-based (child start within parent `[start, end]`). The invariant does *not* bind when the runtime can perform a synchronous "is this span still open?" check against the trace backend before reusing the parent — in that case the restored context is validated, not assumed. It also does not bind in a single-process runtime where the span object survives compaction because it lives on a stack the compactor does not touch. ## Decision Boundary The operational decision is: **on resume from any checkpoint that crossed a compaction or process boundary, the agent must open a new span — a *resumption span* — and parent all post-resume work to it, not to the pre-compaction span.** The resumption span is explicitly linked (via a span link, not a parent reference) to the pre-compaction span, preserving the audit trail without asserting a false causal parent. The boundary condition is precise: reuse the restored `parent_span_id` only if the checkpoint record includes `parent_span_end_ts = null` *and* the runtime holds a lease or liveness token proving the parent is still open. Absent both, re-parent. A span ID that resolves is not a span that is open; conflating the two is the entire failure. For the auditor, the corresponding rule is interval-based verification: reject any trace in which a child's start timestamp precedes its parent's start or follows its parent's end. This converts a silent causal corruption into a loud, localized integrity failure — which is the correct outcome, because a non-reconstructable trace is worse than a rejected one. ## Operational Effect After adopting the resumption-span rule, the pipeline's traces became longer (one extra span per resume) but causally sound: the auditor's interval check passed, and the synthesis agent's "wait for retrieval" predicate — which keyed on the *open* retrieval span — correctly blocked until the fresh fetches completed under the resumption span. The staleness class of bug disappeared because the causal signal C depended on was no longer forged by a reused ID. The cost is that trace consumers must now understand span links in addition to parent references, and dashboards that counted "children of the loop" must be rewritten to follow links. That is the price of the invariant: causal ancestry is a claim about time and initiation, and a 64-bit token copied across a boundary cannot carry that claim. The guardrail is to stop pretending it does. ```python class CausalAncestryViolation(RuntimeError): """Raised when a restored span context would forge causal ancestry.""" pass def reparent_on_resume(checkpoint: dict, live_span_open: bool) -> dict: """ Decide the parent span for post-resume work. checkpoint: restored trace context, must include trace_id, parent_span_id, and parent_span_end_ts (None if the parent was open at capture). live_span_open: True only if the runtime holds a verified liveness lease on the named parent span in its owning domain. """ trace_id = checkpoint.get("trace_id") parent_id = checkpoint.get("parent_span_id") parent_end = checkpoint.get("parent_span_end_ts") if not trace_id or not parent_id: raise CausalAncestryViolation( f"checkpoint lacks trace context: {checkpoint!r}" ) # Safe to reuse the parent only if it was open at capture AND is still live. if parent_end is None and live_span_open: return {"trace_id": trace_id, "parent_span_id": parent_id, "linked_to": None} # Parent was closed at capture, or we cannot prove it is still open. # Reusing it would assert a causal link that does not exist. if parent_end is not None: raise CausalAncestryViolation( f"refusing to reuse closed parent {parent_id} (ended at {parent_end}); " f"open a resumption span and link to it instead" ) # Parent open at capture but liveness unverifiable across the boundary: # do not forge ancestry; emit a resumption span linked to the old one. return { "trace_id": trace_id, "parent_span_id": None, # new resumption span becomes the parent "linked_to": parent_id, # audit link, not a causal parent } ```