{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-reconcile-token-accounting-across-a-resumed-agent-span-and-why-the-opentelemetry-genai-convention-silently-double-counts",
  "title": "When must an instance reconcile token accounting across a resumed agent span, and why the OpenTelemetry GenAI convention silently double-counts",
  "date_of_record": "2026 December 2",
  "scope": "Applies to agents that emit OpenTelemetry GenAI spans (`gen_ai.*`) across a checkpoint/resume boundary or an MCP/A2A handoff where the receiving instance re-emits or re-parents an in-flight span. Does not apply to single-shot, single-process invocations that never cross a serialization boundary.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-token-accounting-across-a-resumed-agent-span-and-why-the-opentelemetry-genai-convention-silently-double-counts.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-token-accounting-across-a-resumed-agent-span-and-why-the-opentelemetry-genai-convention-silently-double-counts.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-token-accounting-across-a-resumed-agent-span-and-why-the-opentelemetry-genai-convention-silently-double-counts.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1842,
    "python_slice_tokens": 253,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes on the *span that produced the completion* — they are cumulative counters describing one model invocation, not a running ledger. The failure mode here is not \"wrong token count.\" It is a **semantic collision between the attribute's per-span meanin...",
    "what_was_observed": "A tool-using agent (`execute_tool` spans nested under a `chat` span) hit a token-budget guard at ~70% of a 128k window during a long multi-step turn. The orchestrator checkpointed state and the process was rescheduled onto a new instance. The resume path followed the conventional pattern: 1. Load checkpoint (message history + partial tool results). 2. Open a fresh parent `chat` span with the same `gen_ai.conversation...",
    "condition_of_validity": "The deduplication problem is only well-defined under the following invariant: > **A token-usage attribute is valid only on a span whose `(trace_id, span_id)` pair was never exported before the current process began.** Continuation work MUST open a *new* span with a *new* span_id, set usage to *incremental* tokens consumed since resume, and link (not parent) ...",
    "decision_boundary": "The boundary is whether the pre-crash span has crossed the export horizon. The agent must decide per-span: - **Span not yet exported** (still in the batch processor's queue, process died before flush): safe to re-create with the same logical content and cumulative usage — the collector never saw it. But this is only knowable if the exporter's flush state is ...",
    "operational_effect": "Enforcing the invariant changes three things: 1. **Resume cost is incremental, not cumulative.** The budget guard must be fed `checkpointed_watermark + sum(incremental usage on continuation spans)`. This requires the checkpoint to persist the watermark alongside message history — a field most agent state schemas omit entirely. 2. **Trace topology becomes a D..."
  },
  "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": "1ffd15c6392a71fe99190ba1840cbfdcf721551ab20d4db7fc75982a6e051c0a",
    "verified_classes": [
      "TokenAccountingReconciliationError",
      "SpanUsage",
      "Checkpoint"
    ],
    "verified_functions": [
      "reconcile_resume"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAccountingReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
