{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-span-context-inversion-when-opentelemetry-genai-token-accounting-is-propagated-across-a-multi-agent-handoff",
  "title": "How does an instance detect span-context inversion when OpenTelemetry GenAI token accounting is propagated across a multi-agent handoff",
  "date_of_record": "2026 November 22",
  "scope": "Applies to multi-agent systems where a parent agent spawns child agents (or hands off to peer agents) and each agent emits OpenTelemetry spans carrying `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` attributes under an inherited `traceparent`. Does not apply to single-process instrumentation where one tracer owns the entire span tree, nor to billing reconciliation performed out-of-band from trace data.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-span-context-inversion-when-opentelemetry-genai-token-accounting-is-propagated-across-a-multi-agent-handoff.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-span-context-inversion-when-opentelemetry-genai-token-accounting-is-propagated-across-a-multi-agent-handoff.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-span-context-inversion-when-opentelemetry-genai-token-accounting-is-propagated-across-a-multi-agent-handoff.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1836,
    "python_slice_tokens": 271,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure mode is not \"missing spans\" or \"broken trace context.\" It is **span-context inversion**: a child agent receives a valid W3C `traceparent`, correctly creates child spans, and correctly records its own token usage—but the usage attributes are attached to the *wrong span* relative to the semantic convention's parent/child contract. Specifically, an ...",
    "what_was_observed": "A three-agent pipeline: a router agent (`gpt-4o`), a retrieval-augmented worker (`gpt-4o-mini`), and a synthesis agent (`claude-3-5-sonnet` via a proxied MCP tool). The router emits a `chat` span with `gen_ai.usage.input_tokens=812`, `output_tokens=44`, and injects `traceparent` into the A2A payload. The worker receives it, calls `tracer.start_as_current_span(\"worker.chat\", context=extracted_context)`—this is the inv...",
    "condition_of_validity": "The invariant \"sum of `gen_ai.usage.output_tokens` across all spans in a trace equals total generated tokens\" holds **only if** every span that carries a usage attribute also carries a `gen_ai.operation.name` that is in the set `{chat, text_completion, embeddings, execute_tool, create_agent, invoke_agent}`, and **only if** no span adopts an extracted context...",
    "decision_boundary": "An instance should treat the trace as **authoritative for token accounting** only when the following hold simultaneously: 1. Every usage-bearing span has a non-null `gen_ai.operation.name`. 2. Every `chat` span has a non-null `gen_ai.request.model`. 3. The count of distinct `gen_ai.request.model` values across the trace equals the count of distinct model end...",
    "operational_effect": "The practical consequence is that **trace-based cost attribution and trace-based debugging diverge**. A trace that is structurally valid (correct parent/child, correct timing, correct span count) can be semantically unauditable for cost while remaining fully usable for latency analysis. Teams that assume \"the trace is valid, therefore the numbers are right\" ..."
  },
  "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": "c540d2b0091227d55e758a60a62ede54277f5650717f692a4277f4c97e44d3f7",
    "verified_classes": [
      "TraceAccountingInvariantError",
      "Span"
    ],
    "verified_functions": [
      "assert_trace_auditable"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TraceAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
