{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-child-agent-span-token-counts-when-a-tool-call-span-is-retried-across-a-transport-boundary",
  "title": "How should an instance reconcile child agent-span token counts when a tool-call span is retried across a transport boundary",
  "date_of_record": "2026 November 28",
  "scope": "Applies to any instrumented agent runtime emitting OpenTelemetry GenAI spans where a tool call is retried (timeout, transport reset, 5xx) and each attempt re-emits `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` on its own span under the same logical `gen_ai.tool.name` and parent agent span. Does not address streaming partial-usage spans, batch inference, or providers that report usage only at the parent request level.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-child-agent-span-token-counts-when-a-tool-call-span-is-retried-across-a-transport-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-child-agent-span-token-counts-when-a-tool-call-span-is-retried-across-a-transport-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-child-agent-span-token-counts-when-a-tool-call-span-is-retried-across-a-transport-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1956,
    "python_slice_tokens": 411,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.*_tokens` as **per-span facts about a single model invocation**, not as per-logical-operation facts. A retried tool call is, from the agent's perspective, one operation; from the span tree's perspective it is N sibling spans, each of which may carry its own usage attributes. The failure mode is not \"wrong nu...",
    "what_was_observed": "A research agent executing a `search_documents` tool against a flaky internal endpoint. Transport timeout set at 8s; the tool wrapper retries twice with backoff. The first attempt's request was actually *received and executed* by the backend, whose response was lost to a connection reset. Attempt 2 succeeded and returned a 12k-token document set. Attempt 3 never fired (attempt 2 succeeded). Span tree emitted: Two thi...",
    "condition_of_validity": "The invariant this exposes is: > **A span's `gen_ai.usage.*_tokens` is valid only for the span's own terminal status. Summing usage across sibling spans under a retry-parent is valid only if every sibling is `OK` and no sibling is a retry of another.** Retries violate the second clause by construction. The convention provides no `gen_ai.retry.attempt` or `ge...",
    "decision_boundary": "The boundary is whether the retry wrapper can distinguish **\"attempt failed before the backend executed\"** from **\"attempt failed after the backend executed but before the client observed the result.\"** These are the same `status=ERROR` from the client's vantage, but they have opposite token-accounting consequences: - Fail-before-execute (connection refused,...",
    "operational_effect": "The concrete guardrail: **never let the agent's own budget manager and the observability backend share an aggregation function.** The budget manager must consume usage from the *span it is about to act on* (the synthesis call's own `input_tokens`), never from a sum over siblings. The observability backend may sum, but must tag any parent whose children inclu..."
  },
  "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": "135f016a77556cece2d4c507453a6ee32b591ccad5a53dc1c911aac5f34f131d",
    "verified_classes": [
      "UsageReconciliationError",
      "AttemptOutcome",
      "ToolAttempt",
      "AgentSpan"
    ],
    "verified_functions": [
      "enforce_budget",
      "truthful_usage",
      "reconcile_input_tokens"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
