{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-gen-ai-usage-tokens-after-the-parent-agent-span-has-already-ended",
  "title": "What happens when an instance emits gen_ai.usage tokens after the parent agent span has already ended",
  "date_of_record": "2026 November 29",
  "scope": "Applies to agents instrumented with OpenTelemetry GenAI semantic conventions where child tool-call or sub-agent spans report `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` asynchronously after the enclosing `gen_ai.agent.*` span has been closed. Does not apply to synchronous request-scoped spans or to span processors that buffer and reorder on export.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-gen-ai-usage-tokens-after-the-parent-agent-span-has-already-ended.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-gen-ai-usage-tokens-after-the-parent-agent-span-has-already-ended.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-gen-ai-usage-tokens-after-the-parent-agent-span-has-already-ended.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1872,
    "python_slice_tokens": 369,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "A span's *end timestamp* is a lifecycle fact; a span's *attributes* are a mutable payload that can be written until the span is ended. The GenAI semantic conventions assume a monotonic relationship: token accounting for a turn is complete and attributed before the turn's agent span closes. That assumption is false for streaming agents, for deferred tool exec...",
    "what_was_observed": "A tool-augmented agent (`gen_ai.agent.name = \"planner\"`) emitted a parent span with `gen_ai.usage.input_tokens = 1840`, `gen_ai.usage.output_tokens = 212`, then ended. Its child `execute` span (`gen_ai.operation.name = \"execute_tool\"`, `gen_ai.tool.name = \"vector_search\"`) was dispatched to an async worker. The worker completed 340 ms later, recorded `gen_ai.usage.input_tokens = 0`, `gen_ai.usage.output_tokens = 0` (...",
    "condition_of_validity": "The undercount is bounded and predictable under the following condition: the agent's usage must be attributed at span creation or before `span.end()`, and no descendant span may contribute model tokens that were causally consumed by the parent turn. When a descendant *does* consume tokens on behalf of the parent (sub-agent delegation, deferred summarization,...",
    "decision_boundary": "The boundary is the span end event. Before it, `set_attribute` on `gen_ai.usage.*` is a legitimate accumulation. After it, the SDK's span is immutable (per the OpenTelemetry spec: \"attributes... MUST NOT be modified after the span is ended\") and any attempt to add usage is either dropped by the SDK or, worse, accepted by a lenient exporter and produces a spa...",
    "operational_effect": "The observable effect is a systematic, silent undercount of token spend proportional to the fraction of a turn's tokens consumed by delegated children. In our fleet this manifested as: (a) per-agent budget dashboards reading 20–40% below actual for planner-class agents, (b) cost attribution charging summarizer agents for tokens the planner caused, (c) no ale..."
  },
  "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": "907094754a969afefb25df60e3037cbcbd1e28b0ab0955c1d7851c5176b21491",
    "verified_classes": [
      "UsageAttributionError",
      "Span"
    ],
    "verified_functions": [
      "sum_subtree_usage",
      "enforce_closed_sum",
      "attribute_turn"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "UsageAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
