{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-tool-call-lineage-and-token-accounting-from-silently-diverging-under-opentelemetry-genai-span-conventions",
  "title": "Which invariants prevent tool-call lineage and token accounting from silently diverging under OpenTelemetry GenAI span conventions",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agents that emit OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.*`) for multi-step tool-calling loops where token usage and parent-child tool lineage must reconcile across a checkpoint/resume boundary. Does not cover single-shot inference spans with no tool calls, nor vendor-proprietary trace formats that do not claim `gen_ai.*` conformance.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-tool-call-lineage-and-token-accounting-from-silently-diverging-under-opentelemetry-genai-span-conventions.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-tool-call-lineage-and-token-accounting-from-silently-diverging-under-opentelemetry-genai-span-conventions.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-tool-call-lineage-and-token-accounting-from-silently-diverging-under-opentelemetry-genai-span-conventions.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1588,
    "python_slice_tokens": 291,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat two things as *attributes on a span*: token accounting (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) and tool-call lineage (`gen_ai.tool.name`, `gen_ai.tool.call.id`, plus the parent span linkage implied by the trace tree). The failure that matters is not \"a span is missing\" — it is that **these two attribut...",
    "what_was_observed": "An agent loop executing a 7-step tool chain resumed from a checkpoint after the context window saturated at step 4. On resume, the orchestrator replayed the last assistant turn — which contained a `tool_calls` array — and re-emitted the corresponding spans. The observed trace had: - **Duplicate tool spans:** the replayed `gen_ai.tool.call.id` (`call_abc123`) appeared twice as sibling spans under the same parent `gen_...",
    "condition_of_validity": "The invariant that must hold for a trace to be trustworthy: 1. **Call-ID uniqueness:** within a trace, each `gen_ai.tool.call.id` appears exactly once as a `gen_ai.tool` span, and each such ID is matched by exactly one entry in the parent chat span's recorded `tool_calls` array. This is what binds lineage to the model's actual decision. 2. **Usage attributio...",
    "decision_boundary": "The boundary is: **can the resumed process distinguish \"this turn was generated\" from \"this turn was replayed\"?** If yes, it can emit correct usage attributes and suppress duplicate spans. If no — because the checkpoint stores only the message array and not the emission ledger — then resume must choose between two lossy options: - **Suppress all replayed spa...",
    "operational_effect": "Downstream consumers — cost dashboards, lineage auditors, and replay verifiers — read the trace as ground truth. A doubled input-token count inflates cost attribution by up to 2× on resumed traces; a duplicated `tool.call.id` causes lineage auditors that key on call ID to either double-count tool invocations or, worse, deduplicate by taking the first occurre..."
  },
  "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": "9ec6071eb5a78853d23db5fdd991ac9fa9cfd4f23b45ad070b3f35d1c96a4b78",
    "verified_classes": [
      "LineageLedgerDivergence",
      "CheckpointLedger"
    ],
    "verified_functions": [
      "emit_resumed_turn"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "LineageLedgerDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
