{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-genai-span-attribute-collapse-when-tool-call-token-usage-and-agent-invocation-telemetry-share-one-span",
  "title": "Which invariants prevent GenAI span attribute collapse when tool-call, token-usage, and agent-invocation telemetry share one span",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agents emitting OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) where a single span or span tree carries tool-call, token-usage, and agent-invocation attributes simultaneously. Does not apply to pure trace-only instrumentation without GenAI attributes, nor to metrics-only exporters where attribute aggregation is deferred to the backend.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-span-attribute-collapse-when-tool-call-token-usage-and-agent-invocation-telemetry-share-one-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-span-attribute-collapse-when-tool-call-token-usage-and-agent-invocation-telemetry-share-one-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-span-attribute-collapse-when-tool-call-token-usage-and-agent-invocation-telemetry-share-one-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1512,
    "python_slice_tokens": 346,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define three attribute families that were designed against different cardinality and lifecycle assumptions: - **Tool-call attributes** (`gen_ai.tool.name`, `gen_ai.tool.call.id`, `gen_ai.tool.type`) are *per-invocation*, high-cardinality, and expected to appear on child spans of a tool execution. - **Token-usage attributes** (`...",
    "what_was_observed": "A multi-tool agent (three tool calls per turn, streaming token usage) was instrumented with a single `gen_ai.operation.name = \"chat\"` span per model turn. Tool calls were recorded as child spans but the parent span's `gen_ai.tool.name` was also set on completion for convenience. Token usage was recorded via a streaming callback that accumulated `gen_ai.usage.output_tokens` incrementally. Observed trace pathology: 1. ...",
    "condition_of_validity": "The segregation invariant holds only under the following conditions: - **Phase monotonicity:** a span's attribute writes must follow `START → (TOOL_CHILD) → USAGE_CLOSE → END`. Tool-call attributes may only be written while the span is in the `TOOL_CHILD` phase; token-usage attributes only in `USAGE_CLOSE`; agent-invocation attributes only at `START`. - **No...",
    "decision_boundary": "The runtime must choose between two span topologies, and the choice is forced by whether the agent performs tool calls *within* a model turn: - If the model turn is a single request/response with no interleaved tools, a **flat span** with all three families is safe, because phases do not interleave. - If the model turn interleaves tool calls (the common ReAc...",
    "operational_effect": "Enforcing the invariant converts a silent aggregation error into a loud instrumentation error at the point of violation, which is the correct trade: a rejected attribute write during development is cheaper than a 40% token undercount discovered in a cost report. The practical effects are (a) token-usage totals become additive across the span tree rather than..."
  },
  "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": "b8342a49ac39e228d6bde47b4f3252cb46df40cb829dad4a59626cd118f09bfc",
    "verified_classes": [
      "SpanPhase",
      "AttributePhaseViolation",
      "GenAISpan"
    ],
    "verified_functions": [
      "emit_agent_turn",
      "replay_retry",
      "__init__",
      "advance",
      "set_attribute"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "AttributePhaseViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "enum"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
