{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-tool-call-span-collapse-when-genai-semantic-conventions-meet-retried-streamed-and-nested-agent-invocations",
  "title": "Which invariants prevent tool-call span collapse when GenAI semantic conventions meet retried, streamed, and nested agent invocations",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agents that emit OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.usage.input_tokens`/`output_tokens`, `gen_ai.agent.*`) for tool calls, streaming completions, and nested sub-agent delegation. Does not cover pure inference-server metrics (TTFT histograms) or non-OTel tracing backends.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-tool-call-span-collapse-when-genai-semantic-conventions-meet-retried-streamed-and-nested-agent-invocations.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-tool-call-span-collapse-when-genai-semantic-conventions-meet-retried-streamed-and-nested-agent-invocations.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-tool-call-span-collapse-when-genai-semantic-conventions-meet-retried-streamed-and-nested-agent-invocations.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1610,
    "python_slice_tokens": 356,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions describe *what an operation was*, not *how many times the runtime attempted it*. A tool-call span is a logical record of one invocation of `gen_ai.tool.name`; a retry is a distinct physical attempt. The conventions provide no attribute that reconciles the two, so the burden falls on the emitter to preserve a **one-span-per-logi...",
    "what_was_observed": "A tool-calling agent (`gen_ai.operation.name = \"execute_tool\"`) issued a `search_documents` call. The transport returned a 503 on attempt 1, a partial stream that terminated mid-`finish_reason` on attempt 2, and a clean result on attempt 3. The emitter was configured with a `BatchSpanProcessor` and a single long-lived span created at the *start of the logical call*, with retries recorded as span events. Observed span...",
    "condition_of_validity": "The one-span-per-logical-call invariant holds **only if** all of the following are true simultaneously: 1. **Attempt identity is externalized.** Every physical attempt carries a distinct `gen_ai.tool.call.id` (or a child span with its own ID), so the logical call is reconstructable by grouping on a stable logical key, never by assuming span count equals call...",
    "decision_boundary": "The emitter must choose, at span-creation time, between two mutually exclusive topologies: - **Flat-logical:** one span per logical call, retries as events, usage summed on the parent, `status.code` reflecting *any* attempt failure via a custom attribute (since OTel status is single-valued). Acceptable only when the backend does not aggregate on `gen_ai.tool...",
    "operational_effect": "Downstream, the collapsed span produces three concrete defects: (a) **cost attribution drift** proportional to retry count, since summed-parent usage is counted once per span but the partial-stream tokens are invisible to per-attempt billing reconciliation; (b) **loop-detection blindness**, because a retry storm and a single slow call are indistinguishable w..."
  },
  "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": "6d695f55231b253521746e7a22d2f0116b749797bceb4828611b0f67c6e5a433",
    "verified_classes": [
      "SpanCollapseError",
      "GenAISpan"
    ],
    "verified_functions": [
      "validate_before_end",
      "emit"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "SpanCollapseError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
