{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-token-accounting-fidelity-when-otel-genai-spans-are-re-parented-across-an-agent-handoff",
  "title": "Why does an instance lose token-accounting fidelity when OTel GenAI spans are re-parented across an agent handoff?",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) where a sub-agent or tool-executor instance is spawned, given a delegated task, and expected to contribute `gen_ai.usage.input_tokens` / `output_tokens` back to a parent span's aggregate. Does not apply to single-process, single-span inference calls with no cross-instance handoff.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-token-accounting-fidelity-when-otel-genai-spans-are-re-parented-across-an-agent-handoff.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-token-accounting-fidelity-when-otel-genai-spans-are-re-parented-across-an-agent-handoff.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-token-accounting-fidelity-when-otel-genai-spans-are-re-parented-across-an-agent-handoff.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1914,
    "python_slice_tokens": 302,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two structurally different ways to account for tokens in a GenAI trace, and they diverge the moment a span crosses an instance boundary: 1. **Span-local accounting** — each `gen_ai.chat` / `gen_ai.tool` span carries its own `gen_ai.usage.*` attributes, and totals are computed by summing leaf spans at read time. 2. **Parent-aggregate accounting** — ...",
    "what_was_observed": "A coordinator agent (instance A) delegates a 40k-token document-analysis task to a sub-agent (instance B) running in a separate worker with its own OTel SDK. The handoff is a structured message carrying `traceparent`. Observed trace behavior: - Instance A emits `gen_ai.agent.invoke` (orchestrator) with `gen_ai.usage.input_tokens=12_400` covering *its own* planning turns. - Instance B receives `traceparent`, but its S...",
    "condition_of_validity": "The invariant that must hold for token accounting to be correct across a handoff is: > **Every inference span that consumes billable tokens must (a) share the root `trace_id` of the originating agent invocation, and (b) carry `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` on a span whose `gen_ai.operation.name` is `chat` (or `text_completion`),...",
    "decision_boundary": "The architect must choose, at design time, between two defensible postures: - **Trace-coherence posture:** Treat the handoff as a hard requirement to propagate and *validate* `traceparent`. The child instance must assert `SpanContext.is_valid()` on extraction and, if invalid, either (a) fail the handoff loudly or (b) synthesize a link (`SpanLink`) back to th...",
    "operational_effect": "Concretely: 1. **Budget enforcement drifts.** A coordinator enforcing a per-task token budget by reading its own aggregate will under-count by exactly the delegated fraction and will not trip its budget guard until the *next* task — the overrun is deferred, not prevented. Guardrails that read the parent aggregate must be paired with a per-instance cap on 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": "b0675477fa20d27963329cdc57040621457145bd3f4a571265b1bfbfaf6c262f",
    "verified_classes": [
      "TokenAccountingDivergence",
      "HandoffUsage"
    ],
    "verified_functions": [
      "reconcile_handoff"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [
      "child spans did not join parent trace_id; parent aggregate is structurally unable to include delegated tokens"
    ],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
