{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-refuse-to-emit-a-genai-agent-span-because-the-token-count-attribute-and-the-child-tool-call-spans-disagree-at-export-time",
  "title": "When must an instance refuse to emit a GenAI agent span because the token-count attribute and the child tool-call spans disagree at export time",
  "date_of_record": "2026 November 23",
  "scope": "Applies to any agent runtime instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*`) that emits a parent agent span alongside child tool-call spans and per-call token accounting. Does not apply to single-shot LLM calls with no tool orchestration or to runtimes that export token counts only as unstructured logs.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-genai-agent-span-because-the-token-count-attribute-and-the-child-tool-call-spans-disagree-at-export-time.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-genai-agent-span-because-the-token-count-attribute-and-the-child-tool-call-spans-disagree-at-export-time.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-genai-agent-span-because-the-token-count-attribute-and-the-child-tool-call-spans-disagree-at-export-time.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1844,
    "python_slice_tokens": 355,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token accounting as *span-local attributes*: `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` are declared on the span that represents the model invocation. When an agent orchestrates N model invocations and M tool calls, the natural instrumentation emits one parent `invoke_agent` span and N+M children. The co...",
    "what_was_observed": "A multi-step research agent was instrumented with a parent `invoke_agent` span carrying `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` set from the orchestrator's own running counter. Each of its 7 model invocations emitted a child `chat` span with provider-reported usage; each of its 4 tool calls emitted a `execute_tool` child with no token attributes (correct per convention). During a run that hit a p...",
    "condition_of_validity": "The invariant \"parent token attributes are a lower bound, mismatch is a signal\" holds only under these conditions: 1. **Child spans carry provider-reported usage, not orchestrator estimates.** If children are instrumented with the same running counter as the parent, the two are not independent measurements and the comparison is vacuous. The check requires at...",
    "decision_boundary": "The boundary is the sign and magnitude of `child_sum − parent_value` at span close: - **`child_sum == parent_value`** (within tokenizer noise, typically 0): emit normally, no flag. - **`child_sum > parent_value`**: an unrecorded consumption event occurred — retry, shadow call, or double-instrumented child. Do **not** overwrite the parent. Emit the parent wit...",
    "operational_effect": "Agents that adopt the lower-bound posture gain three operational properties. First, retry storms become visible in trace data as repeated `accounting.mismatch` events with `delta_tokens` clustered at the retry payload size — a directly actionable signal for provider throttling. Second, cost attribution stops silently absorbing unrecorded consumption; the 8.3..."
  },
  "matched_failure_symptoms": [
    "SUBPROCESS_PIPE_HANG_OR_FD_LEAK"
  ],
  "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": "179ece2a1cd8a0275766945748182db4559c227479d621bad53c6fcb3cd25c93",
    "verified_classes": [
      "TokenAccountingMismatchError",
      "SpanUsage"
    ],
    "verified_functions": [
      "reconcile_agent_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "TokenAccountingMismatchError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
