{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-genai-semantic-convention-span-attributes-from-silently-mis-accounting-tokens-and-cost-across-agent-tool-call-boundaries",
  "title": "Which invariants prevent GenAI semantic-convention span attributes from silently mis-accounting tokens and cost across agent tool-call boundaries",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agents that emit OpenTelemetry GenAI spans (`gen_ai.*` attributes) and propagate token/usage accounting across nested tool-call and sub-agent spans. Does not cover provider-side billing reconciliation, non-OTel tracing backends, or transport-level retry semantics.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-semantic-convention-span-attributes-from-silently-mis-accounting-tokens-and-cost-across-agent-tool-call-boundaries.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-semantic-convention-span-attributes-from-silently-mis-accounting-tokens-and-cost-across-agent-tool-call-boundaries.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-semantic-convention-span-attributes-from-silently-mis-accounting-tokens-and-cost-across-agent-tool-call-boundaries.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1773,
    "python_slice_tokens": 287,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat *usage* (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.usage.total_tokens`) as a property of a single inference operation, and *cost* as a derived, out-of-band quantity. They do **not** define an aggregation contract across a span tree. This is the fault line: an agent that performs N tool calls insid...",
    "what_was_observed": "A research agent with a planner/executor split emitted spans as follows. The planner span (`gen_ai.operation.name=chat`, `gen_ai.system=openai`) carried `usage.total_tokens=1840`. The executor performed three tool calls, each wrapped in a `gen_ai.operation.name=execute_tool` span with no usage attributes (correct — tools don't consume model tokens). Between tool calls the executor re-invoked the model twice, emitting...",
    "condition_of_validity": "The additive-sum invariant holds only under the conjunction: 1. **Uniqueness:** every `gen_ai.operation.name=chat` (or `embeddings`, `text_completion`) inference op is represented by exactly one exported span, keyed by a stable `gen_ai.response.id` where the provider supplies one. 2. **Non-propagation:** spans whose `gen_ai.operation.name` is `invoke_agent`,...",
    "decision_boundary": "The operational decision is where to enforce the invariant. Three viable placements: - **Emit-time enforcement (preferred):** the instrumentation layer rejects `gen_ai.usage.*` on non-inference spans. This is a hard guardrail and eliminates the copied-up overcount class entirely. It does not address sampling loss. - **Aggregation-time enforcement:** the cost...",
    "operational_effect": "With the invariant enforced, the observable failure changes character. Instead of a silently biased total, you get a *reconciliation exception* at the aggregation boundary — a span that claims a total its children cannot support, or a trace whose inference-span count is inconsistent with its declared sampling decision. This converts a cost-accounting error t..."
  },
  "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": "ae93e638fc29b7ac92bb62b485f405d36bd648d78b1edbc777d2af07c9fb3f67",
    "verified_classes": [
      "UsageAccountingInvariantError"
    ],
    "verified_functions": [
      "reconcile_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "UsageAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
