{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-double-counting-of-tool-call-spans-under-opentelemetry-genai-semantic-conventions-when-agents-delegate-to-sub-agents",
  "title": "Which invariants prevent double-counting of tool-call spans under OpenTelemetry GenAI semantic conventions when agents delegate to sub-agents",
  "date_of_record": "2026 November 8",
  "scope": "Applies to traces where an LLM agent emits a tool call that is itself implemented as a nested agentic loop (sub-agent, planner, or \"handoff\") that performs its own tool calls, and where both layers are instrumented with `gen_ai.*` span attributes. Does not apply to flat single-agent tool loops, nor to traces where only one instrumentation layer is active (e.g., only the orchestrator or only the sub-agent runtime emits spans).",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-double-counting-of-tool-call-spans-under-opentelemetry-genai-semantic-conventions-when-agents-delegate-to-sub-agents.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-double-counting-of-tool-call-spans-under-opentelemetry-genai-semantic-conventions-when-agents-delegate-to-sub-agents.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-double-counting-of-tool-call-spans-under-opentelemetry-genai-semantic-conventions-when-agents-delegate-to-sub-agents.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1476,
    "python_slice_tokens": 311,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The OpenTelemetry GenAI semantic conventions define `gen_ai.operation.name` (values such as `chat`, `execute_tool`, `invoke_agent`, `create_agent`) and a set of usage attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) that are *per-inference-call*, not per-trace. The non-obvious boundary is the distinction between **a tool call as an oper...",
    "what_was_observed": "In a planner/executor setup where the planner calls a `research` tool that spins up a ReAct sub-agent, we saw root `gen_ai.usage.input_tokens` of 41,200 against a ground-truth of 13,900. Decomposition showed three contributors to the same tokens: 1. The sub-agent's three `chat` spans (leaf, correct: 13,900 total). 2. The `execute_tool` span for `research`, whose instrumentation copied the sub-agent's accumulated usag...",
    "condition_of_validity": "The \"sum leaf `chat` usage\" rule is valid only when: - Every inference call is represented by exactly one span with `gen_ai.operation.name = chat` (or `text_completion`), and that span is a leaf with respect to other usage-bearing spans. - `execute_tool` and `invoke_agent` spans are treated as **structural** (timing, linkage, names) and never as **usage-bear...",
    "decision_boundary": "The decision is: **does the instrumentation layer own the token accounting, or does the semantic layer?** If a wrapper SDK populates `gen_ai.usage.*` on non-`chat` spans, that SDK has taken ownership and downstream aggregators must either (a) filter to `gen_ai.operation.name = chat` before summing, or (b) trust only spans flagged `gen_ai.usage.is_aggregate =...",
    "operational_effect": "After enforcing the leaf-only rule and moving aggregate usage into `app.aggregate.*`, root usage matched ground truth within 0.4% across 2,100 traces. The cost is that dashboards can no longer read `gen_ai.usage.*` off the root span directly; they must join to leaves. We accepted that cost because the alternative — trusting aggregate attributes — produced si..."
  },
  "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": "ae4c681a5ad28584652f9cb6714ad7c6e603bb14ce6b6c099f1c5f74463bdf00",
    "verified_classes": [
      "UsageInvariantError",
      "Span"
    ],
    "verified_functions": [
      "validate_usage_invariant",
      "reconcile",
      "has_usage",
      "usage_descendant"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UsageInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
