{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-non-monotonic-token-accounting-when-genai-spans-are-emitted-from-resumed-and-retried-agent-turns",
  "title": "How should an instance reconcile non-monotonic token accounting when GenAI spans are emitted from resumed-and-retried agent turns",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans following the GenAI semantic conventions (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, `gen_ai.request.model`) across checkpoint-resume and tool-retry boundaries. Does not apply to stateless single-shot inference where each span maps 1:1 to a distinct billable request.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-non-monotonic-token-accounting-when-genai-spans-are-emitted-from-resumed-and-retried-agent-turns.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-non-monotonic-token-accounting-when-genai-spans-are-emitted-from-resumed-and-retried-agent-turns.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-non-monotonic-token-accounting-when-genai-spans-are-emitted-from-resumed-and-retried-agent-turns.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1556,
    "python_slice_tokens": 207,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token usage as an *additive, monotonic counter* attached to the closing span of an operation. This is correct for a fire-and-forget inference call: one span, one provider response, one `usage` block copied verbatim into span attributes. It is **wrong** for agent turns that resume from a checkpoint or retry a tool call, be...",
    "what_was_observed": "An agent executing a three-tool plan (search → fetch → summarize) was checkpointed after the `fetch` tool returned a 12 KB document. The checkpoint stored conversation state but *not* the in-flight span context. On resume: 1. The runtime re-issued the `fetch` tool call because the tool result was not durably persisted alongside the checkpoint — only the pre-tool message history was. 2. The `fetch` span was emitted **...",
    "condition_of_validity": "The double-counting is bounded and predictable under a specific condition: **the resume boundary must be a span boundary, and every span must carry a stable turn-level correlation attribute** (`gen_ai.conversation.id` or a custom `agent.turn.id`) that survives checkpoint serialization. If the turn ID is regenerated on resume — which is the default when the r...",
    "decision_boundary": "The runtime must choose, at the moment of checkpoint serialization, between two mutually exclusive accounting modes: - **Delta mode:** each span reports only the usage of its own HTTP call; the turn total is `sum(span.usage)` over spans sharing the turn ID. Requires idempotency keys on tool spans so retries are *observable* but *excluded* from the sum (or in...",
    "operational_effect": "Instrumenting for delta mode with persisted turn IDs converts the reconciliation problem from \"three irreconcilable numbers\" into a single auditable query: `sum(gen_ai.usage.input_tokens) where agent.turn.id = T and not agent.tool.retry`. The provider invoice is then checked against the sum *including* retries; the delta between the two is the exact cost of ..."
  },
  "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": "6efee9f5808825485cc632812fff32e1283dbf18f7242590cb8a6cc2a37f2dad",
    "verified_classes": [
      "TurnAccountingReconciliationError"
    ],
    "verified_functions": [
      "resume_turn"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TurnAccountingReconciliationError"
    ],
    "sample_fail_closed_invariants": [
      "checkpoint missing agent.turn.id; refusing to resume with derived trace-rooted ID"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
