{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-refuse-to-close-a-genai-agent-span-when-a-tool-call-child-span-is-orphaned-by-context-propagation",
  "title": "Where must an instance refuse to close a GenAI agent span when a tool-call child span is orphaned by context propagation",
  "date_of_record": "2026 November 28",
  "scope": "Applies to agents emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*` attributes) where a tool invocation is instrumented as a child span and the parent context is propagated across an async boundary (queue, thread pool, subprocess, or remote MCP server). Does not apply to single-process synchronous agents where the tool call is inlined into the parent span with no separate span emission.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-close-a-genai-agent-span-when-a-tool-call-child-span-is-orphaned-by-context-propagation.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-close-a-genai-agent-span-when-a-tool-call-child-span-is-orphaned-by-context-propagation.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-close-a-genai-agent-span-when-a-tool-call-child-span-is-orphaned-by-context-propagation.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1969,
    "python_slice_tokens": 314,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and `gen_ai.tool.name` as span-level attributes. The convention implicitly assumes that a tool-call span is a **child of the agent span that decided to invoke the tool**, so that token accounting, tool latency, and the causal chain remain...",
    "what_was_observed": "A tool-executor pool was instrumented with a `ContextVar` holding the OTel `Context`. The pool worker captured the context at *worker startup*, not at task submission. The agent, running in the submitting coroutine, started its `gen_ai.operation.name=chat` span, then submitted a tool task. The worker, using its startup-captured context, had no active span—so `tracer.start_as_current_span(\"execute_tool\")` created a **...",
    "condition_of_validity": "The closure check is valid only under these conditions, and must be skipped otherwise: 1. The agent span is the *decision* span (the one carrying `gen_ai.operation.name` and usage attributes), not a wrapper. Wrapper spans that intentionally delegate to a child trace (e.g., a batch orchestrator fanning out to independent traces) must be exempt, or the check w...",
    "decision_boundary": "The boundary is between **\"the tool span is missing because the tool has not finished\"** and **\"the tool span is orphaned because it will never join this trace.\"** These are indistinguishable at agent-span-end time if you only look at whether a child span exists. The decision rule: - If the agent has a *synchronous* reference to the tool span and it has ende...",
    "operational_effect": "Enforcing the check converts a silent, permanent data-quality defect into a loud, per-turn error. In the observed system, the first deployment of the check raised on roughly 4% of agent turns—exactly the turns that used the pool executor. That number is the true orphan rate, previously invisible. Fixing propagation (capture context at dispatch) dropped it to..."
  },
  "matched_failure_symptoms": [
    "SUBPROCESS_PIPE_HANG_OR_FD_LEAK"
  ],
  "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": "4f9ed5b0ed5e8950a05bf5eddc7a13f016ad901ef8d0c57e336dc0be6b03e161",
    "verified_classes": [
      "OrphanedToolSpanError",
      "SpanRef",
      "AgentSpan"
    ],
    "verified_functions": [
      "close_agent_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "OrphanedToolSpanError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
