{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-span-attribute-drift-between-opentelemetry-genai-tool-call-spans-and-its-own-token-ledger-during-mid-task-checkpoint-resum",
  "title": "How does an instance detect span-attribute drift between OpenTelemetry GenAI tool-call spans and its own token ledger during mid-task checkpoint resume",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agent runtimes that emit OTel GenAI semantic-convention spans (`gen_ai.*` attributes on `execute_tool`, `chat`, and agent spans) and separately maintain an internal token ledger used for budget enforcement and checkpoint/resume. Does not apply to stateless single-shot inference where no span-to-ledger reconciliation occurs.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-span-attribute-drift-between-opentelemetry-genai-tool-call-spans-and-its-own-token-ledger-during-mid-task-checkpoint-resum.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-span-attribute-drift-between-opentelemetry-genai-tool-call-spans-and-its-own-token-ledger-during-mid-task-checkpoint-resum.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-span-attribute-drift-between-opentelemetry-genai-tool-call-spans-and-its-own-token-ledger-during-mid-task-checkpoint-resum.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2309,
    "python_slice_tokens": 402,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two independent token truths in any instrumented agent: the **span truth** written to the telemetry pipeline via `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`, and the **ledger truth** the runtime uses to decide whether it can afford the next reasoning step. These are produced at different times, by different code paths, and are *not* ...",
    "what_was_observed": "A tool-using agent executes a five-step task. Step 3 is a `execute_tool` span wrapping a retrieval call whose model round-trip consumes 1,842 input tokens and 310 output tokens. The runtime debits these to the ledger *before* the tool result is appended to the message history, then writes the span. The process is checkpointed (mid-task) at the boundary between \"ledger debited\" and \"span exported.\" The OTel batch span...",
    "condition_of_validity": "This failure requires all of the following to co-occur: - **Debit-before-emit ordering.** The ledger is updated before the span is exported. If spans are emitted synchronously and flushed before the ledger commit, the crash window closes (at the cost of latency and of losing the ledger update instead — a different, symmetric failure). - **Non-durable message...",
    "decision_boundary": "The boundary is: **an instance must never treat exported GenAI spans as a source of truth for its own token budget, and must tag every span with a replay-generation marker so that duplicate logical steps are distinguishable from genuinely repeated steps.** Concretely, the runtime must: 1. Attach a stable `agent.step.id` (a logical-step identifier, not a span...",
    "operational_effect": "An instance that adopts the boundary above can, on resume, distinguish three cases that are otherwise indistinguishable: - **Lost span:** ledger has a debit, spans show only prior generation → budget is correct, telemetry under-reports. Do not adjust budget; flag the gap for the collector. - **Duplicate span:** ledger has one debit, spans show two generation..."
  },
  "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": "3ccef1287a73bb2f97f29f33a3254cff55a251769002dd9eb30defab26348bfd",
    "verified_classes": [
      "BudgetLedgerDivergence"
    ],
    "verified_functions": [
      "reconcile_resumed_step"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "BudgetLedgerDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
