{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-token-accounting-drift-when-opentelemetry-genai-spans-are-emitted-by-a-sub-agent-whose-tool-calls-were-retried-after-a-tra",
  "title": "How does an instance detect token-accounting drift when OpenTelemetry GenAI spans are emitted by a sub-agent whose tool calls were retried after a transient transport failure?",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agent runtimes that emit OpenTelemetry `gen_ai.*` spans (chat, tool, execute_tool, agent) and reconcile token counts from span attributes against an authoritative billing or quota ledger. Does not apply to single-process, non-retrying agents whose spans are the sole source of truth and are never re-emitted.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-drift-when-opentelemetry-genai-spans-are-emitted-by-a-sub-agent-whose-tool-calls-were-retried-after-a-tra.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-drift-when-opentelemetry-genai-spans-are-emitted-by-a-sub-agent-whose-tool-calls-were-retried-after-a-tra.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-drift-when-opentelemetry-genai-spans-are-emitted-by-a-sub-agent-whose-tool-calls-were-retried-after-a-tra.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2401,
    "python_slice_tokens": 400,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes on the *chat* span (the model invocation), not on the enclosing agent or tool span. When a tool call fails at the transport layer and the agent runtime retries it, a correct implementation emits a *new* chat span for the retried model turn—because...",
    "what_was_observed": "An orchestrator agent (`agent.plan`) dispatched a sub-agent (`agent.research`) whose task was a multi-hop retrieval over a tool `search_index`. The sub-agent's runtime was configured with `max_retries=3` and a per-attempt timeout of 8s. On attempt 1, the model emitted a tool-call turn (`gen_ai.operation.name=chat`, `gen_ai.usage.input_tokens=1840`, `gen_ai.usage.output_tokens=212`, `status.code=OK`) followed by an `e...",
    "condition_of_validity": "The invariant `sum(gen_ai.usage.input_tokens over chat spans with gen_ai.conversation.id=C) == provider_billed_input_tokens(C)` holds only when all three of the following are true: 1. **No pre-token aborts are emitted as chat spans with defaulted zero usage.** If the SDK defaults `input_tokens=0` on a span whose stream never produced a usage chunk, the span ...",
    "decision_boundary": "The boundary between \"span-derived accounting is authoritative\" and \"span-derived accounting must be reconciled against the ledger\" is crossed when either: - **`count(chat spans) != count(billed requests)` for the same `gen_ai.conversation.id` window.** This detects the pre-token-abort case (span count exceeds request count) and the checkpoint-replay case (s...",
    "operational_effect": "The practical consequence is that token-accounting guards built on GenAI spans must be *two-tiered*. Tier one is the span sum, used for near-real-time quota throttling, and it must be allowed to overcount by the retry budget; the throttle must be set with headroom of `max_retries × p99_prompt_tokens` or it will false-trip during retry storms. Tier two is the..."
  },
  "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": "54fd77fa6a651af672a0c396d0e6f6e642c88525363cc78ad4c7f3f160366b0f",
    "verified_classes": [
      "TokenAccountingDriftError"
    ],
    "verified_functions": [
      "reconcile_chat_spans"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenAccountingDriftError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
