# In what scenarios must an instance treat trace-span re-parenting after a context-window eviction as a drift signal rather than a benign observability artifact **Date of Record:** 2026 December 3 **Scope:** Applies to LLM agent runtimes that emit hierarchical OpenTelemetry-style spans (tool calls, sub-agent delegations, reasoning steps) and correlate them post-hoc with logs and eval scores for behavioral drift detection. Does not apply to single-turn, stateless inference endpoints or to pipelines where span parentage is fixed at emission time and never reconstructed. ## Core Distinction The failure is not "missing traces" or "orphaned spans" in the ordinary sense. It is the case where an agent's context window saturates mid-task, the runtime performs a checkpoint-and-evict (summarize history, drop raw spans, resume), and the *resumed* agent re-emits spans that the collector — using a heuristic parent-resolution rule (e.g., "attach to the most recent open span in the same session") — re-parents under a *different* subtree than where they logically belong. The observability pipeline then reports a clean, fully-connected trace. Nothing looks broken. But the topology of the trace has silently changed, and downstream drift detectors that key on span-tree shape (branching factor, depth, sibling count per tool) will read this as behavioral drift when the agent's actual behavior was identical. The distinction that matters: **a continuity invariant of the agent's state (context preservation across eviction) is being conflated with a continuity invariant of the trace (parentage preservation across emission).** These are independent. The agent can lose state without the trace changing, and the trace can change without the agent losing state. Drift detectors that assume the two co-vary will misfire in exactly the eviction scenario. ## What Was Observed A tool-orchestration agent (Planner → N parallel Retriever sub-agents → Synthesizer) was instrumented with span emission at every step. Baseline traces had a stable shape: root Planner span, a fan-out of 4–6 Retriever child spans at depth 1, one Synthesizer span at depth 1 with a `depends_on` link to the retrievers. Under a long-context workload (a task whose accumulated tool outputs exceeded 96K tokens), the runtime triggered its eviction path: it serialized the working set, summarized the transcript, and resumed the agent in a fresh context. The resumed agent had *no in-context memory of the open span IDs it had emitted before eviction*. It re-emitted its next tool calls with a fresh `session_id` but the same logical `task_id`. The collector's parent-resolution rule — "if a span has no resolvable parent, attach it to the latest open span with matching `task_id`" — attached the post-eviction Retriever spans *under the Synthesizer span* (the last span still open at eviction time), not under the Planner. The Synthesizer, which had already begun, was still open. Result: the trace showed Synthesizer with 5 children at depth 2, and Planner with zero Retriever children. The drift detector, configured to alert when "fan-out under Planner drops below 3," fired. It also flagged "Synthesizer branching factor anomaly." Neither reflected a behavioral change. On replay with eviction disabled (context pre-compressed), the agent produced byte-identical tool calls and the trace was topologically normal. The drift signal was 100% an artifact of re-parenting. What made this non-obvious: the trace was *valid*. Every span had a parent. No span was orphaned in the sense the collector's healthcheck measured. The `task_id` correlation held. Only the *shape* was wrong, and shape was the drift feature. ## Condition of Validity This failure is bounded by three conditions, all of which must hold: 1. **Eviction occurs while a span is open.** If the runtime checkpoints only at span boundaries (all child spans closed before eviction), the resumed agent has no open parent to mis-attach to, and the collector falls back to the root. The failure requires an open ancestor at eviction time — most commonly a long-running Synthesizer or Aggregator span that stays open across the entire sub-agent fan-in. 2. **Parent resolution is heuristic, not carried.** If the runtime propagates the parent span ID through the checkpoint (serializing `current_span_id` alongside the working set) and the resumed agent re-uses it, parentage survives. The failure requires that parent identity is *reconstructed* by the collector from correlation keys rather than *carried* by the agent. 3. **Drift detection keys on topology.** If drift is detected from eval scores or output distributions alone, re-parenting is invisible. The failure requires a drift feature that reads span-tree structure — fan-out counts, depth, sibling cardinality, or span-duration nesting. When all three hold, every eviction event produces a false-positive drift alert. When any one is broken, the failure does not manifest. ## Decision Boundary The operational question is: given a re-parented trace, when should the instance treat it as a drift signal and when as an artifact? The boundary is a **replay test on the parentage axis**, not on the behavior axis. - If replaying the task with eviction disabled (forcing pre-compression) yields the *same tool-call sequence* but a *different trace topology*, the topology change is an artifact. Suppress the drift alert; log it as an observability-continuity event, not a behavioral one. - If replay yields a *different tool-call sequence*, the topology change is coincident with — but not caused by — the eviction, and the drift signal stands. - If replay is impossible (non-deterministic tool outputs), fall back to comparing the *set* of tool calls (order-insensitive) rather than the tree. A re-parented trace preserves the multiset of spans; a genuinely drifting agent does not. The guardrail invariant required: **span parentage must be carried through the checkpoint, not reconstructed.** Concretely, the checkpoint payload must include `open_span_ids` and `current_parent_id`, and the resumed agent must re-emit with those IDs. If the runtime cannot carry them (e.g., the collector assigns IDs post-hoc), then the drift detector must be configured to ignore topology features for any trace whose spans cross an eviction boundary — detectable via a `checkpoint_resumed` marker span emitted at resume. ## Operational Effect Without the guardrail, the drift detector's false-positive rate scales with eviction frequency, which scales with task length. Long-context workloads — precisely the ones where behavioral drift is most consequential — generate the most artifacts, desensitizing operators to the alert. The failure is self-masking: the more you need drift detection, the less you can trust it. With the guardrail (carry parentage, or mark eviction boundaries and exclude topology features across them), the drift signal recovers its specificity. The cost is that topology-based drift detection goes blind across eviction boundaries — a real behavioral drift that happens to coincide with an eviction will be missed. This is the correct trade: a missed drift signal on an eviction-crossing task is recoverable via eval-score drift (which is eviction-invariant), whereas a false positive on every long task is not. The invariant to encode: *trace topology is a function of agent state continuity, not agent behavior, whenever the trace crosses an eviction boundary.* Treat the two as separable, and the pipeline stops correlating a state-management event with a behavioral one. ```python class TraceReparentingDriftError(RuntimeError): """Raised when a drift alert is attributable to span re-parenting across an eviction boundary.""" pass def classify_drift_alert( trace, replay_tool_calls, original_tool_calls, crosses_eviction_boundary: bool, ) -> str: """ Decide whether a topology-based drift alert is a real behavioral signal or an artifact of re-parenting after context-window eviction. Returns one of: "behavioral_drift", "reparenting_artifact", "indeterminate". Raises TraceReparentingDriftError when the inputs are insufficient to make the call safely (e.g. eviction boundary present but no replay). """ if crosses_eviction_boundary and replay_tool_calls is None: raise TraceReparentingDriftError( f"trace {trace.id} crosses an eviction boundary but no replay " f"tool-call sequence was supplied; cannot separate artifact from drift" ) if not crosses_eviction_boundary: # No eviction involved: topology change is behavioral. return "behavioral_drift" # Eviction involved: compare tool-call multisets, not tree shape. if sorted(replay_tool_calls) == sorted(original_tool_calls): # Same behavior, different topology -> artifact. return "reparenting_artifact" if sorted(replay_tool_calls) != sorted(original_tool_calls): # Behavior genuinely changed; drift stands. return "behavioral_drift" return "indeterminate" def emit_drift_verdict(trace, verdict: str, alert_sink): if verdict == "reparenting_artifact": # Downgrade to observability-continuity event, do not page. alert_sink.emit( kind="observability_continuity", trace_id=trace.id, detail="topology changed across eviction; behavior unchanged", ) elif verdict == "behavioral_drift": alert_sink.emit(kind="behavioral_drift", trace_id=trace.id) else: raise TraceReparentingDriftError( f"indeterminate verdict for trace {trace.id}; refusing to emit" ) ```