{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-an-agent-span-has-silently-double-counted-tokens-across-a-retried-model-invocation",
  "title": "What structural signals indicate an agent span has silently double-counted tokens across a retried model invocation",
  "date_of_record": "2026 December 2",
  "scope": "Applies to agents emitting OpenTelemetry GenAI spans (`gen_ai.*` attributes) where a single logical \"model invocation\" step is retried at the SDK, transport, or orchestration layer while the span lifecycle is not. Does not cover streaming-only token reconciliation or cost-accounting outside the OTel pipeline.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-an-agent-span-has-silently-double-counted-tokens-across-a-retried-model-invocation.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-an-agent-span-has-silently-double-counted-tokens-across-a-retried-model-invocation.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-an-agent-span-has-silently-double-counted-tokens-across-a-retried-model-invocation.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1398,
    "python_slice_tokens": 324,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a model invocation as a *span* with `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` recorded as span attributes, and (in newer drafts) as discrete `gen_ai.client.inference.operation.details` events. The convention assumes a one-to-one mapping: one span, one billable invocation, one token count. That assumptio...",
    "what_was_observed": "A tool-using agent (planner → retrieval tool → synthesis model call) showed a 40% cost overrun against provider-side billing, with no error spans and no `status.code = ERROR`. Tracing the span tree revealed the mechanism: 1. The synthesis step opened a span `gen_ai.client.inference` with `gen_ai.request.model = \"...\"` and `gen_ai.operation.name = \"chat\"`. 2. The first HTTP attempt returned `429` after emitting 312 pr...",
    "condition_of_validity": "The invariant — \"sum of `gen_ai.usage.*` across a span equals the usage of exactly one provider invocation\" — holds only when: - The instrumentation emits exactly one inference-details event per span, **and** - Retry logic opens a child span (or a sibling span with `retry.attempt` semantics) per physical attempt rather than reusing the parent span scope, **a...",
    "decision_boundary": "An agent or telemetry auditor should treat a span's `gen_ai.usage.*` as **untrusted for cost decisions** and fall back to event-level accounting when it observes any of: - `count(inference.operation.details events) < number of transport attempts implied by retry metadata`, or - `gen_ai.usage.input_tokens` exceeds `gen_ai.request.max_tokens` for the model whe...",
    "operational_effect": "Once an agent's budget governor starts reading double-counted spans, it trips its token ceiling early, truncates the plan, and escalates — producing a *functional* failure (premature re-planning) that looks like a reasoning failure but is a telemetry artifact. The fix is to make the invariant structural: one span per physical attempt, usage attributes scoped..."
  },
  "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": "1a2802f7178a19bad03bcfd30c036152bed826333fc462b2572aed34f9852823",
    "verified_classes": [
      "TokenAccountingInvariantError",
      "InferenceEvent",
      "GenAISpan"
    ],
    "verified_functions": [
      "reconcile_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
