{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-token-accounting-attributes-against-the-tool-call-span-tree-before-closing-an-age",
  "title": "Under what conditions must an instance reconcile OpenTelemetry GenAI token-accounting attributes against the tool-call span tree before closing an agent trace",
  "date_of_record": "2026 November 24",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.*`) and nests `execute_tool` child spans under a parent `invoke_agent` span. Does not apply to single-shot completion calls with no tool loop, nor to runtimes that delegate token accounting entirely to a billing-side aggregator.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-token-accounting-attributes-against-the-tool-call-span-tree-before-closing-an-age.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-token-accounting-attributes-against-the-tool-call-span-tree-before-closing-an-age.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-token-accounting-attributes-against-the-tool-call-span-tree-before-closing-an-age.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1632,
    "python_slice_tokens": 301,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token usage as an attribute of the *model invocation* span (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`), not of the agent span. An agent span that fans out into N tool-call turns will therefore contain N child `chat`/`generate_content` spans, each carrying its own usage attributes, plus a parent `invoke_ag...",
    "what_was_observed": "A research agent with a `search_documents` tool that internally performs a query-rewrite LLM call. Trace structure observed in the collector: The runtime's accounting hook walked `span.children` of `invoke_agent`, summed `gen_ai.usage.input_tokens` across the two `chat` children (812 + 1104 = 1916) and the two `execute_tool` children (which carry no usage attributes, contributing 0). It wrote `gen_ai.usage.input_toke...",
    "condition_of_validity": "The invariant — *parent aggregate equals true consumption* — holds only when all of the following are true: 1. **Traversal is depth-first over the full subtree**, not direct-children. Any tool that re-enters the model creates grandchild usage spans. 2. **Span status is consulted before summing.** Spans with `status = ERROR` and no `gen_ai.usage.output_tokens...",
    "decision_boundary": "The runtime must choose between two postures at trace close: - **Reconcile-and-fail-closed:** if the depth-first subtree sum disagrees with any provider-reported total (e.g., a `gen_ai.response.id`-keyed billing reconciliation), or if any in-flight child is detected, do not write the aggregate; emit `agent.accounting.incomplete = true` and raise. This is cor...",
    "operational_effect": "Runtimes that adopt depth-first reconciliation with explicit retry policy see two effects. First, token budgets trip at the correct turn rather than one to three turns late, which changes the shape of agent trajectories near the budget ceiling — the agent truncates earlier and with less wasted context. Second, cost dashboards stop under-reporting by the fan-..."
  },
  "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": "086c71ef7ec6d19295b3894d0b0a50ddd1e12726130cfd1468c07549450c6914",
    "verified_classes": [
      "TokenAccountingReconciliationError",
      "Span"
    ],
    "verified_functions": [
      "_walk_subtree",
      "reconcile_agent_tokens"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenAccountingReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
