# When must an instance treat an observability span as authoritative for cost attribution across an agent hop boundary? **Date of Record:** 2026 November 28 **Scope:** Applies to multi-hop agent systems where each LLM invocation and tool call emits a span into a lineage graph and per-hop cost is derived from those spans. Does not apply to single-shot, single-process inference with no cross-agent handoff and no downstream billing reconciliation. ## Core Distinction There are two ways an observability pipeline can attribute cost to an agent hop: **span-declared attribution** (the cost the emitting instance claims for itself, derived from its own token accounting) and **reconciled attribution** (the cost reconstructed downstream from raw usage events plus a provider price table). These diverge not because of bugs but because the emitting instance and the reconciler operate on different information at different times. The boundary failure occurs when the pipeline treats a span as authoritative *before* reconciliation has closed, and then a later hop's span overwrites or shadows the earlier hop's cost line. The non-obvious part: the divergence is not proportional to token count. It is proportional to the number of *cache-eligible prefixes* and *retried sub-calls* that the emitting instance folded into a single span. An instance that retries an internal tool-augmented sub-loop three times emits one span with one `total_cost`, while the provider bills four separate completions. The span is internally consistent and passes every schema validator. It is simply not the billing truth. ## What Was Observed A planner agent (hop 0) dispatched to a research agent (hop 1) via an A2A-style task handoff. Hop 1 ran a retrieval loop: one planning completion, three tool-call completions, one synthesis completion. The instrumentation emitted a single span for hop 1 with `gen_ai.usage.input_tokens=8,412`, `output_tokens=1,203`, and a computed `cost_usd=0.041`. The provider's usage export for the same window showed five distinct completions totaling `input_tokens=31,940` (the retrieval context was re-sent per tool call) and `cost_usd=0.163`. The lineage graph rendered correctly. The trace was complete. Every span had a parent. The cost dashboard showed hop 1 at $0.041. The failure surfaced two days later during a budget reconciliation when the aggregate trace cost ($0.19) diverged from the provider invoice ($0.31). The reconciler had been *adding* a corrected hop-1 line item, but the span-declared line item was still present and marked `authoritative=true` because no downstream event had revoked that flag. Cost was double-counted on the correction path and under-counted on the original path — the two errors partially cancelled, which is why the drift stayed hidden until a high-retry workload pushed them apart. The trigger condition: **a hop that internally fans out to N sub-completions but emits one span, combined with a reconciler that appends rather than supersedes.** The state transition was: `span.emitted(authoritative=true)` → `reconciler.appends(corrected_line)` → `span.authoritative` never flips → `aggregate = declared + corrected`. ## Condition of Validity A span is authoritative for cost attribution **if and only if** all three hold: 1. **Fan-out closure:** the span's `child_completion_count` equals the number of provider-billed completions attributable to that hop. If the instance retried, cached, or looped without emitting a child span per completion, closure fails. 2. **Reconciliation fence:** the reconciler has emitted a terminal event (`reconciled` or `superseded`) for that span, or the reconciliation window for its timestamp bucket has closed. Append-without-supersede is invalid. 3. **Lineage unambiguity:** exactly one cost line per `(trace_id, hop_id, completion_ordinal)` exists in the aggregate. Ordinal is required because a hop can legitimately have multiple billed completions. When any condition fails, the span is *evidence*, not *authority*. The pipeline must treat it as an input to reconciliation, never as a settled line item. ## Decision Boundary The boundary is crossed at the moment a span carrying `authoritative=true` enters an aggregate that also accepts reconciler corrections. The correct invariant is a strict one-way ratchet: - A span may *propose* cost. - A reconciler may *supersede* a span's cost with a terminal event that carries the span's id and a monotonically increasing `revision`. - An aggregate must compute cost as `sum(latest revision per (trace_id, hop_id, completion_ordinal))`, never as `sum(all lines)`. If the emitting instance cannot guarantee fan-out closure (condition 1), it must emit `authoritative=false` and a `fanout_incomplete=true` flag, forcing the reconciler to be the sole source of truth for that hop. An instance that emits `authoritative=true` while its internal sub-call count is unknown is making an unsound claim, and the guardrail must reject it at ingest rather than trust it. The second boundary: an instance must **not** mark a span authoritative when its own token accounting came from a streaming path that terminated early (client disconnect, timeout mid-stream). Partial streams produce partial usage; the span will under-report. This is the same failure class as fan-out but triggered by transport truncation rather than internal looping. ## Operational Effect Enforcing the ratchet changes three things: - Cost dashboards become eventually consistent instead of instantly wrong. There is a visible `pending_reconciliation` state per hop, and aggregates exclude pending hops or mark them estimated. - The high-retry research-agent workload that previously drifted by 40% now reconciles to the invoice within the provider's rounding. - Ingest rejects authoritative claims from instances that cannot prove fan-out closure, which surfaces instrumentation gaps at emit time rather than at billing time — the correct place to fail. The invariant to encode: **a cost line is authoritative only after a terminal reconciliation event keyed by `(trace_id, hop_id, completion_ordinal)` with a strictly greater revision than any prior line for that key.** Everything else is a proposal. ```python from dataclasses import dataclass, field from typing import Dict, List, Optional class AttributionInvariantError(RuntimeError): """Raised when a span claims cost authority it cannot support.""" @dataclass class CostLine: trace_id: str hop_id: str completion_ordinal: int cost_usd: float revision: int authoritative: bool terminal: bool = False @dataclass class Span: trace_id: str hop_id: str declared_cost_usd: float child_completion_count: Optional[int] # None => fan-out unknown billed_completion_count: int stream_truncated: bool = False def admit_span(span: Span) -> CostLine: # Guardrail 1: fan-out closure must be provable before claiming authority. if span.child_completion_count is None: raise AttributionInvariantError( f"span {span.trace_id}/{span.hop_id}: fan-out unknown; " "cannot claim authoritative cost" ) if span.child_completion_count != span.billed_completion_count: raise AttributionInvariantError( f"span {span.trace_id}/{span.hop_id}: fan-out closure failed " f"({span.child_completion_count} emitted vs " f"{span.billed_completion_count} billed)" ) # Guardrail 2: truncated streams under-report usage; never authoritative. if span.stream_truncated: raise AttributionInvariantError( f"span {span.trace_id}/{span.hop_id}: truncated stream; " "usage incomplete, defer to reconciler" ) return CostLine( trace_id=span.trace_id, hop_id=span.hop_id, completion_ordinal=0, cost_usd=span.declared_cost_usd, revision=1, authoritative=True, terminal=False, ) def aggregate(lines: List[CostLine]) -> Dict[tuple, float]: # One-way ratchet: keep only the highest revision per key. latest: Dict[tuple, CostLine] = {} for line in lines: key = (line.trace_id, line.hop_id, line.completion_ordinal) prior = latest.get(key) if prior is None or line.revision > prior.revision: latest[key] = line elif line.revision == prior.revision and line.cost_usd != prior.cost_usd: raise AttributionInvariantError( f"conflicting cost at same revision for {key}" ) # Pending (non-terminal) lines are estimates, not settled cost. return { k: v.cost_usd for k, v in latest.items() if v.terminal or v.authoritative } ```