{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-attributes-child-span-token-usage-to-the-wrong-genai-semantic-convention-generation",
  "title": "What happens when an instance attributes child-span token usage to the wrong GenAI semantic convention generation",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agents emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where a parent agent span fans out to child tool-call and chat spans, and where the collector or backend aggregates `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` for cost and budget enforcement. Does not apply to single-span, non-nested instrumentation, nor to backends that only consume raw span payloads without cross-span aggregation.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-child-span-token-usage-to-the-wrong-genai-semantic-convention-generation.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-child-span-token-usage-to-the-wrong-genai-semantic-convention-generation.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-child-span-token-usage-to-the-wrong-genai-semantic-convention-generation.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1756,
    "python_slice_tokens": 367,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two incompatible ways an agent span tree can describe token usage, and they are not distinguishable from the attribute values alone: 1. **Inclusive accounting** — the parent agent span carries the *sum* of all descendant chat spans' token usage, and children carry their own usage. This is the model implied by naive \"wrap the whole run in a span and...",
    "what_was_observed": "A tool-using agent was instrumented with a run-level span `agent.run` (`gen_ai.operation.name = \"invoke_agent\"`) that, at completion, set `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` to the run total reported by the orchestrator's own counter. Three child `chat` spans (`gen_ai.operation.name = \"chat\"`) each set their own per-call usage, and two nested `execute_tool` spans set none. The trace was valid...",
    "condition_of_validity": "The exclusive-accounting invariant holds only when: - Every span carrying `gen_ai.usage.*` is a leaf chat/embedding span, **or** - Every non-leaf span carrying `gen_ai.usage.*` is explicitly marked with a disambiguating attribute (e.g. `gen_ai.usage.aggregate = true` or a custom `agent.usage.rollup = \"inclusive\"`) that the backend is configured to exclude fr...",
    "decision_boundary": "The decision the instrumenting agent must make at span-emit time: - **If the backend aggregates by leaf-sum** (the common default for GenAI cost tooling), then non-leaf spans MUST NOT emit `gen_ai.usage.*`. The run total is a derived query, never a stamped attribute. Cost dashboards read it from the leaf sum. - **If the backend aggregates by span-max or by e...",
    "operational_effect": "Downstream, the inflated total propagates into budget-enforcement state, and because the agent's halting logic reads that state, the corruption feeds back into agent behavior: the agent under-spends, truncates, and skips tool calls it would otherwise make. The trace remains green; the agent silently degrades. Recovery requires (a) identifying every non-leaf ..."
  },
  "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": "bef895ba016d47460598fa0ecfdc1efaf5b8c7e232f0be57c80b0092002e5f45",
    "verified_classes": [
      "TokenAccountingInvariantError",
      "Span"
    ],
    "verified_functions": [
      "_walk",
      "verify_token_accounting",
      "enforce_or_halt"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
