{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-the-causal-chain-when-opentelemetry-genai-spans-are-emitted-per-turn-but-the-agent-loop-re-enters-a-tool-call-after-a-retry",
  "title": "Why does an instance lose the causal chain when OpenTelemetry GenAI spans are emitted per-turn but the agent loop re-enters a tool call after a retry?",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.*` attributes) across multi-turn loops with tool calls and retries. Does not apply to single-shot inference where one span equals one completion, nor to tracing systems that propagate context exclusively via W3C `traceparent` without any per-turn span re-parenting logic.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-the-causal-chain-when-opentelemetry-genai-spans-are-emitted-per-turn-but-the-agent-loop-re-enters-a-tool-call-after-a-retry.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-the-causal-chain-when-opentelemetry-genai-spans-are-emitted-per-turn-but-the-agent-loop-re-enters-a-tool-call-after-a-retry.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-the-causal-chain-when-opentelemetry-genai-spans-are-emitted-per-turn-but-the-agent-loop-re-enters-a-tool-call-after-a-retry.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1929,
    "python_slice_tokens": 419,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not a missing span or a dropped attribute. It is a **causal-parent inversion** that occurs when an agent loop retries a tool invocation: the retried tool-call span is emitted as a *sibling* of the original attempt rather than a *child* of the turn that decided to retry. The trace remains structurally valid—every span has a `parent_span_id`, th...",
    "what_was_observed": "An agent runtime (loop: `chat → tool_call → chat → …`) emitted the following on a flaky tool that failed once and succeeded on retry: - Turn 1: `gen_ai.chat` span `S1` (root, `gen_ai.operation.name=chat`). Model returns a tool-call request for `search`. - Tool attempt 1: span `S2`, `gen_ai.operation.name=execute_tool`, `gen_ai.tool.name=search`, parent = `S1`. Returns error. - Retry logic lives in a wrapper *outside*...",
    "condition_of_validity": "The invariant that must hold for GenAI spans to be causally sound is: > For any `gen_ai.tool.call` span `T` and the `gen_ai.chat` span `C` whose model output named `T`'s tool, `T.parent_span_id == C.span_id`. For any retry `T'` of `T`, `T'.parent_span_id == C.span_id` **and** `T'` carries `gen_ai.tool.call.retry_count` (or equivalent) so it is distinguishabl...",
    "decision_boundary": "The boundary is: **does the retry wrapper own context creation, or does the turn loop?** - If the **turn loop** owns it, each turn attaches a fresh context; retries inside the loop inherit the correct parent. Safe. - If the **retry wrapper** owns it (common when retries are a generic decorator applied around tool functions), the wrapper captures context at d...",
    "operational_effect": "The observable consequence is a **silent degradation of every trace-derived metric that depends on causal edges**: per-decision cost, retry rate, tool-failure attribution, and replay fidelity all read from `parent_span_id`. Because the trace passes schema validation (all required `gen_ai.*` attributes present, parent IDs non-null, trace ID consistent), no al..."
  },
  "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": "6e7ac7cce1b5d4b6e987b26813ca4344bb8ce0476879b54fcfbf8d4885a1ffda",
    "verified_classes": [
      "CausalParentInversion",
      "Span"
    ],
    "verified_functions": [
      "assert_genai_causal_integrity",
      "emit_tool_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "CausalParentInversion"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
