{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-span-attribute-corruption-when-opentelemetry-genai-semantic-conventions-are-emitted-mid-loop-by-an-agent-that-mutates-its-own",
  "title": "Which invariants prevent span-attribute corruption when OpenTelemetry GenAI semantic conventions are emitted mid-loop by an agent that mutates its own tool schema",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agents that emit OTel GenAI spans (`gen_ai.*` semantic conventions, spec version ≥1.27) for tool calls, token accounting, and model attribution while the agent itself can rewrite its own tool manifest, system prompt, or model routing mid-execution. Does not apply to stateless single-turn inference where the span is closed before any tool result returns.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-attribute-corruption-when-opentelemetry-genai-semantic-conventions-are-emitted-mid-loop-by-an-agent-that-mutates-its-own.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-attribute-corruption-when-opentelemetry-genai-semantic-conventions-are-emitted-mid-loop-by-an-agent-that-mutates-its-own.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-attribute-corruption-when-opentelemetry-genai-semantic-conventions-are-emitted-mid-loop-by-an-agent-that-mutates-its-own.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1996,
    "python_slice_tokens": 406,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure mode is not \"missing spans\" or \"wrong span names.\" It is **attribute drift on an already-open span whose semantics were fixed at span start but whose referent changed before span end.** OTel GenAI conventions bind `gen_ai.request.model`, `gen_ai.operation.name`, `gen_ai.system`, and the tool identity (`gen_ai.tool.name`, `gen_ai.tool.call.id`) to...",
    "what_was_observed": "A three-step agent loop: `plan → tool_call(search_index) → synthesize`. On step 2, the tool call exceeded a 4s deadline, the runtime retried against a secondary index backend registered under the *same* `gen_ai.tool.name` but a different `gen_ai.tool.description` hash and a different result schema. The retry succeeded at 6.1s. The parent `chat` span had `gen_ai.request.model = \"model-a\"`, but the runtime's fallback r...",
    "condition_of_validity": "The conventions remain sound only under the following invariant, which the spec states implicitly but does not enforce: > **Attribution closure invariant:** For every span S with `gen_ai.operation.name ∈ {chat, text_completion, execute_tool}`, the tuple `(gen_ai.request.model, gen_ai.response.model, gen_ai.usage.*, gen_ai.tool.name, gen_ai.tool.call.id)` mus...",
    "decision_boundary": "The agent must decide, at each mutation point (model fallback, tool retry, schema swap), between: - **Boundary A — close-and-reopen:** end the current span, start a sibling with the new attributes, propagate the same `trace_id` and a `parent_span_id` pointing at the enclosing logical operation. Preserves attribution closure at the cost of span cardinality (o...",
    "operational_effect": "Under the invariant, three downstream systems behave correctly: 1. **Cost reconciliation** (`sum(usage) group by response.model`) becomes exact, because no span aggregates two models. 2. **Tool-execution audit** (`count(distinct gen_ai.tool.call.id) by gen_ai.tool.name`) counts executions, not logical calls, and schema-hash joins on retries are recoverable. ..."
  },
  "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": "8da3c52abbda16f5a0c531a3f1aaff61376947dd0f1f4e315cb1d5bf8f64ffb7",
    "verified_classes": [
      "AttributionClosureViolation",
      "GenAISpan"
    ],
    "verified_functions": [
      "reconcile",
      "_attribution_tuple",
      "add_tokens",
      "mutate_tool",
      "close"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "AttributionClosureViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
