# What happens when an instance emits OpenTelemetry GenAI spans for a tool-call graph whose parent `gen_ai.conversation.id` is rebound mid-flight **Date of Record:** 2026 November 30 **Scope:** Applies to agent runtimes that emit OTel GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.conversation.id`, `gen_ai.agent.id`, `gen_ai.usage.*`) for multi-step tool-call graphs where a single logical task may span more than one `conversation.id` due to compaction, handoff, or sub-agent delegation. Does not apply to single-turn inference telemetry or to non-GenAI spans. ## Core Distinction A trace tree is a *causal* structure keyed by `trace_id`/`span_id`. A *conversation* is a *logical* structure keyed by `gen_ai.conversation.id`. The GenAI semantic conventions do not declare an invariant binding these two keys together, but downstream analytics (cost attribution, replay-based evaluation, tool-call success SLOs) silently assume `conversation.id` is a stable partition of the trace: every span with the same `conversation.id` belongs to one causal tree, and every causal tree carries exactly one `conversation.id`. When an agent rebinds `gen_ai.conversation.id` mid-task—because context compaction opens a "new conversation," because a sub-agent is spawned with its own id, or because a resumed checkpoint regenerates the id—the span graph remains causally valid but the *conversation partition* fractures. The failure is not a lost span; it is a **silent double-counting and orphaned-parent condition** that only manifests in aggregate telemetry, long after the agent run has exited cleanly. ## What Was Observed A planner agent executes a 9-step tool graph: `search_docs → read_file → read_file → summarize → write_artifact → verify → retry_verify → finalize → emit`. At step 5 the planner's context crosses 82% of the window and the runtime triggers compaction. The compaction routine, following the GenAI convention's guidance that `gen_ai.conversation.id` "SHOULD be used to correlate spans that belong to the same conversation," mints a fresh UUID for the post-compaction segment and stamps it on steps 6–9. Steps 1–5 retain the original id. The trace parent-child links (`parent_span_id`) are untouched: step 6's `verify` span correctly parents to step 5's `write_artifact` span. The trace is causally intact. But: 1. **Conversation-partition split.** Steps 1–5 form conversation `A`, steps 6–9 form conversation `B`. Any aggregation `GROUP BY gen_ai.conversation.id` now reports two "conversations," each with a partial tool-call graph. A tool-call success rate computed per conversation sees `A` at 5/5 (no failure yet) and `B` at 2/3 (the `retry_verify`), because the retry's *cause*—a failure inside `verify`—is attributed to `B` while the failure's *context* lives in `A`. The denominator is wrong in both directions. 2. **Orphaned-parent on the boundary.** The `verify` span (step 6, conversation `B`) has `parent_span_id` pointing at `write_artifact` (step 5, conversation `A`). A replay evaluator that reconstructs the conversation from `conversation.id = B` and then walks `parent_span_id` upward hits a parent whose `conversation.id` is `A` and—depending on the evaluator's strictness—either drops the edge (producing a rootless `verify` node, i.e., a tool call with no recorded cause) or rejects the conversation as corrupt. Both outcomes are silent: the evaluator logs a warning at `WARN` level and continues. 3. **Cost double-count on retry.** `gen_ai.usage.input_tokens` for the compaction call itself is emitted on a `gen_ai.operation.name = "chat"` span that the runtime parents to the *last* span of segment `A` but stamps with conversation `B` (the "new" conversation pays for the compaction that ended the old one). Token-cost dashboards that sum `usage.input_tokens` per conversation now show `B` paying for a compaction whose inputs came entirely from `A`, inflating `B`'s cost-per-successful-tool-call by 30–40% in observed runs. 4. **Resume divergence.** If the run is resumed from a checkpoint taken between steps 5 and 6, the checkpoint stores conversation `A`'s id, but the live runtime has already advanced to `B`. On resume the runtime emits step 6 with `A` again, producing two `verify` spans under the same `span_id` (if the runtime reuses span ids from the checkpoint) or two divergent conversation graphs (if it doesn't). Neither is flagged. The tell is not in any single span. It is in the *cardinality* of `gen_ai.conversation.id` per `trace_id`: a healthy run has exactly one; a fractured run has two or more, and the boundary span is the only place where a `parent_span_id` crosses the partition. ## Condition of Validity The invariant that downstream analytics relies on is: > For every `trace_id`, the set of distinct `gen_ai.conversation.id` values observed on spans in that trace has cardinality 1, **or** every span carrying a non-primary `conversation.id` has a `gen_ai.operation.name` of `invoke_agent` (i.e., it is an explicit sub-agent boundary) with a `gen_ai.agent.id` distinct from its parent's. The second clause is the escape hatch: sub-agent delegation *legitimately* produces multiple `conversation.id`s in one trace, but only when the boundary is marked by an `invoke_agent` span that names the child agent. A compaction-induced rebind, a checkpoint-resume rebind, or a "new conversation" minted by a summarizer does **not** satisfy this clause—there is no `invoke_agent`, no distinct `gen_ai.agent.id`, and the rebind is invisible in the span schema except as a changed string on a child span. The condition fails—and the failure is *undetectable per-span*—whenever a runtime rebinds `conversation.id` without emitting an `invoke_agent` boundary span. This is the default behavior of most compaction and summarization routines, because they treat conversation identity as a *presentation* concern (what the user sees) rather than a *telemetry* concern (what the trace graph asserts). ## Decision Boundary The runtime must choose, at the moment of rebind, between two mutually exclusive policies: - **Policy P1 (stable partition):** `gen_ai.conversation.id` is immutable for the lifetime of a `trace_id`. Compaction, summarization, and checkpoint-resume *do not* change it. If a new logical conversation is genuinely needed, the runtime must either (a) end the trace and start a new one with a new `trace_id` and a `gen_ai.conversation.id` linked via a `link` attribute, or (b) emit an explicit `invoke_agent` boundary span that names the transition. - **Policy P2 (segmented partition):** `gen_ai.conversation.id` may change mid-trace, but *only* across an `invoke_agent` span, and the runtime must additionally emit `gen_ai.conversation.parent_id` (a non-standard extension) on the first span of the new segment so the partition is reconstructable. The decision boundary is **whether the rebind is causally a delegation or a continuation**. A sub-agent spawn is a delegation: P2 is correct, and the `invoke_agent` span is the marker. A compaction or resume is a continuation: P1 is correct, and the id must not change. The failure mode in "What Was Observed" is a continuation that was recorded as if it were a delegation, without the marker. The runtime conflated the two because both are "a new context window with a new id," and the GenAI conventions do not distinguish them. The guardrail is a **trace-level post-condition check**, not a per-span validation: after the root span closes, the runtime (or the collector's processor) asserts the cardinality invariant above. If cardinality > 1 and no `invoke_agent` boundary span exists between the segments, the trace is flagged `gen_ai.conversation.fractured = true` and the offending boundary span is annotated with the parent's `conversation.id`. This converts a silent aggregate corruption into a per-trace, attributable signal. ## Operational Effect Downstream, the effect is that **tool-call success rates, cost-per-success, and replay-based evaluations are computed over a partition that does not match the causal graph**. The error is not random: it systematically attributes the *consequences* of a failure (the retry, the re-verify) to the post-rebind conversation while attributing the *cause* (the original verify failure) to the pre-rebind conversation. This biases every per-conversation metric toward "the new conversation is where things go wrong," which is exactly backwards for compaction-induced rebinds, where the new segment is usually the recovery. Teams that tune retry policies against these metrics will over-retry the recovery segment and under-retry the segment that actually failed. The second effect is on **replay-based evaluation**. An evaluator that reconstructs the conversation graph from `conversation.id` and walks `parent_span_id` will, at the boundary, either drop the edge (losing the causal link between the failure and its retry) or reject the conversation (losing the whole trace). Because the evaluator logs at `WARN` and continues, the evaluation set silently shrinks by the fraction of traces that crossed a rebind—in observed runs, 12–18% of multi-step traces—and the surviving set is biased toward short, non-compacting runs. The evaluation reports a higher success rate than the system actually achieves, and the gap is exactly the compaction-heavy tail. The third effect is on **checkpoint/resume correctness**. A checkpoint that stores `conversation.id` but not the trace-level cardinality state will, on resume, either re-emit the old id (creating a duplicate span id if the runtime reuses ids) or emit a new id (creating a third segment). Neither is detectable without the trace-level post-condition. The invariant to enforce at checkpoint time is: *the checkpoint must store the full set of `conversation.id`s observed so far in the trace, and resume must not introduce a new one without an `invoke_agent` boundary.* ```python from dataclasses import dataclass, field from typing import Iterable class ConversationFractureError(RuntimeError): """Raised when a trace's conversation.id partition does not match its causal graph.""" @dataclass(frozen=True) class Span: span_id: str parent_span_id: str | None trace_id: str conversation_id: str operation_name: str agent_id: str | None = None attributes: dict = field(default_factory=dict) def validate_conversation_partition(spans: Iterable[Span]) -> None: """ Enforce the GenAI trace-level invariant: cardinality(conversation.id per trace_id) == 1 OR every non-primary segment is introduced by an invoke_agent span with a distinct gen_ai.agent.id. Raises ConversationFractureError on violation. """ by_trace: dict[str, list[Span]] = {} for s in spans: by_trace.setdefault(s.trace_id, []).append(s) for trace_id, trace_spans in by_trace.items(): # Root span defines the primary conversation. roots = [s for s in trace_spans if s.parent_span_id is None] if len(roots) != 1: raise ConversationFractureError( f"trace {trace_id}: expected exactly 1 root span, found {len(roots)}" ) primary_conv = roots[0].conversation_id primary_agent = roots[0].agent_id # Find every span whose conversation.id differs from primary. foreign = [s for s in trace_spans if s.conversation_id != primary_conv] if not foreign: continue # Each foreign segment must be introduced by an invoke_agent span # that (a) is itself the first span in its segment, and (b) names a # distinct agent. for s in foreign: is_boundary = ( s.operation_name == "invoke_agent" and s.agent_id is not None and s.agent_id != primary_agent ) if not is_boundary: parent = next( (p for p in trace_spans if p.span_id == s.parent_span_id), None ) raise ConversationFractureError( f"trace {trace_id}: span {s.span_id} " f"(op={s.operation_name}) carries conversation.id " f"{s.conversation_id!r} but parent " f"{s.parent_span_id!r} carries {primary_conv!r}; " f"no invoke_agent boundary with distinct agent_id. " f"Rebind is a continuation, not a delegation." ) def record_span(span: Span, ledger: list[Span]) -> None: """Append a span to the trace ledger, validating the partition on each write.""" ledger.append(span) try: validate_conversation_partition(ledger) except ConversationFractureError: # Annotate the offending span so the collector can attribute the fault, # then re-raise: the trace must not be exported as healthy. span.attributes["gen_ai.conversation.fractured"] = True raise ```