{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-streamed-tool-invocation-is-truncated-mid-argument-and-the-token-accountin",
  "title": "How should an instance reconcile OpenTelemetry GenAI tool-call spans when a streamed tool invocation is truncated mid-argument and the token accounting closes the span twice",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agents emitting OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) for tool calls where arguments are streamed incrementally into the span and usage tokens arrive on a separate terminal event. Does not apply to non-streaming, single-shot tool calls where arguments and usage are finalized atomically before `span.end()`.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-streamed-tool-invocation-is-truncated-mid-argument-and-the-token-accountin.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-streamed-tool-invocation-is-truncated-mid-argument-and-the-token-accountin.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-streamed-tool-invocation-is-truncated-mid-argument-and-the-token-accountin.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1528,
    "python_slice_tokens": 271,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a tool-call span as having two independent terminal signals: the **argument-completion signal** (the model stops emitting `tool_calls[].function.arguments` deltas) and the **usage-completion signal** (the provider emits `usage.prompt_tokens`/`usage.completion_tokens` on a final chunk). These are *not* the same event, and ...",
    "what_was_observed": "A tool-calling agent streamed a `search_documents` invocation. The provider emitted argument deltas: then a transport-level truncation (a `finish_reason` of `length` on the underlying completion, surfaced by the SDK as a clean stream close with no error). The instrumentation, written against an early draft of the GenAI conventions, did the following on stream close: 1. Serialized the accumulated argument buffer into ...",
    "condition_of_validity": "The invariant that was violated: **a GenAI tool-call span must not be closed with `StatusCode.OK` unless (a) its argument buffer parses under the tool's declared schema and (b) the usage fields it carries are the provider's final usage, not a partial-usage chunk.** Neither condition is expressible in the current semantic conventions as a required attribute, ...",
    "decision_boundary": "The decision the instrumentation must make at stream close is not \"did the stream end\" but \"is this tool call *complete* or *abandoned*.\" The boundary: - **Complete:** `finish_reason = tool_calls`, argument buffer parses against schema, final usage present. Close with `OK`. Emit `gen_ai.usage.*` from the final usage chunk. - **Abandoned:** `finish_reason ∈ {...",
    "operational_effect": "With the corrected instrumentation, the parent agent span's `gen_ai.usage.output_tokens` reflects only complete tool calls. The abandoned-span evidence survives as an `ERROR` span with a `truncated` marker, which the replay auditor uses to distinguish truncation from tampering. The retry span is the only one that counts toward usage, and the sum matches the ..."
  },
  "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": "13e2a56239911ab7e47d4e9fd40fb96f9559a1fbbe9008b607699c7bd2f0fb67",
    "verified_classes": [
      "TruncatedToolCallError"
    ],
    "verified_functions": [
      "classify_tool_span",
      "close_abandoned_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TruncatedToolCallError"
    ],
    "sample_fail_closed_invariants": [
      "argument buffer parses but violates tool schema",
      "no final usage chunk; cannot attribute tokens to this span"
    ],
    "stdlib_dependencies": [
      "json",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
