{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-token-accounting-drift-when-opentelemetry-genai-spans-are-re-parented-across-agent-handoffs",
  "title": "Which invariants prevent token-accounting drift when OpenTelemetry GenAI spans are re-parented across agent handoffs",
  "date_of_record": "2026 November 25",
  "scope": "Applies to multi-agent systems that emit OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, `gen_ai.system`) and that hand off execution between agent instances via link-based or re-parented span contexts. Does not cover single-agent tracing, nor cost aggregation performed purely from billing-side metering.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-accounting-drift-when-opentelemetry-genai-spans-are-re-parented-across-agent-handoffs.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-accounting-drift-when-opentelemetry-genai-spans-are-re-parented-across-agent-handoffs.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-accounting-drift-when-opentelemetry-genai-spans-are-re-parented-across-agent-handoffs.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1606,
    "python_slice_tokens": 437,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a span's `gen_ai.usage.*` attributes as *terminal, additive facts about a single model invocation*. The tracing model, however, treats parent/child relationships as *structural, mutable topology*. These two contracts collide at handoff boundaries. When agent A delegates to agent B, the natural instrumentation pattern is t...",
    "what_was_observed": "A three-tier pipeline (planner → executor → verifier) instrumented each hop as a child span. The planner span recorded `input_tokens=8200, output_tokens=640`. The executor received the planner's full output plus a 6k-token tool schema and recorded `input_tokens=9100`. The verifier received planner output + executor output + rubric and recorded `input_tokens=11800`. A dashboard summing `gen_ai.usage.input_tokens` acro...",
    "condition_of_validity": "The additive-usage invariant holds **only if** every span in a trace represents a *disjoint* model invocation whose prompt is not a superset of any other span's prompt on the same trace path. This is violated whenever: 1. **Context forwarding** — a child agent's prompt includes the parent's prompt verbatim (the common case in planner/executor/verifier topolo...",
    "decision_boundary": "The boundary is: **does the child span's prompt contain tokens already billed on an ancestor span?** - If **no** (fan-out to independent sub-tasks, parallel tool calls with distinct inputs) → additive summation across the trace is valid; parent-child edges are safe. - If **yes** (sequential handoff with context forwarding) → the trace must carry a `gen_ai.us...",
    "operational_effect": "Budget enforcement built on trace-summed tokens over-fires: an agent that forwards context through three hops appears to consume ~1.5× its real budget, tripping circuit breakers early and starving downstream work. Conversely, `max`-based dedup under-fires on legitimate retries, letting a flaky tool loop exhaust provider quota before the breaker trips. The co..."
  },
  "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": "5314c04e41084e77d61e32e3bfe80d5fdd5dd0971a49561c4355ed19053c9619",
    "verified_classes": [
      "TokenAccountingDrift",
      "GenAISpan"
    ],
    "verified_functions": [
      "aggregate_trace_usage",
      "enforce_summable_trace"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAccountingDrift"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
