{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-span-level-cost-attribution-from-silently-misattributing-tokens-when-a-tool-call-fans-out-into-parallel-sub-agent-spans",
  "title": "Which invariants prevent span-level cost attribution from silently misattributing tokens when a tool call fans out into parallel sub-agent spans",
  "date_of_record": "2026 November 25",
  "scope": "Applies to trace-based observability pipelines that attribute token cost and wall-clock latency to individual agent steps and tool calls, where a single tool invocation may dispatch concurrent child spans (sub-agents, retries, speculative branches). Does not apply to single-threaded, single-span-per-step tracing, nor to billing reconciliation against provider invoices (which is a separate, coarser invariant).",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-level-cost-attribution-from-silently-misattributing-tokens-when-a-tool-call-fans-out-into-parallel-sub-agent-spans.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-level-cost-attribution-from-silently-misattributing-tokens-when-a-tool-call-fans-out-into-parallel-sub-agent-spans.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-level-cost-attribution-from-silently-misattributing-tokens-when-a-tool-call-fans-out-into-parallel-sub-agent-spans.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1979,
    "python_slice_tokens": 496,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure here is not \"the trace is missing spans\" or \"the cost total is wrong.\" Those are visible. The non-obvious failure is **attribution drift under fan-out**: the aggregate cost of a parent step remains numerically correct while the per-child, per-tool-call attribution is silently redistributed. The trace looks internally consistent — parent cost equa...",
    "what_was_observed": "A planner agent emits a single step `step_7` that invokes a tool `search_and_summarize`. That tool internally spawns three parallel sub-agent spans (`sub_A`, `sub_B`, `sub_C`) that each call the same model with different query fragments, then a reducer span `sub_R` merges their outputs into one completion attributed to `step_7`. The pipeline records token usage at the **parent completion** boundary: the provider retu...",
    "condition_of_validity": "The invariant that prevents drift is: **every span that issues a model call MUST carry its own provider-returned usage object, and parent usage MUST be defined as the sum of child usage objects, never as an independently recorded quantity.** This holds only when three conditions are simultaneously true: 1. **Usage is captured at the call site, not the orches...",
    "decision_boundary": "The boundary is whether the observability pipeline treats **usage as a property of a model call** or **as a property of a span**. These are the same thing only when spans and model calls are 1:1. Under fan-out, retries, speculative decoding branches, or framework batching, they are not. Operational rule: if a span can issue more than one model call (retry, f...",
    "operational_effect": "Enforcing call-site usage capture converts a silent, self-consistent misattribution into a loud ingest failure. The cost: orchestration frameworks that batch sub-calls must be instrumented at the client layer rather than the graph layer, which is more invasive and requires per-retry accumulation logic. The benefit: per-tool-call cost becomes causally meaning..."
  },
  "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": "e7787cd1c4142144f05cb5babed810589bd9294b221d312f11c4244db4094f69",
    "verified_classes": [
      "AttributionDriftError",
      "ModelCall",
      "Span"
    ],
    "verified_functions": [
      "attribute_span",
      "ingest",
      "call_count",
      "total_input",
      "total_output"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "AttributionDriftError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
