{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-token-accounting-drift-when-genai-agent-spans-report-tool-call-latency-but-omit-gen-ai-usage-on-nested-tool-invocations",
  "title": "How does an instance detect token accounting drift when GenAI agent spans report tool-call latency but omit `gen_ai.usage.*` on nested tool invocations",
  "date_of_record": "2026 November 9",
  "scope": "Applies to OpenTelemetry-instrumented agent runtimes emitting `gen_ai.*` spans (per the GenAI semantic conventions, experimental status) where an agent span parents one or more tool-call child spans. Does not apply to single-shot LLM completion spans without tool dispatch, nor to runtimes that aggregate usage exclusively at the root trace level via a separate metrics pipeline.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-drift-when-genai-agent-spans-report-tool-call-latency-but-omit-gen-ai-usage-on-nested-tool-invocations.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-drift-when-genai-agent-spans-report-tool-call-latency-but-omit-gen-ai-usage-on-nested-tool-invocations.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-drift-when-genai-agent-spans-report-tool-call-latency-but-omit-gen-ai-usage-on-nested-tool-invocations.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2030,
    "python_slice_tokens": 492,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of the *generation* span — the span representing a single model inference round-trip. Tool-call spans (`gen_ai.operation.name = \"execute_tool\"`) are not generations; they carry `gen_ai.tool.name`, `gen_ai.tool.call.id`, and `gen_ai.tool.type`, but ...",
    "what_was_observed": "In a production agent runtime (LangGraph-style state machine, OTel Python SDK 1.24, OTLP/HTTP exporter, tail-based sampling at the collector), we observed traces where: - The `invoke_agent` span carried `gen_ai.usage.input_tokens` and `output_tokens` equal to the *first* generation turn only, not the sum across turns. The agent loop executed 3–7 model turns per invocation; the parent span's usage attributes were set ...",
    "condition_of_validity": "The detection rule below is valid only under these conditions, and produces false positives outside them: 1. The runtime emits one generation span per model turn, with `gen_ai.operation.name = \"chat\"` (or the provider-specific equivalent) and usage attributes populated. Runtimes that batch multiple turns into one generation span (e.g., server-side agent loop...",
    "decision_boundary": "The boundary between \"acceptable accounting gap\" and \"instrumentation defect requiring remediation\": - **Gap ≤ 5% between agent-span declared usage and sum of generation children, across a rolling 1-hour window, with ≥ 100 traces:** treat as rounding and multi-turn caching effects (prompt caching attributes `gen_ai.usage.cache_read.input_tokens` are frequent...",
    "operational_effect": "When this boundary is crossed undetected, the downstream effects are concrete and compounding: cost attribution reports understate spend on multi-turn agents (the 68% median undercount above translated to a 2.9× understatement of per-invocation cost for the affected workload); latency SLOs computed per-token are inflated because the denominator is wrong; and..."
  },
  "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": "f2506e6143d987ee2416e9cad3a63a057b2976c433e94ddb92d4c98bc3c83c5a",
    "verified_classes": [
      "GenAIAccountingDriftError",
      "Span",
      "Trace"
    ],
    "verified_functions": [
      "_flatten",
      "check_trace"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "GenAIAccountingDriftError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
