{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-silent-token-and-cost-telemetry-loss-across-opentelemetry-genai-agent-spans",
  "title": "Which invariants prevent silent token and cost telemetry loss across OpenTelemetry GenAI agent spans",
  "date_of_record": "2026 November 16",
  "scope": "Applies to multi-hop agent execution graphs where a parent `invoke_agent` span delegates to nested `execute_tool` / `chat` spans and where token usage and cost attributes are emitted per model invocation. Does not apply to single-shot LLM calls with no tool fan-out, nor to purely trace-only pipelines that never aggregate usage attributes for billing.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-token-and-cost-telemetry-loss-across-opentelemetry-genai-agent-spans.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-token-and-cost-telemetry-loss-across-opentelemetry-genai-agent-spans.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-token-and-cost-telemetry-loss-across-opentelemetry-genai-agent-spans.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1498,
    "python_slice_tokens": 301,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The non-obvious boundary is between *span presence* and *attribute propagation*. The OpenTelemetry GenAI semantic conventions define attribute names (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.usage.cost`, `gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.tool.call.id`) but they do **not** define an aggregation invariant across the...",
    "what_was_observed": "In a ReAct-style agent with a planner, three tools, and a final synthesis step, the trace contained: 1 `invoke_agent` span, 3 `execute_tool` spans, and 4 `chat` spans (planner, two tool-followup reasoning turns, synthesis). Each `chat` span carried correct `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. The root span carried `gen_ai.usage.input_tokens` equal to only the *first* chat turn's input tokens ...",
    "condition_of_validity": "The invariant holds — and must be enforced — only when all of the following are true: 1. The agent performs **iterative re-invocation** (tool-call loops, reflection, retries), so the number of model calls is not known at root-span start. 2. Usage attributes are aggregated for **billing or quota**, where under-counting has downstream consequences. 3. The coll...",
    "decision_boundary": "The correct decision is: **never write terminal usage attributes on a span before its children close.** Root-level usage must be a *derived* value computed at span end from the closed child set, or must be omitted from the root entirely and left to backend aggregation. The forbidden pattern is a root span that reports a usage number *and* has usage-bearing d...",
    "operational_effect": "When the invariant is enforced, cost rollups reconcile to provider invoices within rounding, and tool-attributed cost analysis is possible. When it is violated, the failure is invisible until invoice reconciliation, at which point the trace data cannot explain the gap because the trace is *structurally complete* — there is no missing span to point at. The re..."
  },
  "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": "66d564f396eef14fb6d7b138ab7f7dc0af5989c1d3655a05d4f9320624e9a104",
    "verified_classes": [
      "GenAIUsagePropagationError",
      "SpanRecord"
    ],
    "verified_functions": [
      "validate_usage_invariant",
      "validate_tool_call_joins"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "GenAIUsagePropagationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
