{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-abandon-a-genai-agent-span-because-tool-call-child-spans-outlive-the-parent-s-context-deadline",
  "title": "When must an instance abandon a GenAI agent span because tool-call child spans outlive the parent's context deadline",
  "date_of_record": "2026 December 1",
  "scope": "Applies to LLM agent runtimes that emit OpenTelemetry spans under the `gen_ai.*` semantic conventions, specifically `gen_ai.agent`, `gen_ai.tool`, and `gen_ai.chat` spans where a parent agent span closes before its tool-call children finish. Does not apply to single-shot inference calls with no tool fan-out, nor to runtimes that buffer all spans until the root closes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-abandon-a-genai-agent-span-because-tool-call-child-spans-outlive-the-parent-s-context-deadline.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-abandon-a-genai-agent-span-because-tool-call-child-spans-outlive-the-parent-s-context-deadline.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-abandon-a-genai-agent-span-because-tool-call-child-spans-outlive-the-parent-s-context-deadline.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1842,
    "python_slice_tokens": 380,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two ways an agent span can \"end,\" and conflating them corrupts the trace tree and the token ledger: 1. **Logical completion** — the agent has produced a final assistant message and stopped issuing tool calls. This is a *reasoning* event. 2. **Span completion** — `span.end()` is called, freezing the span's `end_time`, its `status`, and its attribute...",
    "what_was_observed": "A planning agent (`gen_ai.agent.name = \"planner\"`) issued a parallel fan-out of three tool calls: a retrieval tool, a code-execution tool, and a web-fetch tool. The web-fetch tool was slow — 41 seconds against a 30-second parent context deadline. Trace sequence as exported: - `planner` span: `start_time = T0`, `end_time = T0+30.0s`, `status = ERROR` (deadline exceeded, set by the runtime's cancellation path). - `tool...",
    "condition_of_validity": "The invariant \"parent ends after all children\" holds only under one of two conditions, and the runtime must know which one it is in: - **Structured concurrency:** the parent's `end()` is deferred until a `join()` over all spawned child spans completes, *including* children that were cancelled. Cancellation must propagate downward and each child must call `sp...",
    "decision_boundary": "The runtime must make an explicit decision at the moment the parent context deadline fires, and the decision cannot be deferred to the exporter: - If the tool executor honors cancellation within a bounded grace window (say, 500ms), **wait** for children to end, then end the parent with the true `end_time`. The parent duration now exceeds the deadline; that i...",
    "operational_effect": "Once the invariant is enforced, three downstream properties become reliable: 1. **Token ledger closure.** Sum of leaf `gen_ai.usage.output_tokens` equals the value attributed to the enclosing agent span, because the agent span cannot close before its leaves. The 1180 discarded tokens become visible. 2. **Duration monotonicity.** A trace's critical path is th..."
  },
  "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": "3969947d0e11ee7ec3576481ba31bbc05e1e6b4ab7715fec0ff4aa918630ad50",
    "verified_classes": [
      "UnjoinedSpanError",
      "Span"
    ],
    "verified_functions": [
      "close_agent_span",
      "demo",
      "end_span"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "UnjoinedSpanError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
