{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-tool-call-mutates-its-own-token-accounting-mid-execution",
  "title": "Where must an instance reconcile OpenTelemetry GenAI span attributes when a tool call mutates its own token accounting mid-execution?",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agents that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) around LLM invocations and tool executions, where token counts and finish reasons are recorded at span end. Does not address distributed trace sampling policy or exporter backpressure.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-tool-call-mutates-its-own-token-accounting-mid-execution.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-tool-call-mutates-its-own-token-accounting-mid-execution.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-tool-call-mutates-its-own-token-accounting-mid-execution.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1579,
    "python_slice_tokens": 237,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as **terminal attributes** — values written once when the span closes, describing the completed inference. But an agent loop does not have one inference; it has a chain. When a tool call returns content that the agent feeds back into a *second* LLM turn within t...",
    "what_was_observed": "A three-turn agent task (plan → tool call → synthesize) emitted the following, captured from an OTLP collector before export: - Turn 1 LLM span: `input_tokens=1840, output_tokens=210`, closed at t=0.0s. - Tool span: no usage attributes (correct — tool spans carry `gen_ai.operation.name=execute_tool`, not token counts). - Turn 2 LLM span: `input_tokens=2260, output_tokens=430`, closed at t=1.9s. - Turn 3 LLM span: `in...",
    "condition_of_validity": "The invariant that must hold is: **a parent agent span's aggregated `gen_ai.usage.*` attributes are valid only if every child LLM span has been finalized and its usage attributes committed before the parent's aggregation reads them.** This is a happens-before edge that the semantic conventions do not specify, because they describe attribute *names and types*...",
    "decision_boundary": "The boundary is between two defensible designs, and the choice determines where the guardrail lives: - **Aggregate-at-end (fragile):** Parent reads child usage at its own `end()`. Requires an explicit barrier — the parent must not end until all children have ended. This is only safe if the orchestrator awaits all child finalization, which most agent loops do...",
    "operational_effect": "Without the barrier, the failure is silent and *biased low* — the parent always under-counts, because it reads before the last child commits. A low-biased budget signal is worse than a missing one: it makes the watchdog trust headroom that does not exist, and the resulting overflow surfaces as truncated tool output rather than a budget exception, so the root..."
  },
  "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": "d96cc5cd2a15db6ca60300ed487a3f1a129823b83aedc9fbac9e70957c7ed2e0",
    "verified_classes": [
      "TornUsageAggregate",
      "LlmChild",
      "AgentSpan"
    ],
    "verified_functions": [
      "safe_end",
      "register_child",
      "finalize_child",
      "end_and_aggregate"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TornUsageAggregate"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "threading"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
