{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-refuse-to-emit-a-genai-tool-call-span-when-its-parent-agent-span-has-already-been-closed-by-an-out-of-band-completion-signal",
  "title": "Where must an instance refuse to emit a GenAI tool-call span when its parent agent span has already been closed by an out-of-band completion signal",
  "date_of_record": "2026 December 1",
  "scope": "Applies to any agent runtime that emits OpenTelemetry GenAI spans (`gen_ai.*` semantic conventions) where tool invocations are attributed to an enclosing agent/invoke-agent span and the span lifecycle is owned by the LLM loop rather than the tool executor. Does not apply to fire-and-forget telemetry sinks that tolerate orphan spans, nor to runtimes where tool execution is fully synchronous within the parent span's lexical scope.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-emit-a-genai-tool-call-span-when-its-parent-agent-span-has-already-been-closed-by-an-out-of-band-completion-signal.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-emit-a-genai-tool-call-span-when-its-parent-agent-span-has-already-been-closed-by-an-out-of-band-completion-signal.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-emit-a-genai-tool-call-span-when-its-parent-agent-span-has-already-been-closed-by-an-out-of-band-completion-signal.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1752,
    "python_slice_tokens": 342,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a tool call as a *child event of an agent turn*: `gen_ai.operation.name = \"execute_tool\"`, `gen_ai.tool.name`, `gen_ai.tool.call.id`, and `gen_ai.agent.name` are all attributes whose meaning is anchored to the enclosing `invoke_agent` span. The invariant that is easy to miss is this: **the semantic validity of a tool-call...",
    "what_was_observed": "A multi-step agent loop was instrumented so that each LLM turn opened an `invoke_agent` span, and each tool call opened a nested `execute_tool` span with `gen_ai.tool.call.id` matching the `tool_call_id` returned by the model. Under normal completion the nesting was clean: `invoke_agent → chat → execute_tool`, with the tool span closing before the agent span. Under a specific trigger — the model emitting a final assi...",
    "condition_of_validity": "The invariant holds — and the guardrail is required — under the conjunction of three conditions: 1. **Asynchronous tool dispatch.** The tool executor runs on a task/thread not joined to the LLM turn's `finally` block. Synchronous tool calls inside the turn cannot trigger this. 2. **Out-of-band turn termination.** The agent loop can end an `invoke_agent` span...",
    "decision_boundary": "An instance must **refuse to export** a `gen_ai.operation.name = \"execute_tool\"` span when the resolved parent `invoke_agent` span is already ended. The correct behavior is one of two bounded options, never silent export: - **Re-parent to a synthetic root** with an explicit attribute `gen_ai.tool.orphaned = true` and `gen_ai.tool.parent_turn_ended_at = <time...",
    "operational_effect": "The practical consequence is that tool-call telemetry becomes *complete and attributable* rather than merely *delivered*. Without the guardrail, the trace looks fine in volume — span counts match invocation counts — but per-turn cost, latency, and error attribution silently drift, and any evaluator that joins tool results to turns by parent span will mis-joi..."
  },
  "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": "7b7a8a14d6e080a14614e1cd2fb84d1b455bbf43b8d956c3fbdf126b6274f95f",
    "verified_classes": [
      "OrphanedToolSpanError",
      "SpanRef"
    ],
    "verified_functions": [
      "validate_tool_span_export",
      "emit_tool_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "OrphanedToolSpanError"
    ],
    "sample_fail_closed_invariants": [
      "orphan drop requested but not wired to counter"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
