{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-refuse-to-close-an-opentelemetry-genai-agent-span-the-tool-call-lineage-orphan-under-partial-token-accounting",
  "title": "When must an instance refuse to close an OpenTelemetry GenAI agent span: the tool-call lineage orphan under partial token accounting",
  "date_of_record": "2026 November 26",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) for LLM invocations and tool executions, where tool-call lineage is propagated via `gen_ai.tool.call.id` and token usage is reported via `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`. Does not apply to single-shot, stateless completions with no tool loop, nor to runtimes that buffer the entire agent trajectory and emit one span at `END` with no intermediate tool spans.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-close-an-opentelemetry-genai-agent-span-the-tool-call-lineage-orphan-under-partial-token-accounting.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-close-an-opentelemetry-genai-agent-span-the-tool-call-lineage-orphan-under-partial-token-accounting.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-close-an-opentelemetry-genai-agent-span-the-tool-call-lineage-orphan-under-partial-token-accounting.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2177,
    "python_slice_tokens": 342,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between *span lifecycle correctness* and *lineage correctness*. A span can be perfectly well-formed — valid trace ID, valid parent span ID, correct start/end timestamps, no missing required attributes — and still be a **lineage orphan**: a `gen_ai.tool` span whose `gen_ai.tool.call.id` was never matched by a corresponding assi...",
    "what_was_observed": "A planner agent (`gen_ai.operation.name = \"chat\"`) emitted an assistant message containing three tool-call blocks in a single completion: `call_a`, `call_b`, `call_c`. The runtime dispatched all three concurrently. The span tree at flush time looked like this: - `agent.run` (root) - `gen_ai.chat` (planner turn 1) — `gen_ai.usage.output_tokens = 412`, output message recorded with three tool-call blocks - `gen_ai.tool`...",
    "condition_of_validity": "The bijection holds only under a conjunction of conditions that agent runtimes routinely break: - **All tool dispatches are instrumented on every exit path.** The span must be opened *before* the dispatch and closed on success, error, cancellation, and timeout — not opened inside the success handler. The common bug is `with tracer.start_as_current_span(...)`...",
    "decision_boundary": "The decision the runtime must make at `gen_ai.chat` span end is: *do I close now, or do I hold?* The boundary is not \"did the completion return\" — it did. The boundary is: > Close the `gen_ai.chat` span only when the set of `gen_ai.tool.call.id` values recorded in its output message is a subset of the set of `gen_ai.tool.call.id` values present on its descen...",
    "operational_effect": "Enforcing the bijection changes three things: 1. **Span end becomes a synchronization point.** The chat span's `END` timestamp now reflects the last descendant tool span's end, not the completion's end. This is correct for latency accounting (the turn genuinely wasn't done) but shifts the meaning of `gen_ai.chat` duration from \"model latency\" to \"turn latenc..."
  },
  "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": "fe38b65e54c542f5a9215d837ca58fc909ac02a0123f51ab948d5ad2fc86f909",
    "verified_classes": [
      "LineageBijectionError",
      "ToolSpan",
      "ChatSpan"
    ],
    "verified_functions": [
      "close_chat_span_guarded",
      "register_tool_span",
      "_unbacked_call_ids",
      "close",
      "assert_bijection"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "LineageBijectionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
