{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-commits-an-opentelemetry-genai-span-before-tool-call-resolution-attribute-set-divergence-across-parent-child-spans-and-t",
  "title": "What happens when an instance commits an OpenTelemetry GenAI span before tool-call resolution: attribute-set divergence across parent/child spans and the token-accounting double-count",
  "date_of_record": "2026 November 29",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) where a parent agent/invocation span and its child tool-call spans are written by different code paths, processes, or SDK versions. Does not apply to single-span, single-process instrumentation where the parent span's attributes are finalized after all children close.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-commits-an-opentelemetry-genai-span-before-tool-call-resolution-attribute-set-divergence-across-parent-child-spans-and-t.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-commits-an-opentelemetry-genai-span-before-tool-call-resolution-attribute-set-divergence-across-parent-child-spans-and-t.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-commits-an-opentelemetry-genai-span-before-tool-call-resolution-attribute-set-divergence-across-parent-child-spans-and-t.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2200,
    "python_slice_tokens": 382,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two distinct ways an agent span can \"finish,\" and only one of them is visible to the OpenTelemetry collector: 1. **Logical completion** — the agent loop has decided it is done and the span object is `.end()`-ed. At this instant the attribute set is frozen and shipped. 2. **Semantic completion** — every child tool-call span has resolved, and the agg...",
    "what_was_observed": "A tool-using agent loop (`plan → tool_call → observe → plan`) was instrumented so that: - The **agent span** (`gen_ai.operation.name=invoke_agent`, `gen_ai.agent.name=...`) is opened at turn start and ended by the orchestration coroutine when the model returns a message with no further tool calls. - Each **tool-call span** (`gen_ai.operation.name=execute_tool`, `gen_ai.tool.name=...`) is opened inside the tool execut...",
    "condition_of_validity": "The divergence is bounded and predictable under the following condition: > A parent GenAI agent span's attribute set is only semantically complete if, at the moment `.end()` is called, every child span that contributes to `gen_ai.usage.*` or to the aggregate tool inventory has already ended *and* its contribution has been synchronously folded into the parent...",
    "decision_boundary": "The boundary is not \"does the span have the right attributes\" but **\"is the parent's attribute set a function of the complete child set, or of a prefix of it?\"** - If the runtime can guarantee the parent is the *last* span in the turn to end (children joined before parent `.end()`), the convention's aggregate semantics hold and no guardrail is needed. - If t...",
    "operational_effect": "Downstream, the divergence manifests as three concrete operational symptoms, each of which looks like a different bug: 1. **Cost dashboards drift upward over long turns.** Turn-level cost computed from parent spans under-reports on multi-tool turns; cost computed from all-span sums over-reports because chat spans and the parent aggregate overlap. The drift i..."
  },
  "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": "0240b030a6550000dac29ea9e543d5ef711f7510eb88db72454a0bd3c1061079",
    "verified_classes": [
      "SpanFinalizationError",
      "GenAISpan"
    ],
    "verified_functions": [
      "finalize_agent_span",
      "end",
      "add_child"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "SpanFinalizationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
