{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-span-attributes-against-tool-call-events-before-emitting-a-terminal-agent-span",
  "title": "Under what conditions must an instance reconcile OpenTelemetry GenAI span attributes against tool-call events before emitting a terminal agent span",
  "date_of_record": "2026 November 30",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the `gen_ai.*` semantic conventions (agent spans, `gen_ai.tool.call` events, and `gen_ai.usage.*` token counters) across a multi-step tool-using execution. Does not apply to single-shot inference calls with no tool events, nor to runtimes that emit only flat traces without span hierarchy.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-span-attributes-against-tool-call-events-before-emitting-a-terminal-agent-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-span-attributes-against-tool-call-events-before-emitting-a-terminal-agent-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-span-attributes-against-tool-call-events-before-emitting-a-terminal-agent-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1883,
    "python_slice_tokens": 595,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"missing telemetry.\" It is **attribute/event divergence at span close time**: the terminal agent span's `gen_ai.usage.input_tokens` / `output_tokens` and `gen_ai.operation.name` attributes are computed from one source of truth (the model client's cumulative counter), while the child `gen_ai.tool.call` events and tool child-spans are emitte...",
    "what_was_observed": "A three-step agent executed: (1) model call → tool `search` → (2) model call → tool `fetch` → (3) model call → final answer. During step 2, the `fetch` tool call timed out at the executor and was **retried once internally** by the tool wrapper before returning. The wrapper emitted two `gen_ai.tool.call` events (attempt 1 failed, attempt 2 succeeded) but the model client saw **one** tool result and incremented its tok...",
    "condition_of_validity": "The invariant that must hold before a terminal agent span may be closed: 1. **Token attribution completeness:** `gen_ai.usage.input_tokens` and `output_tokens` on the terminal span equal the sum over *all* model calls in the run, including retried model calls, not the last accumulator value. 2. **Event/attribute cardinality agreement:** the number of distinc...",
    "decision_boundary": "The reconciler must choose between **emit-as-terminal** and **emit-as-provisional** at span close. The boundary is crossed when: - `sum(per-call usage)` ≠ `terminal span usage` beyond a rounding tolerance, **or** - `distinct(tool.call.id)` < `count(tool.call events)` without retry marking, **or** - a model call's usage was observed but its result was discard...",
    "operational_effect": "Consequences of skipping reconciliation: - **Cost attribution drift** that is invisible per-span but compounds across a fleet; a 30% tool-retry rate yields a systematic under- or over-count depending on which side is canonical. - **Loop detection false positives** from retry events counted as reasoning steps, triggering premature agent termination or escalat..."
  },
  "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": "bd4468259d8bed0f02d7b505832cd688f3fe7492f4e8dc40e4fdefb13bacbd20",
    "verified_classes": [
      "GenAISpanReconciliationError",
      "ToolCallEvent",
      "ModelCallUsage",
      "AgentRunTelemetry"
    ],
    "verified_functions": [
      "reconcile_terminal_span",
      "close_agent_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 7,
    "raised_exceptions": [
      "GenAISpanReconciliationError"
    ],
    "sample_fail_closed_invariants": [
      "terminal span missing gen_ai.usage.* attributes; cannot certify"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
