{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-double-counting-and-orphaned-tool-spans-when-opentelemetry-genai-semconv-attributes-collide-across-retry-streaming-and-nested",
  "title": "Which invariants prevent double-counting and orphaned tool spans when OpenTelemetry GenAI semconv attributes collide across retry, streaming, and nested agent boundaries",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) for chat, tool-call, and agent-execution spans, especially when retries, streaming responses, and nested child agents share a single trace. Does not apply to pure request-level HTTP metrics or to runtimes that flatten all agent activity into a single span with no child tool spans.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-double-counting-and-orphaned-tool-spans-when-opentelemetry-genai-semconv-attributes-collide-across-retry-streaming-and-nested.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-double-counting-and-orphaned-tool-spans-when-opentelemetry-genai-semconv-attributes-collide-across-retry-streaming-and-nested.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-double-counting-and-orphaned-tool-spans-when-opentelemetry-genai-semconv-attributes-collide-across-retry-streaming-and-nested.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1564,
    "python_slice_tokens": 378,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semconv is a *descriptive* attribute schema, not a *reconciliation* protocol. It tells you how to name a `gen_ai.operation.name`, how to attach `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`, and how to label a `gen_ai.tool.name` on an execute-tool span. It does **not** specify an invariant that guarantees, across a retried or streamed ...",
    "what_was_observed": "A supervisor agent (`gen_ai.operation.name = \"invoke_agent\"`, `gen_ai.agent.name = \"supervisor\"`) delegated to a child agent (`gen_ai.agent.name = \"researcher\"`) inside a single trace. The child made a streaming chat call to a model, received a tool-call delta for `search_web` with `gen_ai.tool.call.id = \"call_9f2\"`, and the SDK's retry middleware retried the *chat* span once after a 529, then the tool executed. The ...",
    "condition_of_validity": "The single-charge invariant holds **only if** the runtime guarantees that `gen_ai.usage.*` attributes are emitted on exactly one span per *logical* model invocation, and that retried attempts are represented as either (a) child spans under the logical invocation with usage suppressed on retries, or (b) sibling spans each carrying an explicit `gen_ai.request....",
    "decision_boundary": "The boundary is: **does the runtime treat the span as the unit of accounting, or the logical invocation as the unit of accounting?** If the span is the unit, retries inflate totals and duplicate tool ids — acceptable only if downstream consumers deduplicate on `gen_ai.response.id` or an attempt index. If the logical invocation is the unit, the runtime MUST s...",
    "operational_effect": "Unreconciled, this failure corrupts cost attribution (retried prompts charged twice), breaks tool-audit pipelines (orphan and duplicate tool-call ids), and — most dangerously — makes a *failed* child agent look *successful* because its re-parented chat span still carries a completion event. Downstream evaluators reading the trace conclude the child produced ..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION"
  ],
  "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": "4d1bf0da0bc2293d910f781783d6622c6dbc7d4844c155c99addf7acffcce266",
    "verified_classes": [
      "GenAITraceInvariantError",
      "Span"
    ],
    "verified_functions": [
      "reconcile_agent_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "GenAITraceInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
