{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-gen-ai-agent-invoke-span-outlives-its-parent-trace-context-and-tool-call",
  "title": "Where must an instance reconcile OpenTelemetry GenAI token accounting when a `gen_ai.agent.invoke` span outlives its parent trace context and tool_call lineage is re-parented mid-execution?",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents emitting OTel GenAI spans (`gen_ai.agent.invoke`, `gen_ai.tool.call`, `gen_ai.chat`) where a long-running invoke span spans a trace-context boundary (root span expiry, remote parent loss, or `traceparent` re-injection on resume). Does not cover pure single-shot inference calls that begin and end inside one trace.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-gen-ai-agent-invoke-span-outlives-its-parent-trace-context-and-tool-call.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-gen-ai-agent-invoke-span-outlives-its-parent-trace-context-and-tool-call.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-gen-ai-agent-invoke-span-outlives-its-parent-trace-context-and-tool-call.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1881,
    "python_slice_tokens": 386,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *per-span, additive, and finalized at span end*. They also treat `gen_ai.agent.invoke` as a *container* span whose children (`gen_ai.tool.call`, nested `gen_ai.chat`) carry their own usage. The invariant the spec implicitly relies on — but never states — is t...",
    "what_was_observed": "A three-tool agent task (retrieve → transform → summarize) ran under a 90-second wall-clock budget with a 60-second OTel `SpanProcessor` batch flush and a 45-second trace-context TTL enforced by the ingress proxy. The invoke span opened at t=0 with `trace_id=A`. Tool 1 (`gen_ai.tool.call`, 12k input tokens) completed at t=8s under `trace_id=A`. At t=38s the agent checkpointed mid-transform. At t=52s the context TTL e...",
    "condition_of_validity": "The additive-token invariant (`parent.usage == Σ child.usage`, all children share `parent.trace_id`) is valid **iff** the following holds for the entire invoke span lifetime: 1. The `SpanContext` (trace_id + span_id) is preserved across every checkpoint/resume, i.e. the resume worker receives the *original* `traceparent`, not a freshly minted root. 2. The in...",
    "decision_boundary": "The boundary is a single comparison the runtime must make **before** emitting any resume span: If `trace_context_ttl < task_budget`, the runtime is *guaranteed* to cross this boundary and must pre-declare segmentation at task start (segment_index=0 on the first invoke). A runtime that does not checkpoint its token counter will, on the orphan path, either dou...",
    "operational_effect": "Consequences of crossing the boundary without the guardrail: - **Latency SLO corruption:** suspension gaps inside invoke spans are counted as inference time. p99 inflates proportional to checkpoint frequency × TTL overshoot. - **Token undercount:** orphaned children (no valid parent) drop out of `sum(invoke.usage)`. In the observed run this was 48% — large e..."
  },
  "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": "f8b023113914ba7f5393f7b1324945c08474c9eef726a920f2884462a178ce78",
    "verified_classes": [
      "TraceContextLossError",
      "InvokeSpan"
    ],
    "verified_functions": [
      "reconcile_resume",
      "aggregate_task_tokens"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 7,
    "raised_exceptions": [
      "TraceContextLossError"
    ],
    "sample_fail_closed_invariants": [
      "resume produced no child spans; cannot attribute tokens",
      "checkpointed counters must be non-negative",
      "no segments to aggregate",
      "segment 0 must not be a continuation"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
