{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-abort-a-trace-rather-than-close-it-span-termination-invariants-for-opentelemetry-genai-agent-spans-under-tool-call-attribute-mut",
  "title": "When must an instance abort a trace rather than close it: span-termination invariants for OpenTelemetry GenAI agent spans under tool-call attribute mutation",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents that emit OpenTelemetry spans following the GenAI semantic conventions (`gen_ai.*` attributes, `execute_tool` child spans, `invoke_agent` parent spans) where tool-call attributes are written from non-deterministic tool outputs. Does not apply to stateless request/response inference spans with a single terminal status write, nor to traces exported via a sidecar that buffers and rewrites attributes post-hoc.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-abort-a-trace-rather-than-close-it-span-termination-invariants-for-opentelemetry-genai-agent-spans-under-tool-call-attribute-mut.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-abort-a-trace-rather-than-close-it-span-termination-invariants-for-opentelemetry-genai-agent-spans-under-tool-call-attribute-mut.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-abort-a-trace-rather-than-close-it-span-termination-invariants-for-opentelemetry-genai-agent-spans-under-tool-call-attribute-mut.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1985,
    "python_slice_tokens": 342,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a span as a *record of a completed operation*: attributes such as `gen_ai.tool.name`, `gen_ai.tool.call.id`, and `gen_ai.usage.input_tokens` are expected to be set before the span ends, and `span.set_status()` is expected to be called exactly once at termination. The failure mode examined here is not \"attributes are wrong...",
    "what_was_observed": "A tool-using agent (planner → `execute_tool` → observe → re-plan) was instrumented with the GenAI conventions. The planner occasionally emits a function-call payload whose `name` field is a near-miss of a registered tool (e.g. `web_search_v2` when only `web_search` is registered). The runtime's dispatch layer resolves the near-miss to the registered tool via fuzzy match, executes it, and writes the span attributes fr...",
    "condition_of_validity": "The abort-rather-than-close rule is valid only when all of the following hold: - The tool-call span is a *child of an `invoke_agent` span that is still open*. If the parent has ended, the trace is already sealed and the corrective span must be emitted as a new root with an explicit `gen_ai.conversation.id` linkage, not as a sibling. - The revision is *caused...",
    "decision_boundary": "The decision is between three terminal actions for a tool-call span whose attributes were invalidated after execution: The boundary is *consumption*, not *completion*. A tool call that completed at the transport layer but whose result never entered the model's context is not a completed operation from the agent's perspective, and marking it `OK` is the speci...",
    "operational_effect": "Enforcing the boundary changes three things: 1. **Cost attribution becomes single-counted.** The `gen_ai.usage.input_tokens` on the successor span is the only one counted; the aborted predecessor carries `gen_ai.usage.input_tokens = 0` and a `gen_ai.tool.call.supersedes` pointer. Downstream rollups that sum tokens no longer double-count re-planned calls. 2. ..."
  },
  "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": "200fad7f39264ce8f2019a88fd5498606d743751dfc8899ba7a0e75b5efdd406",
    "verified_classes": [
      "SpanTerminationError",
      "ToolSpanStatus",
      "ToolCallSpan"
    ],
    "verified_functions": [
      "finalize_tool_span",
      "set_attribute",
      "terminate"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "SpanTerminationError"
    ],
    "sample_fail_closed_invariants": [
      "call_id must be persisted before termination"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
