{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-against-a-tool-call-event-stream-that-was-truncated-by-the-exp",
  "title": "In what scenarios must an instance reconcile OpenTelemetry GenAI token-accounting spans against a tool-call event stream that was truncated by the exporter's batch deadline",
  "date_of_record": "2026 November 28",
  "scope": "Applies to agent runtimes that emit OTel GenAI spans (`gen_ai.*`) through a batching `SpanProcessor` (e.g., `BatchSpanProcessor`) while tool-call results are streamed to a separate sink (event log, message bus, or trace-sidecar). Does not cover synchronous `SimpleSpanProcessor` deployments where span end precedes export, nor does it cover cost-attribution pipelines that read only the metrics SDK.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-against-a-tool-call-event-stream-that-was-truncated-by-the-exp.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-against-a-tool-call-event-stream-that-was-truncated-by-the-exp.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-against-a-tool-call-event-stream-that-was-truncated-by-the-exp.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2083,
    "python_slice_tokens": 554,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a tool call as a *span with attributes* (`gen_ai.tool.name`, `gen_ai.operation.name = \"execute_tool\"`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) and treat the agent step as a *parent span* (`gen_ai.operation.name = \"chat\"` or `\"invoke_agent\"`). The invariant most operators assume is that a completed tool ...",
    "what_was_observed": "A 12-step agent loop (7 tool calls, 5 chat turns) was instrumented with `BatchSpanProcessor(schedule_delay_millis=5000, max_export_batch_size=512)`. The tool executor emitted a `execute_tool` child span per call and a `tool.result` event to a Kafka topic. The parent `invoke_agent` span was ended only after step 12. Trace reconstruction from the OTel backend showed, across 400 runs: - 31% of runs had at least one batc...",
    "condition_of_validity": "The parent-covers-children token invariant (`parent.gen_ai.usage.output_tokens == Σ child.gen_ai.usage.output_tokens + Σ chat-turn output`) holds **only when the parent span and all its children are exported in the same batch, or when the reconciler joins on `trace_id` + `span_id`/`parent_span_id` after a quiescence window longer than `schedule_delay_millis ...",
    "decision_boundary": "The boundary is: **do not compute per-run token cost from span attributes until you have either (a) a quiescence-confirmed join on `trace_id`, or (b) an event-stream-anchored reconciliation that treats spans as advisory.** Concretely, the reconciler must decide, per agent run: - If the parent span is present and `parent.end_time > max(child.end_time)` and th...",
    "operational_effect": "Two concrete guardrails: 1. **Quiescence gate on the join.** The reconciler must not finalize a `trace_id` until `now − max_span_end_time > schedule_delay_millis + export_timeout_millis + clock_skew_margin`. A 15 s gate eliminated the 31% double-count in replay. Shorter gates reintroduced it whenever a tool call ran long enough to straddle a flush. 2. **Even..."
  },
  "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": "c271d887a02e6c0822ac31f14dead064674021974d194bb72b3af03524290fd0",
    "verified_classes": [
      "TokenReconciliationError",
      "SpanRecord",
      "EventRecord",
      "RunReconciliation"
    ],
    "verified_functions": [
      "reconcile_run"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
