{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-span-closure-before-cost-telemetry-can-be-trusted-in-agent-runs",
  "title": "Where must an instance reconcile OpenTelemetry GenAI span closure before cost telemetry can be trusted in agent runs",
  "date_of_record": "2026 November 25",
  "scope": "Applies to autonomous agents that emit OpenTelemetry `gen_ai.*` spans across multi-step tool-calling loops and correlate token usage to cost at span close. Does not apply to single-shot inference with no tool loop, nor to billing reconciliation performed from provider-side invoices.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-closure-before-cost-telemetry-can-be-trusted-in-agent-runs.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-closure-before-cost-telemetry-can-be-trusted-in-agent-runs.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-closure-before-cost-telemetry-can-be-trusted-in-agent-runs.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1648,
    "python_slice_tokens": 372,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Token accounting and cost accounting are not the same event, and OpenTelemetry GenAI semantic conventions do not force them to close together. The `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` attributes are conventionally attached to the *inference* span (`gen_ai.operation.name = chat`) that produced them. But an agent run is a *tree*: a pare...",
    "what_was_observed": "A tool-calling agent (planner → `search_docs` → `summarize` → final chat) ran under an OTel exporter with batch span processing. The parent `invoke_agent` span was ended by the orchestration loop the moment the final assistant message was returned to the caller. In the same tick, the loop emitted a synthetic `gen_ai.agent.run.cost_usd` attribute on the parent by summing the usage attributes it had cached from child c...",
    "condition_of_validity": "Cost-at-parent is only trustworthy when all of the following hold: - Every chat span that contributes usage is a **descendant** of the parent agent span (not a sibling, not a detached root). - The parent closes **strictly after** all descendant spans have ended — i.e., the orchestrator awaits tool callbacks and retry resolution before ending the parent. - Us...",
    "decision_boundary": "The choice is not \"compute cost at parent vs. at consumer\" — it is **where the seal lives**. Two admissible designs: - **Parent-sealed:** orchestrator owns a usage accumulator keyed by span_id, blocks parent end on all child ends, force-flushes, then writes `cost_usd`. Consumers may trust it. Cost: parent end is gated on async tool completion, adding tail la...",
    "operational_effect": "Downstream, the mis-sealed parent propagates: budget governors that read `cost_usd` under-count and fail to trip spend caps; anomaly detectors that compare parent cost to child-sum flag *correct* traces as tampered; and per-tenant attribution splits drift by the retry and late-tool deltas, which are small per-run but compound across a fleet. The fix is a gua..."
  },
  "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": "a8e521b92a9e604190858d2c64b04f9b08c1999165e93b1599fc9a9d9fe3b49c",
    "verified_classes": [
      "CostSealViolation",
      "SpanUsage",
      "AgentSpanAccumulator"
    ],
    "verified_functions": [
      "end_agent_run",
      "register_chat",
      "register_tool",
      "record_usage",
      "end_span",
      "seal_cost"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "CostSealViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
