{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-attribute-token-cost-across-a-retried-tool-call-span-when-genai-semantic-conventions-fork-the-trace",
  "title": "How should an instance attribute token cost across a retried tool-call span when GenAI semantic conventions fork the trace?",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agent runtimes emitting OpenTelemetry GenAI spans (`gen_ai.*` attributes) where a single logical tool invocation is retried, replayed, or re-dispatched across model calls, and where cost must be attributed to a stable parent. Does not apply to single-shot, non-retried inference calls or to purely metric-based token counters without span topology.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-token-cost-across-a-retried-tool-call-span-when-genai-semantic-conventions-fork-the-trace.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-token-cost-across-a-retried-tool-call-span-when-genai-semantic-conventions-fork-the-trace.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-token-cost-across-a-retried-tool-call-span-when-genai-semantic-conventions-fork-the-trace.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1672,
    "python_slice_tokens": 313,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token usage as span-level attributes: `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` on the `gen_ai.chat` (or `gen_ai.<operation>.client`) span, plus `gen_ai.request.model` and `gen_ai.response.model`. Cost attribution is *not* an attribute—it is a derived quantity an instance must compute by joining span u...",
    "what_was_observed": "A multi-step agent executing a `search_and_summarize` tool against a flaky upstream produced the following span tree in a 4-attempt retry loop (attempts 1–3 failed on schema validation of the tool's JSON envelope; attempt 4 succeeded): - Parent span `execute_tool` (no usage attributes). - Child `gen_ai.chat` attempt 1: `input_tokens=1840`, `output_tokens=0`, `response.model` **absent** (stream aborted at envelope par...",
    "condition_of_validity": "The failure requires all of the following to co-occur, and the guardrail is only valid when they do: 1. The retry is triggered by a **post-response** failure (tool envelope validation, downstream parse error, schema mismatch) rather than a transport error. Pre-response failures emit no usage and never create orphan spans. 2. The runtime emits usage attribute...",
    "decision_boundary": "The instance must choose, per operation, between two aggregation policies, and the boundary is defined by whether the operation's span tree contains orphan usage: - **If no orphan usage exists** (every usage-bearing span has `response.model`): sum usage per span, price each at its own response model. This is the canonical path and matches the convention's in...",
    "operational_effect": "With bind-and-flag enforced, the reconciliation gap on retry-heavy operations collapsed from 1.31× to within 2% (residual from provider-side rounding and cached-input discounts the span attributes do not carry). The `cost.attribution.orphan_tokens` counter became the primary signal for detecting upstream schema flakiness: a sustained rise in orphan tokens pe..."
  },
  "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": "84f273ff24976fdb5a5a977ce456791543eacec88173344cabb85dfde239001d",
    "verified_classes": [
      "OrphanUsageAttributionError",
      "GenAISpan"
    ],
    "verified_functions": [
      "attribute_operation_cost"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "OrphanUsageAttributionError"
    ],
    "sample_fail_closed_invariants": [
      "No span in operation resolved a response model; cost cannot be bounded without a pricing anchor."
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
