{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-opentelemetry-genai-span-graphs-from-silently-orphaning-tool-call-edges-across-multi-turn-agent-invocations",
  "title": "Which invariants prevent OpenTelemetry GenAI span graphs from silently orphaning tool-call edges across multi-turn agent invocations",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agents that emit OpenTelemetry GenAI spans (`gen_ai.*`) where a single user turn fans out into nested tool-call spans and where the same agent instance is resumed across turns (checkpoint/resume, stateless re-invocation with replayed history). Does not apply to single-shot completions with no tool calls, nor to agents whose span export is synchronous and strictly parented within one process lifetime.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-opentelemetry-genai-span-graphs-from-silently-orphaning-tool-call-edges-across-multi-turn-agent-invocations.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-opentelemetry-genai-span-graphs-from-silently-orphaning-tool-call-edges-across-multi-turn-agent-invocations.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-opentelemetry-genai-span-graphs-from-silently-orphaning-tool-call-edges-across-multi-turn-agent-invocations.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1692,
    "python_slice_tokens": 352,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"missing spans.\" It is **span-graph edge orphaning under turn resumption**: a tool-call span that was correctly parented to turn N's invocation span gets re-emitted, re-linked, or re-counted under turn N+1 because the agent's runtime reconstructs its context from a serialized transcript rather than from a live trace context. The GenAI sema...",
    "what_was_observed": "A three-turn agent (`gen_ai.conversation.id = conv-7f2a`) using a stateless executor. Each turn the orchestrator deserialized the prior transcript, re-attached a fresh root `invoke_agent` span, and replayed the message list. On turn 2, the model requested a tool already invoked on turn 1 (`gen_ai.tool.name = \"search_docs\"`). Observed trace shape: - Turn 1: `invoke_agent` (root) → `execute_tool search_docs` (child, re...",
    "condition_of_validity": "The invariant that must hold is: > For a given `gen_ai.conversation.id`, every `execute_tool` span with a given `gen_ai.tool.call.id` is emitted **exactly once**, and its parent is the `invoke_agent` span of the turn whose model output actually requested it. Replayed tool results must appear as *attributes or events on the new invocation span* (e.g., a `gen_...",
    "decision_boundary": "The boundary is: **does the runtime own the trace context, or does it own only the transcript?** - If the runtime owns trace context (live `SpanContext` threaded through the executor), parent-child edges are trustworthy and the only risk is late-export ordering — solvable by forcing child flush before parent close. - If the runtime owns only the transcript (...",
    "operational_effect": "With the invariant enforced (new root per turn + `links` to prior root + replay events instead of re-emitted tool spans), cost attribution per conversation becomes additive and correct, causal traversal from decision to evidence is intact via links, and late-arriving spans cannot create phantom parents. Without it, the trace is a plausible-looking fiction: t..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "ddc3c2aa5e9ee094a80985330f8269dc084777d33566edb689d2aa547b265a82",
    "verified_classes": [
      "SpanGraphInvariantError",
      "SpanRecord",
      "ConversationSpanRegistry"
    ],
    "verified_functions": [
      "open_turn_root",
      "close_turn_root",
      "emit_tool_call",
      "record_replayed_tool_result"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "SpanGraphInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
