{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-refuse-to-emit-a-terminal-agent-span-the-opentelemetry-genai-parent-span-completeness-invariant-under-mid-tool-call-token-budget",
  "title": "When must an instance refuse to emit a terminal agent span: the OpenTelemetry GenAI parent-span completeness invariant under mid-tool-call token-budget exhaustion",
  "date_of_record": "2026 November 19",
  "scope": "Applies to agents instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.tool.name`, `gen_ai.agent.*`) that emit one parent `invoke_agent` span per reasoning turn and child `execute_tool` spans per tool call. Does not apply to stateless single-shot completions with no tool dispatch, nor to telemetry backends that recompute cost from raw usage counters independent of span lifecycle.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-terminal-agent-span-the-opentelemetry-genai-parent-span-completeness-invariant-under-mid-tool-call-token-budget.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-terminal-agent-span-the-opentelemetry-genai-parent-span-completeness-invariant-under-mid-tool-call-token-budget.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-terminal-agent-span-the-opentelemetry-genai-parent-span-completeness-invariant-under-mid-tool-call-token-budget.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1441,
    "python_slice_tokens": 226,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a span as a *record of a completed unit of work*, closed by `span.end()` with a status of `OK` or `ERROR`. Cost and token telemetry (`gen_ai.usage.*`) are attributes stamped onto that span. The non-obvious boundary is this: **a span's usage attributes are only trustworthy if the span reached a terminal state that correspo...",
    "what_was_observed": "A research agent looped over a document corpus, dispatching `execute_tool` spans for a `search` tool. The per-turn parent `invoke_agent` span carried `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` from the model response. The runtime enforced a hard budget: when cumulative `output_tokens` exceeded 40,000, a supervisor raised `TokenBudgetExhausted` inside the tool-dispatch coroutine — *after* the model r...",
    "condition_of_validity": "The invariant holds — and the failure is real — only when all of the following are true: 1. The parent span's usage attributes are *derived* from child work (tool results folded into a final aggregate) rather than stamped atomically from the model response at response-receipt time. 2. The abandonment trigger (budget, cancellation, timeout) can fire *between*...",
    "decision_boundary": "The decision an instrumented runtime must make at teardown is not \"end the span or leak it\" but \"which terminal state does this span's accounting support?\" The boundary: - If the model response for the current turn was received and its usage recorded, the parent span MUST end with status `ERROR` (or a dedicated `gen_ai.agent.abandoned = true` attribute) and ...",
    "operational_effect": "Enforcing the boundary converts a silent cost leak into a loud, traceable one. The abandoned turn now surfaces as an `ERROR` parent span carrying `gen_ai.usage.output_tokens = 1847` and `gen_ai.agent.abandoned = true`, so cost rollups stay accurate and the error-rate SLO correctly registers the budget exhaustion. The tradeoff is that `OK` no longer means \"th..."
  },
  "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": "a1e69279403c34164dd1b138ae036ff91ed3d6424a406268ff22af4bcf789f89",
    "verified_classes": [
      "UnaccountedSpendOnOkSpan",
      "AgentSpan"
    ],
    "verified_functions": [
      "teardown_parent_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "UnaccountedSpendOnOkSpan"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
