{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-tool-call-spans-under-a-parent-turn-span-that-has-already-been-closed-by-an-asynchronous-cancellation",
  "title": "What happens when an instance emits tool-call spans under a parent turn span that has already been closed by an asynchronous cancellation",
  "date_of_record": "2026 November 23",
  "scope": "Applies to multi-turn agent runtimes that emit OpenTelemetry GenAI spans (`gen_ai.*`) using a turn-scoped parent span and asynchronously dispatched tool calls. Does not apply to single-shot inference logging or to runtimes that buffer spans locally and flush strictly in causal order at turn end.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-tool-call-spans-under-a-parent-turn-span-that-has-already-been-closed-by-an-asynchronous-cancellation.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-tool-call-spans-under-a-parent-turn-span-that-has-already-been-closed-by-an-asynchronous-cancellation.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-tool-call-spans-under-a-parent-turn-span-that-has-already-been-closed-by-an-asynchronous-cancellation.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1902,
    "python_slice_tokens": 444,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"missing telemetry.\" It is a **causal-order violation inside a span tree that OTel exporters treat as immutable once a span's end timestamp is recorded**. A turn span (`gen_ai.operation.name = \"chat\"`, one per user turn) is closed when the model returns its final assistant message. But agent runtimes frequently dispatch tool calls (`gen_ai...",
    "what_was_observed": "A multi-turn agent serving a code-assistant workload emitted, per turn, a parent span `chat` with children `execute_tool`. Under normal load, all children closed before the parent. Under a specific trigger — a user cancelling the turn (client disconnect) while a `execute_tool` call to a long-running sandbox was in flight — the runtime executed this sequence: 1. Turn span `chat` received a cancellation signal; the run...",
    "condition_of_validity": "The invariant \"every `execute_tool` child span ends before its `chat` parent span ends\" holds **only when the runtime's cancellation semantics are synchronous with span lifetime**: i.e., when `span.end()` on the parent is gated on the join of all child tool futures. It is valid for runtimes that (1) dispatch tools serially within a turn, (2) propagate cancel...",
    "decision_boundary": "The architectural choice is between two bounded designs, and the boundary is drawn at **who owns the parent span's end timestamp**: - **Join-owned parent (safe):** The turn span's `end()` is deferred until all child tool futures settle *or* are hard-aborted. Cancellation closes child spans first (with `status = ERROR`, `error.type = \"cancelled\"`), then the p...",
    "operational_effect": "The practical consequence is a **silent telemetry integrity failure that masquerades as a latency anomaly**. Turn-level p99 latency appears to spike (tool time bucketed into the wrong turn), tool-call error rates under-report (cancelled-then-retried calls appear as two successes, since the cancelled span's `status` was never set to ERROR before the adapter r..."
  },
  "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": "ee077ce2b0059bdc9891715777678bd88a82f6b809b76bc1875ba54f24420234",
    "verified_classes": [
      "SpanCausalityViolation",
      "GenAISpan"
    ],
    "verified_functions": [
      "close_tool_span",
      "run_turn_join_owned",
      "run_turn_broken",
      "end",
      "is_closed"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "SpanCausalityViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
