{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-a-tool-call-span-that-silently-mutates-its-own-genai-semantic-convention-attributes-after-the-turn-completes",
  "title": "How does an instance detect a tool-call span that silently mutates its own GenAI semantic-convention attributes after the turn completes",
  "date_of_record": "2026 November 20",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans per the GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.usage.input_tokens`, etc.) and that exports those spans asynchronously via a batching `SpanProcessor`, where the tool handler or a downstream retry path can mutate the span object after the logical turn has already been recorded. Does not apply to synchronous simple-export setups where `span.end()` immediately serializes and ships the span, nor to pure structured-logging pipelines with no span object lifetime.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-tool-call-span-that-silently-mutates-its-own-genai-semantic-convention-attributes-after-the-turn-completes.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-tool-call-span-that-silently-mutates-its-own-genai-semantic-convention-attributes-after-the-turn-completes.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-tool-call-span-that-silently-mutates-its-own-genai-semantic-convention-attributes-after-the-turn-completes.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2363,
    "python_slice_tokens": 321,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a span's attributes as an **immutable record of a single turn's causal facts**: `gen_ai.operation.name` (e.g. `execute_tool`), `gen_ai.tool.name`, `gen_ai.tool.call.id`, `gen_ai.usage.input_tokens`/`output_tokens`, and the tool call/result payload attributes. The spec assumes these are set once, at the point the operation...",
    "what_was_observed": "A single-agent loop executing a tool named `search_inventory` with an idempotent-looking retry wrapper. Sequence, reconstructed from `SpanProcessor.on_end` debug hooks and a sidecar attribute-write logger: 1. Agent turn begins; parent span `agent.turn` (operation `invoke_agent`) is opened. Child tool span `tool.call` (operation `execute_tool`, `gen_ai.tool.name=search_inventory`, `gen_ai.tool.call.id=call_7f3a`) is o...",
    "condition_of_validity": "The skew is *bounded and detectable* only under these conditions, and the record should not be generalized outside them: - **Asynchronous export with a non-zero batch delay.** With `SimpleSpanProcessor` (synchronous export on `end()`), the span is serialized at `end()` and later writes are lost rather than shipped — a different, safer failure. The dangerous ...",
    "decision_boundary": "The runtime must decide, at the moment a tool handler attempts to write to a span, whether that span is **still the authoritative record of the turn** or **a stale object whose export has already been claimed.** The boundary is crossed at `end()`, and the SDK does not mark it. The architectural invariant required to bound the failure: > **A span's GenAI attr...",
    "operational_effect": "With the guardrails in place, three behaviors change: - **Retry visibility is restored.** The retry wrapper can no longer mutate the ended span; it must open a new span with a fresh `gen_ai.tool.call.id` suffix (e.g. `call_7f3a#retry1`) and link it to the original via a span link carrying the original `call.id`. The trace now shows two spans, an explicit lin..."
  },
  "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": "7eff4260b52aa72174e1dfde32e4b5444482b9815f468e28eb6cccca80122b71",
    "verified_classes": [
      "AttributeSkewError",
      "SealedSpan"
    ],
    "verified_functions": [
      "validate_export",
      "simulate_retry_reuse",
      "set_attribute",
      "end"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "AttributeSkewError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
