{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-genai-agent-span-attribute-loss-across-tool-call-fan-out-when-token-accounting-propagates-through-nested-spans",
  "title": "Which invariants prevent GenAI agent-span attribute loss across tool-call fan-out when token accounting propagates through nested spans",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans per LLM invocation and per tool call, where token usage and cost attributes must aggregate from leaf tool spans up to the root agent span. Does not cover single-shot, single-span inference calls with no nested tool execution, nor does it cover billing reconciliation against provider invoices.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-agent-span-attribute-loss-across-tool-call-fan-out-when-token-accounting-propagates-through-nested-spans.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-agent-span-attribute-loss-across-tool-call-fan-out-when-token-accounting-propagates-through-nested-spans.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-agent-span-attribute-loss-across-tool-call-fan-out-when-token-accounting-propagates-through-nested-spans.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1918,
    "python_slice_tokens": 459,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure here is not \"missing telemetry\" in the naive sense—spans are emitted, they are exported, and they land in the backend. The failure is **attribute provenance collapse**: the `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` attributes and their derived cost attributes are set at *different* span layers by *different* code paths, and the a...",
    "what_was_observed": "A four-turn agent task (two tool calls, three model invocations) exported this span tree: Three distinct pathologies are visible: - **Tool spans carry usage they did not incur.** The shared tool-instrumentation wrapper read `gen_ai.usage.*` from the active context (the parent chat span) and stamped it onto the tool span to \"make dashboards work.\" This violates the semantic convention that `execute_tool` spans report ...",
    "condition_of_validity": "The leaf-attribution convention (1) is the only one that composes correctly under arbitrary fan-out, and it is valid **only if** the following three conditions hold simultaneously: 1. **Usage attributes are set exclusively on `gen_ai.operation.name ∈ {chat, text_completion, embeddings}` spans**, never on `execute_tool`, `invoke_agent` (non-root), or `create_...",
    "decision_boundary": "The boundary is between **propagation** and **aggregation**. Usage must *propagate upward by summation at export/query time*, never by *copying downward or sideways at span-creation time*. The moment a span copies a parent's usage attribute \"for convenience,\" the tree becomes non-reconstructable: you can no longer tell whether a child's value is its own or i...",
    "operational_effect": "With the creation-time guardrail in place, the same task exports: Root usage is now a well-defined `sum(descendant chat spans)` = 12040 input / 685 output, cost is \\$0.018, and per-tool cost attribution correctly reports zero model spend for tools. The invariant—**cumulative usage is monotonic non-decreasing down any root-to-leaf path, and equals the sum ove..."
  },
  "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": "5eb662c6d3f6fdf1de4827d0cb61efc2ab30f5e7dbe9e65767df945dcae94d81",
    "verified_classes": [
      "UsageAttributeViolation",
      "Span"
    ],
    "verified_functions": [
      "aggregate_usage",
      "assert_monotonic_usage",
      "set_usage",
      "close",
      "walk",
      "walk"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UsageAttributeViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
