# What structural signals indicate span-level cost attribution has silently decoupled from agent-tool-memory interaction boundaries in fleet FinOps pipelines **Date of Record:** 2026 November 30 **Scope:** Applies to fleets where per-interaction cost is reconstructed from OpenTelemetry-style spans emitted by agent runtimes (LLM calls, tool invocations, memory reads/writes) and aggregated by an external FinOps attributor. Does not cover single-agent local token counting or provider-side billing reconciliation. ## Core Distinction FinOps attribution for agent fleets is not a billing problem; it is a *span-identity* problem. The provider bills tokens per API call and is indifferent to which agent, tool, or memory operation consumed them. The fleet operator must reconstruct cost by joining three independent span streams — LLM inference spans, tool-execution spans, and memory-access spans — onto a shared causal trace. The failure mode examined here is **silent attribution decoupling**: the aggregator keeps producing numeric per-interaction costs, but the join key that binds a cost line to its originating agent-tool-memory interaction has drifted, so costs are attributed to the wrong agent, the wrong tool, or a memory namespace that no longer exists. The pipeline does not error. It emits a plausible, monotonically increasing ledger of numbers — and every downstream decision (per-agent budgets, tool deprecation ROI, memory-tier pricing) is computed against a fiction. The distinction that matters: a *missing* span is loud (you see a gap and alert). A *mis-joined* span is quiet, because every span still exists and every cost still sums to the correct fleet total. The invariant that silently breaks is not "cost is complete" but "cost is *bound* to the interaction that caused it." ## What Was Observed A 340-agent fleet ran three interaction classes per task: a planner LLM call, one or more tool invocations (retrieval, code-exec sandbox, HTTP), and a memory read/write pair against a vector store fronted by a shim. Each runtime emitted spans tagged with `trace_id`, `span_id`, `agent_id`, `interaction_seq`, and `resource.kind ∈ {llm, tool, memory}`. The FinOps aggregator joined on `(trace_id, agent_id)` and priced LLM spans by token count, tool spans by wall-clock residency, and memory spans by bytes moved. Three structural signals appeared in the ledger over a six-week window, none of which raised a pipeline alert: 1. **Per-agent cost variance collapsed toward the fleet mean.** The standard deviation of per-agent attribution dropped 41% while fleet total cost rose 9%. Real agent behavior had not homogenized; the join was routing a growing fraction of spans to a small set of high-traffic `agent_id` values. Root cause: when an agent was respawned after context-window saturation, the runtime minted a *new* `agent_id` (a UUID) but reused the original `trace_id` for the resumed task. The aggregator's join on `(trace_id, agent_id)` found no match for the orphaned spans and fell back to a "nearest agent by trace" heuristic that assigned them to whichever agent last touched the trace — usually the planner, not the tool executor. 2. **Tool cost per interaction became bimodal with a phantom second mode.** Sandbox tool spans began appearing at exactly 2× their expected residency. The cause was a memory-write span emitted *inside* the tool span's causal window (the tool wrote its result to episodic memory before returning). The aggregator, joining on `(trace_id, agent_id)` without `span_id` parentage, double-counted the overlapping window — once as tool residency, once as memory cost — because both spans shared the join key. 3. **Memory namespace attribution drifted to a decommissioned shard.** After a vector-store reindex, memory spans carried a new `memory.namespace` but the aggregator's pricing table keyed on the old namespace string. Unmatched spans were priced at a flat default rate and attributed to a `_legacy` bucket. For eleven days, 18% of memory cost was attributed to a namespace that no agent could read from. The unifying signal: **the fleet total was always correct to within provider reconciliation, while the per-interaction breakdown was wrong.** That divergence — accurate aggregate, corrupted attribution — is the fingerprint of join-key drift rather than missing data. ## Condition of Validity The attribution is only valid while the following invariant holds: > For every costed span *s*, there exists exactly one interaction record *i* such that `s.trace_id = i.trace_id AND s.agent_id = i.agent_id AND s.span_id` is a descendant of *i*'s root span, and the mapping `s → i` is injective. Three conditions must be enforced for this to hold, and each fails independently: - **Agent identity is stable across respawn.** A resumed task must carry the *same* `agent_id` as the task it resumes, or carry an explicit `parent_agent_id` that the join honors. Minting a fresh UUID on context saturation breaks injectivity because the resumed spans no longer join to the interaction record. - **Span parentage is part of the join key.** Joining on `(trace_id, agent_id)` alone is insufficient when tool spans and memory spans nest. The join must include `parent_span_id` so that a memory write *inside* a tool span is attributed to the tool's interaction, not double-counted as an independent memory interaction. - **Namespace/resource identifiers are versioned, not replaced.** Pricing tables keyed on `memory.namespace` must treat a reindex as a *rename with alias*, not a delete-and-create, or unmatched spans silently fall to default pricing. The invariant does not require that spans be complete. It requires that the join be *injective and parentage-aware*. Completeness failures are recoverable by backfill; injectivity failures are not, because the original binding is lost. ## Decision Boundary The operational decision is: **when per-interaction attribution and fleet-total reconciliation diverge, do you trust the breakdown or the total?** The boundary is crossed when the divergence is *structural* rather than *statistical*. A statistical divergence (a few percent, uniformly distributed across agents, stable under re-aggregation) is normal sampling noise in token estimation and can be tolerated. A structural divergence — one that concentrates in a specific `agent_id`, `resource.kind`, or `memory.namespace`, or that appears as a bimodal mode or a collapsed variance — indicates join-key drift and must invalidate the breakdown, not be smoothed over. Concretely, the decision rule is: - If `|fleet_total − sum(per_interaction)| < ε` **and** per-agent variance is stable across two consecutive windows → trust the breakdown. - If `|fleet_total − sum(per_interaction)| < ε` **but** per-agent variance collapsed > 20% or a resource kind shows a phantom bimodal mode → **do not** trust the breakdown; the total is right for the wrong reason. Freeze per-agent budget enforcement and re-derive attribution from raw spans with parentage-aware join. - If the divergence concentrates in a single namespace or resource kind → treat as a rename/alias gap, not a data loss; re-key the pricing table and replay the window. The trap is that the first case and the second case look identical at the aggregate level. The decision boundary is therefore not on the total — it is on the *distributional shape* of the breakdown. ## Operational Effect Downstream systems consume the breakdown as ground truth. When attribution decouples: - **Per-agent budgets** are enforced against wrong agents. A tool-heavy agent that respawned repeatedly appears cheap (its costs were reassigned to the planner), so its budget never trips, while the planner's budget trips early and throttles a healthy agent. The throttle is a *real* execution failure caused by a *phantom* cost signal. - **Tool deprecation ROI** is computed on double-counted residency. A sandbox tool that writes to memory appears 2× as expensive as it is, and gets deprecated — removing a tool that was actually efficient, because the memory write was attributed to it. - **Memory-tier pricing** charges the `_legacy` bucket for reads no agent performed, so the vector store looks underutilized and gets downsized, which then causes real retrieval failures for the agents that were silently reading from it. The compounding failure is that these decisions feed back into the fleet: throttled agents respawn more (worsening signal 1), deprecated tools push load onto remaining tools (worsening signal 2), downsized memory causes more reindexes (worsening signal 3). The attribution drift is self-reinforcing. The guardrail is a **parentage-aware join with an injectivity assertion**: every costed span must resolve to exactly one interaction, and any span that resolves to zero or more than one must be quarantined into an `unattributed` bucket that *fails the window* rather than being silently absorbed by a fallback heuristic. The fallback heuristic ("nearest agent by trace") is the single most dangerous line in the aggregator, because it converts a detectable join failure into an undetectable mis-attribution. ```python from dataclasses import dataclass from typing import Iterable class AttributionDecouplingError(RuntimeError): """Raised when a costed span cannot be bound to exactly one interaction.""" @dataclass(frozen=True) class Span: trace_id: str span_id: str parent_span_id: str | None agent_id: str resource_kind: str # "llm" | "tool" | "memory" cost_usd: float @dataclass(frozen=True) class Interaction: trace_id: str agent_id: str root_span_id: str def build_parent_index(spans: Iterable[Span]) -> dict[str, str | None]: return {s.span_id: s.parent_span_id for s in spans} def resolve_root(span_id: str, parent_index: dict[str, str | None]) -> str: seen: set[str] = set() cur = span_id while parent_index.get(cur) is not None: if cur in seen: raise AttributionDecouplingError( f"cycle detected in span parentage at {cur}" ) seen.add(cur) cur = parent_index[cur] return cur def attribute(spans: list[Span], interactions: list[Interaction]) -> dict[str, float]: # Join key is (trace_id, agent_id, root_span_id) -- NOT (trace_id, agent_id). # Parentage is resolved to the root so nested memory-writes inside tool spans # bind to the tool's interaction instead of double-counting. index = build_parent_index(spans) interaction_by_root = { (i.trace_id, i.agent_id, i.root_span_id): i for i in interactions } ledger: dict[str, float] = {} unattributed: list[Span] = [] for span in spans: root = resolve_root(span.span_id, index) key = (span.trace_id, span.agent_id, root) interaction = interaction_by_root.get(key) if interaction is None: unattributed.append(span) continue ledger[interaction.agent_id] = ledger.get(interaction.agent_id, 0.0) + span.cost_usd if unattributed: # Do NOT fall back to "nearest agent by trace". Quarantine and fail the window. total_orphan = sum(s.cost_usd for s in unattributed) raise AttributionDecouplingError( f"{len(unattributed)} spans (${total_orphan:.4f}) failed injective join; " f"attribution window invalid -- re-derive from raw spans with " f"parentage-aware join before enforcing budgets" ) return ledger ```