{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-nested-span-token-accounting-before-cache-hit-telemetry-can-be-trusted-across-an-agentic-loop",
  "title": "Where must an instance reconcile nested span token accounting before cache-hit telemetry can be trusted across an agentic loop",
  "date_of_record": "2026 November 27",
  "scope": "Applies to OpenTelemetry-style GenAI span trees emitted by agent runtimes where a single logical LLM call is decomposed into nested child spans (retrieval, tool, sub-agent, cache-lookup) and where `genai.usage.*` attributes are aggregated upward for billing and loop-topology reconstruction. Does not apply to flat single-span instrumentation, nor to runtimes that emit provider-authoritative aggregate usage on the root span only.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-nested-span-token-accounting-before-cache-hit-telemetry-can-be-trusted-across-an-agentic-loop.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-nested-span-token-accounting-before-cache-hit-telemetry-can-be-trusted-across-an-agentic-loop.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-nested-span-token-accounting-before-cache-hit-telemetry-can-be-trusted-across-an-agentic-loop.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2093,
    "python_slice_tokens": 554,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two incompatible readings of `genai.usage.input_tokens` on a parent span: 1. **Inclusive aggregation** — the parent's token count is the sum of its own prompt plus all descendant spans' token counts (a subtree roll-up). 2. **Exclusive attribution** — the parent's token count is only the tokens consumed by the call the parent directly represents; ch...",
    "what_was_observed": "A two-level agent loop: an orchestrator span `agent.turn` wraps a `genai.chat` span (the model call) and a `tool.retrieve` span (a vector store hit that the model then conditions on). The model call had a provider-reported cache read of 8,192 tokens against an input of 9,000 tokens (91% hit rate — plausible for a long stable system prompt). The orchestrator emitted `genai.usage.input_tokens = 14,500`, computed by sum...",
    "condition_of_validity": "The cache-hit ratio is reconstructible **if and only if** the following three conditions co-hold on the same span: - **Aggregation scope is explicit.** The span carries a marker such as `genai.usage.aggregation = \"inclusive\" | \"exclusive\"`, and numerator and denominator are read from spans with the *same* marker. Absent the marker, treat the ratio as undefin...",
    "decision_boundary": "The boundary is between **aggregation for cost** and **aggregation for ratio**. Cost is linear and additive: rolling up inclusive token counts is correct for billing because every token was paid for exactly once somewhere in the subtree. Ratios are not additive: `sum(cache_read) / sum(input)` across a subtree is only the subtree's effective cache rate if eve...",
    "operational_effect": "The immediate effect is a systematic under-reporting of cache effectiveness on any turn that mixes cached model calls with uncached tool or retrieval calls — which is most agentic turns. Teams observing a \"56% cache hit rate\" conclude their prompt caching is underperforming and invest in cache-key restructuring, when the true rate was 91% and the instrumenta..."
  },
  "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": "77dacee4f51fa2d098c0a024d6bb638ac094d9adb441728944b2417ec3009834",
    "verified_classes": [
      "AggregationScope",
      "CacheRatioUnderivable",
      "GenAISpan"
    ],
    "verified_functions": [
      "cache_hit_ratio",
      "weighted_turn_cache_rate",
      "reconstruct"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 9,
    "raised_exceptions": [
      "CacheRatioUnderivable"
    ],
    "sample_fail_closed_invariants": [
      "no genai.chat spans to aggregate",
      "aggregate input_tokens is zero",
      "inclusive-scoped chat span present; subtree token totals are cost-correct but ratio-unsafe, refusing reconstruction"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "enum"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
