{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-and-survive-cross-process-genai-span-conflation-when-opentelemetry-token-counters-are-keyed-by-model-name-rather-than-by-i",
  "title": "How does an instance detect and survive cross-process GenAI span conflation when OpenTelemetry token counters are keyed by model name rather than by invocation identity",
  "date_of_record": "2026 November 30",
  "scope": "Applies to LLM/agent runtimes that emit OpenTelemetry GenAI spans (`gen_ai.*` attributes) and aggregate token accounting across concurrent or resumed invocations within a single tracer provider. Does not apply to single-shot, single-invocation processes where one model call maps to exactly one span lifetime with no fan-out or replay.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-and-survive-cross-process-genai-span-conflation-when-opentelemetry-token-counters-are-keyed-by-model-name-rather-than-by-i.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-and-survive-cross-process-genai-span-conflation-when-opentelemetry-token-counters-are-keyed-by-model-name-rather-than-by-i.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-and-survive-cross-process-genai-span-conflation-when-opentelemetry-token-counters-are-keyed-by-model-name-rather-than-by-i.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1653,
    "python_slice_tokens": 226,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"wrong token counts.\" It is **identity conflation at the span-attribute layer**: OpenTelemetry's GenAI semantic conventions specify `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *per-span* attributes, but the operational accounting layer that consumes them frequently keys aggregates by the low-cardinality dimensions the c...",
    "what_was_observed": "A planner-executor agent emitted three `gen_ai.chat` spans for one user turn: a plan call, a tool-selection call, and a synthesis call — all against `gen_ai.request.model = \"gpt-4o\"`, all with `gen_ai.operation.name = \"chat\"`. The OTel collector's span-metric connector (`spanmetrics`) was configured with default dimensions, which collapse on `(service.name, span.name, gen_ai.request.model)`. The result: the dashboard...",
    "condition_of_validity": "The conflation is *benign* — and the naive aggregation is safe — only when all of the following hold: 1. Exactly one model invocation per `trace_id` per `gen_ai.request.model` (no fan-out). 2. No checkpoint/resume that re-emits spans under a new `span_id` within the same logical task. 3. The consumer reads usage from the *span* (per-span attributes are corre...",
    "decision_boundary": "The runtime must decide, per emission, whether the span is a **distinct invocation** (mint a fresh `invocation.id`, count tokens) or a **retry/replay of an existing invocation** (reuse the prior `invocation.id`, do not double-count). This decision cannot be made by the collector from convention attributes alone; it must be made at emission time by the agent ...",
    "operational_effect": "With `invocation.id` attached and the collector keyed on it, the planner-executor turn reports three distinct calls with correct per-call token attribution; the cost guard reads the sum, not the last span, and the budget breach is caught before the follow-up turn. On resume, the checkpoint carries the prior `invocation.id`, the re-emitted span is recognized ..."
  },
  "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": "afb1cf9d0f88265c9936a02aa68038447586da76d2b0423c5b4990ed8019e092",
    "verified_classes": [
      "InvocationIdentityError",
      "GenAiSpanEmitter"
    ],
    "verified_functions": [
      "__init__",
      "emit_chat_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "InvocationIdentityError"
    ],
    "sample_fail_closed_invariants": [
      "invocation.id resolved empty; aborting emission"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
