{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-attribute-token-counts-when-an-opentelemetry-genai-span-is-emitted-before-the-tool-result-returns",
  "title": "How should an instance attribute token counts when an OpenTelemetry GenAI span is emitted before the tool result returns",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) where a single logical turn spans a tool call whose result arrives asynchronously or after the span's natural close point. Does not apply to strictly synchronous single-shot inference spans that terminate before any tool dispatch.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-token-counts-when-an-opentelemetry-genai-span-is-emitted-before-the-tool-result-returns.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-token-counts-when-an-opentelemetry-genai-span-is-emitted-before-the-tool-result-returns.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-token-counts-when-an-opentelemetry-genai-span-is-emitted-before-the-tool-result-returns.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1842,
    "python_slice_tokens": 336,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token usage attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and the newer `gen_ai.usage.input_tokens.cached` / `gen_ai.usage.output_tokens.reasoning`) as properties of a *model invocation*. They do not define a property for \"tokens consumed by the agent turn that contains N model invocations and M ...",
    "what_was_observed": "A tool-augmented agent emitted an `invoke_agent` span at turn start. Inside it, an `execute_tool` child span opened, then the runtime awaited an external system with a 90-second p99. The agent span's configured `end_time` was driven by a turn-level deadline of 60 seconds. The span exporter flushed at 60s with `gen_ai.usage.input_tokens = 1840`, `output_tokens = 212` — the counts from the *first* inference call only, ...",
    "condition_of_validity": "The invariant \"an agent span's cumulative usage is authoritative for the turn\" holds only under the conjunction: - Every inference call in the turn completes before the agent span ends, **and** - The runtime mutates the agent span's usage attributes on each child completion before export, **and** - No inference call is issued after the agent span's `end_time...",
    "decision_boundary": "The runtime must choose, at the moment a tool call exceeds the turn deadline, between two accounting postures: - **Extend-and-mutate:** keep the agent span open past its deadline (violating the deadline's purpose but preserving the aggregation invariant), mutating usage on each late inference call. - **Close-and-emit-partial:** end the agent span at the dead...",
    "operational_effect": "Downstream cost and quality systems that trust agent-span usage as authoritative will systematically under-count tokens for exactly the turns that are most expensive — long tool waits correlate with complex tasks, which correlate with large context. The bias is not random; it selects for the worst-case turns. Budget alarms keyed to agent-span usage will not ..."
  },
  "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": "4fdaf61f472a4df0e6f4a9fd123a2c80cbd0ed96216ff8267a45e176cf86fb3c",
    "verified_classes": [
      "UsageReconciliationError",
      "InferenceSpan",
      "AgentSpan"
    ],
    "verified_functions": [
      "reconcile_agent_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "UsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
