{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-opentelemetry-genai-spans-for-a-retried-tool-call-without-resetting-the-span-s-token-and-attempt-attributes",
  "title": "What happens when an instance emits OpenTelemetry GenAI spans for a retried tool call without resetting the span's token and attempt attributes",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agent runtimes that instrument model invocations and tool calls with OpenTelemetry GenAI semantic conventions (`gen_ai.*` attributes) and that retry, fall back, or re-dispatch a single logical step across multiple physical attempts. Does not cover pure tracing of non-agent HTTP services or span export/collector configuration issues.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-opentelemetry-genai-spans-for-a-retried-tool-call-without-resetting-the-span-s-token-and-attempt-attributes.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-opentelemetry-genai-spans-for-a-retried-tool-call-without-resetting-the-span-s-token-and-attempt-attributes.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-opentelemetry-genai-spans-for-a-retried-tool-call-without-resetting-the-span-s-token-and-attempt-attributes.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2007,
    "python_slice_tokens": 452,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters here is between a **logical step** and a **physical attempt**. An agent's planner reasons in terms of logical steps: \"call `search_docs`\", \"invoke `gpt-4o` to summarize\". The GenAI semantic conventions, however, describe **physical invocations**: each `gen_ai.client.inference.operation.details` / `gen_ai.chat` span and each `exec...",
    "what_was_observed": "A tool-calling agent with a `execute_tool` span per logical tool step, instrumented with `gen_ai.operation.name = \"execute_tool\"`, `gen_ai.tool.name`, and `gen_ai.tool.call.id`. The transport layer wrapped the call in a retry decorator (3 attempts, exponential backoff) to absorb transient 429/503s from the tool backend. On a run where the first attempt returned HTTP 503 *after* the backend had already consumed the re...",
    "condition_of_validity": "The invariant \"one span = one physical invocation\" holds only when the following conditions are jointly true: 1. **The retry decorator sits *outside* the span-creation boundary**, i.e., each attempt opens and closes its own span. If the decorator wraps the span (span created once, retried inside), the invariant is violated by construction. 2. **Usage attribu...",
    "decision_boundary": "The boundary is drawn at the point where the runtime decides whether to reuse or re-create the span. The decision rule: - **Reuse the span** only for attributes that are genuinely attempt-invariant: `gen_ai.system`, `gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.request.model` (the *intended* model). These are properties of the logical step. - **Create...",
    "operational_effect": "The downstream consequences are concrete and measurable: - **Token accounting drift.** Aggregated `gen_ai.usage.*` undercounts by the sum of failed-attempt tokens. In a retry-heavy workload (say 8% of steps retry once), the billed-vs-traced delta is ~8% of step cost, which is large enough to invalidate per-agent budget enforcement that keys off trace-derived..."
  },
  "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": "1762691e5111c2a9ae47713e2b4ac9a41ce67eb1bccc3d49cd5a4713151b6c0b",
    "verified_classes": [
      "GenAISpanInvariantError",
      "GenAISpan"
    ],
    "verified_functions": [
      "retried_tool_call",
      "set_attribute",
      "set_status",
      "finish"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "GenAISpanInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
