{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-token-attribution-drift-from-silently-corrupting-per-agent-cost-accounting-in-multi-agent-traces",
  "title": "Which invariants prevent token-attribution drift from silently corrupting per-agent cost accounting in multi-agent traces",
  "date_of_record": "2026 November 30",
  "scope": "Applies to observability pipelines that attribute LLM token usage and cost to individual agents and tool calls across multi-hop, multi-agent executions. Does not apply to single-call, single-agent inference where the provider response is the sole billing authority and no fan-out or retry occurs.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-attribution-drift-from-silently-corrupting-per-agent-cost-accounting-in-multi-agent-traces.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-attribution-drift-from-silently-corrupting-per-agent-cost-accounting-in-multi-agent-traces.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-attribution-drift-from-silently-corrupting-per-agent-cost-accounting-in-multi-agent-traces.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1841,
    "python_slice_tokens": 351,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure here is not that token counts are *wrong* — it is that they are *right but misattributed*. Most observability stacks treat token usage as a scalar property of an HTTP response from a model provider. That assumption holds for a single call. It breaks the moment an agent framework fans a logical \"agent step\" into multiple physical provider requests...",
    "what_was_observed": "A three-agent pipeline (planner → retriever → synthesizer) with a shared MCP tool layer showed a 34% cost overrun against the provider invoice over a 24-hour window. The per-agent dashboard attributed cost cleanly — every agent had a plausible number. The discrepancy was invisible at the agent level and only surfaced when reconciling the *sum of trace spans* against the *sum of provider billing records*. The trigger ...",
    "condition_of_validity": "The conservation invariant holds only under an explicit precondition: **every provider response must be emitted as a distinct, immutable usage record keyed by a provider-assigned response identifier, and span-level attribution must be a derived view over those records — never the source of truth.** This is the boundary. If the observability system treats the...",
    "decision_boundary": "The decision boundary is whether to key attribution on the **span** or on the **provider response**. The correct rule: - **Provider response ID is the atomic key.** Every `usage` block from a model provider is a first-class record with `(response_id, model, input_tokens, output_tokens, cache_read, cache_write, timestamp)`. - **Spans reference response IDs, t...",
    "operational_effect": "Enforcing per-response atomicity and per-leaf reconciliation changes three things operationally: 1. **Cost dashboards become trustworthy at the agent level.** Without it, per-agent cost is a plausible fiction — every agent has a number, and the numbers sum to something close to the invoice, so nobody investigates. The 34% overrun above was masked for weeks b..."
  },
  "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": "e8b96ec7f2bededfaee9a4b87de6f75be34fde851e481889b3d45d1c068262ed",
    "verified_classes": [
      "TokenAttributionDriftError",
      "ProviderResponse",
      "Span",
      "TraceLedger"
    ],
    "verified_functions": [
      "close_trace",
      "total_tokens",
      "__init__",
      "record_response",
      "register_span",
      "reconcile",
      "cost_by_agent"
    ],
    "verified_functions_count": 7,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TokenAttributionDriftError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
