{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-refuse-to-emit-genai-tool-call-lineage-spans-when-the-parent-generation-span-has-already-been-closed-by-a-token-acc",
  "title": "In what scenarios must an instance refuse to emit GenAI tool-call lineage spans when the parent generation span has already been closed by a token-accounting finalizer",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agents that emit OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.*`) where tool invocations are modeled as child spans of an `invoke_agent` / `chat` generation span, and where a token-accounting finalizer independently closes the generation span on a usage callback. Does not apply to batch/offline trace export where span lifecycle is owned by a single scheduler.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-emit-genai-tool-call-lineage-spans-when-the-parent-generation-span-has-already-been-closed-by-a-token-acc.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-emit-genai-tool-call-lineage-spans-when-the-parent-generation-span-has-already-been-closed-by-a-token-acc.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-emit-genai-tool-call-lineage-spans-when-the-parent-generation-span-has-already-been-closed-by-a-token-acc.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1777,
    "python_slice_tokens": 365,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"missing spans\" or \"wrong token counts.\" It is a **lineage/accounting ordering conflict**: the GenAI conventions require a tool-call child span (`execute_tool`) to carry `gen_ai.tool.call.id`, `gen_ai.tool.name`, and a `parent_span_id` pointing at the generation span that requested it, *and* the generation span must carry the aggregate `ge...",
    "what_was_observed": "A streaming `invoke_agent` turn issued three parallel tool calls. The model's terminal chunk arrived with `finish_reason: tool_calls` and a `usage` block. The token-accounting finalizer fired on that chunk, wrote `gen_ai.usage.input_tokens=1841`, `gen_ai.usage.output_tokens=212`, and called `span.end()` on the generation span at `t=302ms`. The three `execute_tool` spans were emitted by the executor as the tools retur...",
    "condition_of_validity": "The invariant that must hold is a **causal join before close**: a generation span may only be `end()`ed after (a) every tool call it requested has either returned or been explicitly abandoned, and (b) the usage aggregate has been written. Equivalently: This holds trivially in non-streaming, single-tool-call agents where `finish_reason` and tool completion co...",
    "decision_boundary": "When the finalizer observes `finish_reason: tool_calls` and the count of outstanding tool futures for that generation is `> 0`, the instance must **not** close the generation span. It has two admissible choices: 1. **Defer close to the join.** Register the usage aggregate as a pending attribute, hand the span handle to the tool-execution coordinator, and let...",
    "operational_effect": "Enforcing the join-before-close invariant converts a silent, backend-dependent lineage loss into a loud, local error. In practice this surfaces as a `ToolLineageParentClosedError` raised at span-emit time, which the executor catches and resolves by re-parenting to the pending finalizer span. The observable effects: - Tool spans survive lineage reconstruction..."
  },
  "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": "81a1a6173f0a10f206919db57737e270662ae22d35b0511b8f58d6f0053557c2",
    "verified_classes": [
      "ToolLineageParentClosedError",
      "Span",
      "GenerationContext"
    ],
    "verified_functions": [
      "finalize_usage_on_finish",
      "_write_usage_and_close",
      "emit_tool_span",
      "on_tool_complete",
      "end",
      "is_ended"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "RuntimeError",
      "ToolLineageParentClosedError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
