{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-genai-span-attribute-collapse-when-an-agent-s-tool-call-tree-is-re-emitted-across-retries",
  "title": "Which invariants prevent GenAI span attribute collapse when an agent's tool-call tree is re-emitted across retries",
  "date_of_record": "2026 November 28",
  "scope": "Applies to agents emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where a single logical invocation may be retried, re-planned, or replayed by a supervisor, and where downstream token accounting is derived by summing span attributes. Does not apply to single-shot, non-retried inference calls or to traces where no retry/replay layer exists.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-span-attribute-collapse-when-an-agent-s-tool-call-tree-is-re-emitted-across-retries.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-span-attribute-collapse-when-an-agent-s-tool-call-tree-is-re-emitted-across-retries.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-span-attribute-collapse-when-an-agent-s-tool-call-tree-is-re-emitted-across-retries.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1898,
    "python_slice_tokens": 356,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not that spans go missing. It is that a *logical* agent invocation and a *physical* span emission decouple under retry. When an agent's execution loop retries a tool call or re-plans a step, the OpenTelemetry SDK re-emits a new span with the same `gen_ai.operation.name` and often the same logical identity (same `gen_ai.tool.name`, same parent ...",
    "what_was_observed": "A three-step agent (plan → retrieve → synthesize) ran under a supervisor that retried any tool call returning a transient error up to N=3 times. The retrieve step failed twice on a rate-limit before succeeding on the third attempt. Trace shape emitted: - `invoke_agent` root span, `gen_ai.usage.input_tokens=1850`, `output_tokens=210`. - `execute_tool` child span #1 (`gen_ai.tool.name=vector_search`), attempt 1, `statu...",
    "condition_of_validity": "The invariant that must hold for tree-sum token accounting to be correct is: > **For every logical agent invocation, exactly one span in the emitted tree carries the authoritative `gen_ai.usage.*` totals for that invocation, and no other span in the tree reports tokens that are a subset of those totals.** This invariant is *not* stated in the GenAI semantic ...",
    "decision_boundary": "The boundary where this bites is: **retry depth > 0 AND a consumer that aggregates token usage by summing across the span tree.** Below that boundary — no retries, or a consumer that reads only the root span's usage — the ambiguity is latent and harmless. The decision is whether to enforce the invariant at emission time or at collection time: - **Emission-ti...",
    "operational_effect": "The observable effect of missing the invariant is a token-accounting drift that is *correlated with system health*: when the upstream tool is flaky, retries spike, and reported cost inflates precisely during the incident you are trying to diagnose. Budget alarms fire on phantom spend; chargeback reports over-attribute to the flaky dependency; and capacity pl..."
  },
  "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": "e361687dfc59a15c1626a53bc55e3ee87af08af844e5142b89c0cb21865fa4aa",
    "verified_classes": [
      "UnauthoritativeUsageError",
      "GenAISpan"
    ],
    "verified_functions": [
      "aggregate_authoritative_input_tokens",
      "verify_trace"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "UnauthoritativeUsageError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
