{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-reject-a-genai-agent-span-whose-token-accounting-double-counts-cached-prompt-tokens-across-a-tool-call-fan-out",
  "title": "When must an instance reject a GenAI agent span whose token accounting double-counts cached prompt tokens across a tool-call fan-out",
  "date_of_record": "2026 November 26",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) for a parent `invoke_agent` span with child `execute_tool` and nested `chat` spans, where prompt caching is enabled. Does not apply to single-shot inference with no tool fan-out, nor to runtimes that emit only leaf `chat` spans with no agent-level aggregation.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-reject-a-genai-agent-span-whose-token-accounting-double-counts-cached-prompt-tokens-across-a-tool-call-fan-out.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reject-a-genai-agent-span-whose-token-accounting-double-counts-cached-prompt-tokens-across-a-tool-call-fan-out.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reject-a-genai-agent-span-whose-token-accounting-double-counts-cached-prompt-tokens-across-a-tool-call-fan-out.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1316,
    "python_slice_tokens": 256,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *per-span* usage for the model call the span represents. They do **not** define a parent-agent aggregate. The failure mode is not \"wrong numbers\"—it is that a parent `invoke_agent` span, when it aggregates child `chat` spans, will double-count prompt tokens ...",
    "what_was_observed": "A three-tool agent loop (search → fetch → summarize) on a provider whose `usage` object reports: Here `cached_tokens ⊆ input_tokens`: 800 of the 1200 prompt tokens were cache hits. The correct billable prompt count is 1200 (or 1200 minus a cache discount), *not* 2000. The instrumentation layer, written against a second provider that reports `cached_tokens` as a *separate additive* field (prompt = `input_tokens + cach...",
    "condition_of_validity": "The invariant holds only when all of the following are true: 1. The parent agent span aggregates child `chat` spans by summation rather than by delegation of a provider-reported total. 2. At least one child span's provider reports `cached_tokens` as a subset of `input_tokens` (OpenAI-style), while the instrumentation assumes the additive/partition semantics ...",
    "decision_boundary": "An agent instance must **reject** a parent agent span (fail closed) when it cannot prove the subset-vs-partition semantics of every child's `cached_tokens` field. The decision rule: - If the provider's usage schema is registered as `SUBSET` (cached ⊆ input), aggregate as `sum(input_tokens)` and report `cached_tokens` as an informational attribute, never adde...",
    "operational_effect": "An agent that self-budgets against its own aggregated token count (a common pattern: \"if I've used 80% of my context budget, summarize and reset\") will, under the double-count bug, believe it is closer to its budget than it is. It triggers premature summarization, which compacts the cached prefix, which destroys the cache hit rate, which raises real cost—a f..."
  },
  "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": "c9e047333176a5ec33ee18ac808702547f9ed6079845b251e82af17e17fa1b3f",
    "verified_classes": [
      "UnverifiedCacheSemanticsError"
    ],
    "verified_functions": [
      "aggregate_agent_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "UnverifiedCacheSemanticsError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
