How should an instance reconcile OpenTelemetry GenAI span parentage when a multi-turn agent re-enters a suspended tool-call loop after context compaction

**Date of Record:** 2026 December 2 **Scope:** Applies to agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) across multi-turn conversations where a tool-call loop can be suspended (awaiting human approval, long-running tool, or context compaction) and resumed by a *different* process or LLM instance. Does not apply to single-shot inference calls or to trace backends that reconstruct parentage purely from timestamps.

Core Distinction

The GenAI semantic conventions model a *conversation* as a span tree rooted at an `invoke_agent` span, with child `chat` spans per turn and `execute_tool` spans nested under the `chat` span that requested them. This model assumes the trace context propagates *forward* through a single logical execution. It does not define what happens when execution is **suspended mid-tool-call and resumed by a fresh instance** whose in-memory span stack is gone.

The non-obvious boundary: the resuming instance has a valid W3C `traceparent` (persisted in the checkpoint) but **no live parent span object**. Naively re-emitting the resumed `execute_tool` span with the persisted `traceparent` re-parents it correctly at the trace level—but the `gen_ai.operation.name`, `gen_ai.usage.*`, and turn-index attributes are reconstructed from a compacted summary, not the original context. The span *structurally* attaches to the old trace while *semantically* describing a different reasoning episode. The invariant that breaks is **span-attribute coherence with the reasoning state that actually produced the observed output**: the resumed span claims continuity (same trace, same parent) but its attributes are a lossy projection of a context that no longer exists.

What Was Observed

Trigger condition: a `chat` span at turn N emits a tool call, the runtime checkpoints `{traceparent, conversation_summary, pending_tool_call}` and suspends. Compaction reduces a 190k-token context to a 4k summary. On resume, the new instance:

  1. Restores `traceparent` → parent span ID = the turn-N `chat` span.
  2. Emits `execute_tool` with the persisted parent. ✅ Trace tree looks correct.
  3. Emits a follow-up `chat` span (turn N+1) carrying `gen_ai.usage.input_tokens` measured against the *compacted* prompt (~4k), not the *logical* conversation (190k).

Failure trace: the trace backend aggregates cost and latency per `invoke_agent` root. The turn-N+1 `chat` span reports 4k input tokens; the turn-N span reported 188k. Downstream cost attribution and "context-window saturation" detectors read the drop as a *legitimate* context reduction and reset their saturation counters—masking that the agent is now reasoning from a lossy summary. The trace is *structurally* valid and *semantically* a lie: it presents an amnesia event as a normal token-count transition.

A second observed variant: two resumed branches (retry + original) both parent to the same turn-N `chat` span ID, producing a fan-out the conventions never anticipated. Auditors reading the tree cannot distinguish "parallel tool calls" (legitimate) from "duplicate resume after a checkpoint race" (a bug).

Condition of Validity

The default parentage rule—"child span's parent = the span that causally triggered it"—holds **only when the triggering span's context is still resident in the executing instance**. It is invalid the moment the trigger is a *persisted artifact* rather than a live span, because:

The invariant to enforce: **every span emitted after a checkpoint/resume MUST carry an explicit continuity attribute distinguishing "live" from "re-based" parentage**, and the parent link must be re-established through a synthetic continuation span rather than direct re-parenting to a closed span.

Decision Boundary

Choose **direct re-parenting** (emit child with persisted `traceparent`) only when: (a) the parent span is still open in a shared collector, (b) the resumed context is byte-identical to the checkpointed context (no compaction), and (c) exactly one resume path exists.

Choose **synthetic continuation span** when any of the above fails. Emit a zero-duration `gen_ai.resume` span (or a `chat` span with `gen_ai.operation.name=resume`) as the child of the persisted parent, carrying `checkpoint.id`, `compaction.ratio`, and `context.tokens_before`/`context.tokens_after`. All post-resume spans parent to this continuation span. This preserves trace-tree integrity while making the amnesia event *first-class and queryable*: saturation detectors and cost aggregators can key on `gen_ai.resume` presence instead of inferring continuity from token-count deltas.

The boundary is not "did the trace render"—both approaches render. It is **"can a downstream consumer distinguish a lossy resume from a normal turn without reading application logs."** Direct re-parenting cannot; the continuation span can.

Operational Effect

With direct re-parenting, the failure is silent: cost dashboards under-report post-compaction inference cost (4k vs 190k tokens), context-saturation alarms miss the reset, and duplicate-resume races appear as legitimate parallel tool fan-out. The trace is a plausible fiction.

With the continuation-span guardrail, resume events become a countable, attributable class. Alerting on `count(gen_ai.resume) > 0 per conversation` surfaces compaction frequency; `context.tokens_before - context.tokens_after` quantifies distillation loss; duplicate `gen_ai.resume` spans under one parent expose checkpoint races. The cost of the guardrail is one extra span per resume and a schema addition to the backend—trivial against the alternative of undetectable amnesia presented as normal operation.

from dataclasses import dataclass


class SpanParentageViolation(RuntimeError):
    """Raised when a resumed agent span cannot honor GenAI parentage invariants."""
    pass


@dataclass
class Checkpoint:
    traceparent: str
    parent_span_open: bool
    tokens_before: int
    tokens_after: int
    resume_paths: int


def emit_resumed_span(checkpoint: Checkpoint, span_kind: str) -> str:
    compacted = checkpoint.tokens_after < checkpoint.tokens_before
    # Invariant: direct re-parenting is valid ONLY for live, uncompacted,
    # single-path resumes. Anything else must route through a continuation span.
    if compacted and span_kind != "gen_ai.resume":
        raise SpanParentageViolation(
            f"cannot re-parent {span_kind} directly: context compacted "
            f"({checkpoint.tokens_before}->{checkpoint.tokens_after}); "
            f"emit gen_ai.resume continuation span first"
        )
    if not checkpoint.parent_span_open and span_kind != "gen_ai.resume":
        raise SpanParentageViolation(
            f"cannot attach {span_kind} to closed parent span; "
            f"re-base via gen_ai.resume"
        )
    if checkpoint.resume_paths > 1 and span_kind != "gen_ai.resume":
        raise SpanParentageViolation(
            f"duplicate resume ({checkpoint.resume_paths} paths) under one "
            f"parent; must disambiguate with gen_ai.resume spans"
        )
    # Valid: emit with persisted traceparent (or the continuation span itself).
    return f"emitted {span_kind} under {checkpoint.traceparent}"