{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-token-accounting-fidelity-when-opentelemetry-genai-spans-are-re-emitted-across-checkpoint-resume-boundaries",
  "title": "Why does an instance lose token-accounting fidelity when OpenTelemetry GenAI spans are re-emitted across checkpoint/resume boundaries",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agent runtimes that emit OTel `gen_ai.*` spans per tool call and per LLM invocation, and that persist/serialize span state across mid-task checkpoint/resume, worker migration, or replay. Does not apply to single-shot, non-checkpointed invocations where the span lifecycle is bound strictly to a single process lifetime.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-token-accounting-fidelity-when-opentelemetry-genai-spans-are-re-emitted-across-checkpoint-resume-boundaries.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-token-accounting-fidelity-when-opentelemetry-genai-spans-are-re-emitted-across-checkpoint-resume-boundaries.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-token-accounting-fidelity-when-opentelemetry-genai-spans-are-re-emitted-across-checkpoint-resume-boundaries.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1810,
    "python_slice_tokens": 309,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The OTel GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as **cumulative-per-span counters** — they describe the total consumption attributable to the *operation* the span represents. Agent runtimes, however, frequently treat these attributes as **incremental deltas** when they re-emit or resume a span. These two...",
    "what_was_observed": "A multi-step agent (planner → 4 tool calls → synthesizer) ran under a runtime that checkpoints after each tool call. Each LLM invocation emits one `chat` span; each tool call emits one `execute_tool` span. The checkpoint serialized the in-flight span context, including `gen_ai.usage.input_tokens=1180`, `gen_ai.usage.output_tokens=340`, and `gen_ai.usage.total_tokens=1520` for the planner span, which had *not yet been...",
    "condition_of_validity": "The cumulative-per-span reading is only valid when the span's start and end bound the entire operation. Checkpoint/resume breaks this: the operation's lifetime now spans two process lifetimes and one serialization boundary, but the span's `start_time_unix_nano` is inherited from the original, so the span *claims* to cover the whole operation while its attrib...",
    "decision_boundary": "The architectural fork is **when to end the span relative to the checkpoint**. Two defensible designs, one invalid: - **End-before-checkpoint (valid):** End the span, flush it, checkpoint *after* export. On resume, a new span begins with a `link` back. Cumulative semantics hold per span; the aggregator must follow links. Cost: trace becomes a linked chain, n...",
    "operational_effect": "The practical consequence is that **token accounting becomes non-monotonic and non-reconcilable across the resume boundary**, and — critically — the error is *directional and predictable*: overwrite-resume undercounts by exactly the pre-checkpoint consumption; append-resume overcounts by exactly the pre-checkpoint consumption. This means budget-enforcement l..."
  },
  "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": "43b5f24c4eb1e21e975385d45a877f388570dad3094d1b4ecd37f99b565530fd",
    "verified_classes": [
      "UsageAccountingDivergence"
    ],
    "verified_functions": [
      "reconcile_resumed_span_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "UsageAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [
      "non-monotonic total_tokens across resume boundary"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
