{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-genai-spans-whose-token-attributes-are-re-aggregated-across-a-resumed-agent-run",
  "title": "What happens when an instance emits GenAI spans whose token attributes are re-aggregated across a resumed agent run",
  "date_of_record": "2026 November 30",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) and resumes execution from a checkpoint or retries a tool call within the same logical run. Does not apply to stateless single-shot inference calls that are never resumed or retried.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-spans-whose-token-attributes-are-re-aggregated-across-a-resumed-agent-run.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-spans-whose-token-attributes-are-re-aggregated-across-a-resumed-agent-run.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-spans-whose-token-attributes-are-re-aggregated-across-a-resumed-agent-run.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1831,
    "python_slice_tokens": 387,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) as *per-request* counters on a single span. They are not deltas, not gauges, and not idempotent. A span is a record of one model invocation, and its token attributes describe exactly that invocation. The failure mode is not a schema violation. E...",
    "what_was_observed": "A planner agent executes a three-tool sequence. At step 2 (a retrieval tool call), the process is checkpointed mid-flight because the tool call exceeds a timeout. On resume, the orchestrator replays from the last durable checkpoint, which was *before* step 2's model invocation. The model call for step 2 is issued again with identical inputs. Both invocations emit spans with the same `trace_id` (propagated from the ru...",
    "condition_of_validity": "The invariant that must hold is: **for any `trace_id`, the sum of `gen_ai.usage.*` across spans equals the sum of provider-billed tokens for the logical run, and each logical model invocation is counted exactly once.** This holds only when all of the following are true: - Every span that begins is either ended with a terminal status or explicitly marked `ERR...",
    "decision_boundary": "The boundary is whether the resumed step is treated as the *same* invocation or a *new* one. Treat it as the same invocation (replay under one span, with the span reopened or a child span linked via `SpanLink`) when the replay is a pure retry of an idempotent model call and you control the exporter such that the original span is closed as `ERROR` before the ...",
    "operational_effect": "An agent that emits GenAI spans without step-attempt discriminators and then reads its own spans for budget enforcement creates a closed feedback loop where replay inflates perceived cost. On runs with no retries the loop is stable; on runs with retries it diverges, and the divergence is biased toward *early termination*, because the agent over-counts. The p..."
  },
  "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": "0c4aae51b7efd0946e10b4cfad76ecb72d104559dc778a8ca4a34dfde7840b0f",
    "verified_classes": [
      "SpanAggregationInvariantError",
      "GenAISpan"
    ],
    "verified_functions": [
      "aggregate_run_tokens",
      "enforce_budget"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "SpanAggregationInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
