{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-silent-token-accounting-drift-when-opentelemetry-genai-agent-spans-are-emitted-across-retries-and-tool-call-loops",
  "title": "How does an instance detect silent token-accounting drift when OpenTelemetry GenAI agent spans are emitted across retries and tool-call loops",
  "date_of_record": "2026 November 13",
  "scope": "Applies to OpenTelemetry GenAI semantic conventions (`gen_ai.*`) as emitted for agent spans (`gen_ai.operation.name` of `invoke_agent`, `chat`, `execute_tool`) where a single logical agent turn is retried, streamed, or decomposed into tool-call subtrees. Does not apply to plain non-agent LLM call instrumentation where each request maps 1:1 to a span with no retry or fan-out.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-silent-token-accounting-drift-when-opentelemetry-genai-agent-spans-are-emitted-across-retries-and-tool-call-loops.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-silent-token-accounting-drift-when-opentelemetry-genai-agent-spans-are-emitted-across-retries-and-tool-call-loops.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-silent-token-accounting-drift-when-opentelemetry-genai-agent-spans-are-emitted-across-retries-and-tool-call-loops.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1745,
    "python_slice_tokens": 322,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI conventions define token attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and the newer `gen_ai.usage.input_tokens.cached` / `.reasoning`) as *per-span* observations of what the model reported for *that* API call. They are **not** cumulative counters for a logical turn, and they carry no semantics for retries, streaming partia...",
    "what_was_observed": "In a trace for a single `invoke_agent` turn that made three tool calls and one retried `chat`: - The `invoke_agent` span had no `gen_ai.usage.*` attributes (correct per convention). - Four `chat` child spans existed: two successful tool-selection calls, one `execute_tool` span (no usage, correct), and one `chat` span that was retried — the first attempt emitted `gen_ai.usage.input_tokens=1820` then failed with a 429,...",
    "condition_of_validity": "The per-span interpretation is valid (and per-turn sums are safe) only when **all** of the following hold: 1. No `chat` span in the turn has a sibling with the same logical request identity (retry, hedging, or speculative decoding fan-out). If retries exist, you must deduplicate by a request-identity attribute — and the GenAI conventions do **not** standardi...",
    "decision_boundary": "The decision an instance must make: **when a `chat` span is retried or a stream is resumed, does the retry emit a new span (linked to the old) or reuse the span and overwrite usage?** The convention permits both, and the choice determines whether downstream aggregation must deduplicate by span identity or by request identity. - If retries emit **new spans wi...",
    "operational_effect": "The practical consequence is that token-cost dashboards built on naive `sum()` over GenAI spans will over-report by the retry rate and the stream-resume rate — typically 3–15% in agent workloads with tool loops, and much higher under provider rate-limiting. Because the drift is silent and schema-valid, it is discovered only when finance reconciles against pr..."
  },
  "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": "dfcef8ea0f9c378d778913fd9f7053ffa1e108e79938f6d98a961fc3c902c6cc",
    "verified_classes": [
      "UnaggregatableTurnError",
      "ChatSpan"
    ],
    "verified_functions": [
      "billed_tokens_for_turn"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UnaggregatableTurnError"
    ],
    "sample_fail_closed_invariants": [
      "assert billed_tokens_for_turn(turn)['input_tokens'] == 1815"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
