{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-the-parent-span-s-token-ledger-before-emitting-a-child-span-or-per-node-cost-attribution-silently-double-counts-cache",
  "title": "Where must an instance reconcile the parent span's token ledger before emitting a child span, or per-node cost attribution silently double-counts cached prefixes",
  "date_of_record": "2026 December 2",
  "scope": "Applies to agent graphs where spans are emitted per node and token counts are attributed from provider usage payloads (including `cached_tokens` / `prompt_tokens_details`) under a shared prefix cache. Does not apply to single-call, non-nested inference with no cache reuse and no parent/child span hierarchy.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-the-parent-span-s-token-ledger-before-emitting-a-child-span-or-per-node-cost-attribution-silently-double-counts-cache.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-the-parent-span-s-token-ledger-before-emitting-a-child-span-or-per-node-cost-attribution-silently-double-counts-cache.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-the-parent-span-s-token-ledger-before-emitting-a-child-span-or-per-node-cost-attribution-silently-double-counts-cache.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1633,
    "python_slice_tokens": 352,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between **token accounting as a billing reconciliation** and **token accounting as a causal attribution**. Provider usage payloads are defined for the former: each response reports the tokens it was billed for, net of cache discounts it received. Observability systems naively treat these per-response numbers as additive across...",
    "what_was_observed": "A planner-executor agent graph with fan-out: one `plan` node emits a shared system+task prefix, then N `execute` nodes run concurrently, each appending its own tool schema and instruction. All N children share the identical prefix and hit the provider's prefix cache after the first child warms it. Trace observed on a 6-way fan-out: - `plan` span: `prompt_tokens=4200`, `cached_tokens=0`, `completion_tokens=310`. - Fir...",
    "condition_of_validity": "The double-count is only possible under all of the following: 1. **Shared prefix cache is active** and the provider reports `cached_tokens` (or equivalent) as a *subset* of `prompt_tokens`, not as a separate field excluded from the total. 2. **Spans form a tree** where a child's prompt logically contains the parent's prompt as a prefix (the common \"append-on...",
    "decision_boundary": "The invariant to enforce: **a token may be attributed as \"fresh compute\" to exactly one span in the tree — the span that first materialized the prefix — and every other span that reuses it must attribute it as \"cache-referenced,\" a non-additive annotation, never as fresh cost.** The decision boundary for the observability layer is: - At child close, do **not...",
    "operational_effect": "Without reconciliation, three downstream systems corrupt: (a) per-node cost dashboards overstate fan-out cost and mis-rank the plan node, causing teams to optimize the wrong node; (b) budget governors that sum child costs trip token-budget limits 2–3× early on high-fan-out graphs, aborting runs that would have fit; (c) latency attribution confuses cache-hit ..."
  },
  "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": "0299178feeec76af882cb48538ffca7190311676675a9fff044f618af0fbbba6",
    "verified_classes": [
      "AttributionReconciliationError",
      "SpanUsage",
      "SubtreeLedger"
    ],
    "verified_functions": [
      "reconcile_subtree",
      "prefix_hash"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "AttributionReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
