{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-attributes-child-span-token-counts-to-the-parent-turn-double-counting-under-opentelemetry-genai-spans-and-the-per-span-s",
  "title": "What happens when an instance attributes child-span token counts to the parent turn: double-counting under OpenTelemetry GenAI spans and the per-span single-writer invariant",
  "date_of_record": "2026 December 1",
  "scope": "Applies to LLM agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) across multi-turn conversations, where tool-call spans are nested under a turn span and token usage is reported on more than one span in the same trace. Does not apply to single-span, single-turn inference telemetry or to systems that export only aggregated metrics without span-level attributes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-child-span-token-counts-to-the-parent-turn-double-counting-under-opentelemetry-genai-spans-and-the-per-span-s.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-child-span-token-counts-to-the-parent-turn-double-counting-under-opentelemetry-genai-spans-and-the-per-span-s.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-child-span-token-counts-to-the-parent-turn-double-counting-under-opentelemetry-genai-spans-and-the-per-span-s.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1305,
    "python_slice_tokens": 228,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) as properties of a *single model invocation*. They do not define an aggregation contract for a *turn* that contains multiple invocations. The distinction that breaks is between **the span that owns the usage measurement** and **the span that sum...",
    "what_was_observed": "A planner/executor agent emitted a turn span (`agent.turn`) with three children: two tool-call spans that each wrapped a model invocation (`gen_ai.operation.name=chat`), and a final synthesis chat span. The executor, wanting per-turn cost visibility, set `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` on the turn span to the sum of its children after the turn completed. A budget governor subscribed to th...",
    "condition_of_validity": "The single-writer invariant is valid when and only when: - Usage attributes are written **only** on spans whose `gen_ai.operation.name` is a model operation (`chat`, `text_completion`, `embeddings`), never on orchestration spans (`agent.turn`, `agent.tool`, `execute_tool`). - Turn-level totals, if needed, are emitted as **distinct attribute names** (e.g., `a...",
    "decision_boundary": "The boundary is whether the parent span's usage is **derived data** or **measured data**. If derived, it must not reuse the `gen_ai.usage.*` namespace, because that namespace is defined as measurement. The moment a parent writes into the measurement namespace, the trace becomes ambiguous to any consumer that cannot distinguish \"this span measured N tokens\" f...",
    "operational_effect": "After the runtime moved turn totals to `agent.turn.total_input_tokens` and stripped `gen_ai.usage.*` from all non-model spans, the governor's summed value matched actual billed tokens within 0.3% (residual from streaming usage arriving after span end). The truncation failures stopped. The cost: dashboards that had been reading parent-span usage had to switch..."
  },
  "matched_failure_symptoms": [
    "SUBPROCESS_PIPE_HANG_OR_FD_LEAK"
  ],
  "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": "f116ac21722078218f71747aae86280a0a207a2b4d4b959fa674cfbc7559d9a0",
    "verified_classes": [
      "GenAIUsageAttributionError",
      "Span"
    ],
    "verified_functions": [
      "validate_usage_ownership",
      "sum_trace_tokens",
      "operation",
      "carries_usage"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "GenAIUsageAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
