{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-parent-agent-spans-from-double-counting-tokens-when-child-tool-call-spans-re-emit-model-invocation-events",
  "title": "Which invariants prevent parent-agent spans from double-counting tokens when child tool-call spans re-emit model invocation events",
  "date_of_record": "2026 November 12",
  "scope": "Applies to agent frameworks that instrument tool-call trees where a child span (tool execution, sub-agent invocation, or retrieval step) performs its own LLM call and emits `gen_ai.client.token.usage` / `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` attributes on that child span. Does not apply to single-shot chat completions with no nested spans, nor to frameworks that aggregate usage exclusively at the root via a separate accounting layer.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-parent-agent-spans-from-double-counting-tokens-when-child-tool-call-spans-re-emit-model-invocation-events.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-parent-agent-spans-from-double-counting-tokens-when-child-tool-call-spans-re-emit-model-invocation-events.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-parent-agent-spans-from-double-counting-tokens-when-child-tool-call-spans-re-emit-model-invocation-events.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1584,
    "python_slice_tokens": 205,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two structurally different ways token usage can appear in a span tree, and they are indistinguishable from attributes alone: 1. **Inclusive usage** — the parent span's `gen_ai.usage.*` attributes represent the sum of the parent's own model call plus all descendant model calls. This is the \"rollup\" convention. 2. **Exclusive usage** — the parent spa...",
    "what_was_observed": "A multi-tool agent (planner → 3 parallel tool calls, each of which internally called a small classifier model → synthesizer) produced a span tree where the root `invoke_agent` span reported `gen_ai.usage.input_tokens = 4820`. The three child tool spans each reported `gen_ai.usage.input_tokens` of roughly 1100–1400. The synthesizer child reported 900. A dashboard summing `input_tokens` across all spans reported 4820 +...",
    "condition_of_validity": "The double-count hazard is *inert* (no accounting error) when and only when at least one of the following holds: - Every span in the tree is instrumented by a library using the **same** accounting semantics (all inclusive or all exclusive), *and* the collector's aggregation matches that semantics. - The collector aggregates **only leaf spans** and every mode...",
    "decision_boundary": "When building or auditing an agent instrumentation, the decision is not \"should I emit usage on the parent\" but \"does any span in this tree simultaneously own a model invocation and contain model-invoking children.\" If yes, you must choose one of: - **Exclusive everywhere:** parent emits usage only for its own direct `chat`/`embeddings` call; children emit t...",
    "operational_effect": "Downstream consumers — cost dashboards, rate-limit governors, budget alerts, and trace-based evals that weight by token count — inherit whichever semantics the leaf-most instrumentation happened to use, silently. A budget governor that sums all spans will trip early on inclusive-instrumented trees (overcount) and never trip on exclusive-instrumented trees ag..."
  },
  "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": "5ab6fd846faeba7dd66aae5e582148eeadb257e2e73b8f71ce7a88ef7d4c9c4e",
    "verified_classes": [
      "AmbiguousTokenAccountingError"
    ],
    "verified_functions": [
      "aggregate_input_tokens",
      "has_usage",
      "usage_bearing_descendants"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "AmbiguousTokenAccountingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
