{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-refuse-to-merge-a-resumed-agent-trace-after-opentelemetry-genai-span-re-emission-corrupts-token-accounting",
  "title": "When must an instance refuse to merge a resumed agent trace after OpenTelemetry GenAI span re-emission corrupts token accounting",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agents that persist OTel GenAI spans (agent invocation, tool-call events, `gen_ai.usage.*` attributes) to a durable store and re-emit or resume them after a mid-task checkpoint. Does not apply to stateless single-shot inference where each span lifecycle is bounded by one process and no replay occurs.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-merge-a-resumed-agent-trace-after-opentelemetry-genai-span-re-emission-corrupts-token-accounting.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-merge-a-resumed-agent-trace-after-opentelemetry-genai-span-re-emission-corrupts-token-accounting.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-merge-a-resumed-agent-trace-after-opentelemetry-genai-span-re-emission-corrupts-token-accounting.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1927,
    "python_slice_tokens": 290,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *cumulative counters for one logical generation*, attached to a span whose lifetime is the generation. The spec is silent on what happens when the same logical agent invocation is *resumed*: a checkpointed agent restarts, rehydrates its message history, and r...",
    "what_was_observed": "A research agent runs a 14-step plan. Step 9 issues a `execute_sql` tool call. The tool call is slow; the orchestrator's checkpoint fires at step 9 (message history persisted, including the assistant's tool-call request but *not* the tool result, which has not returned). The process is preempted at T+41s. At T+90s the orchestrator resumes. It rehydrates the message history, sees an unresolved tool call, and re-issues...",
    "condition_of_validity": "The invariant (sum of usage == billed-once) holds only under the following condition, which must be checked *before* any merge: A resumed span is safe to merge with its predecessor **iff** the resumed instance can prove that the pre-checkpoint generation's tokens were either (a) never billed by the provider, or (b) billed and already accounted in a span that...",
    "decision_boundary": "The decision boundary is the point at which the resumed instance must choose between three actions on encountering a same-`trace_id` span with `status=UNSET` and matching `gen_ai.operation.name`: - **Merge** — fold the resumed span into the predecessor, summing usage. Valid only if billing state proves the predecessor was billed and the resumed generation di...",
    "operational_effect": "The operational effect of getting this wrong is not a crash; it is a slow drift in three coupled metrics that are individually plausible and jointly incoherent. Budget enforcement drifts high or low depending on which provider's re-billing semantics the tenant happens to hit. Trace-based cost attribution diverges from invoice by a factor that grows with resu..."
  },
  "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": "9c785b5830acbae706766618029138ef7aaeeb1a55f672f3db2ff7b853ddc136",
    "verified_classes": [
      "ResumeMergeUndefinedError",
      "BillingState",
      "Span"
    ],
    "verified_functions": [
      "resolve_resumed_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "ResumeMergeUndefinedError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
