# Where must an instance Attribute Latency and Token Cost When a Task Graph's Critical Path Is Not the Path That Consumed the Budget **Date of Record:** 2026 December 2 **Scope:** Applies to multi-step agent task graphs where per-span latency and token telemetry are aggregated into observability SLOs, and where a single task graph fans out across concurrent tool-call subtrees. Does not apply to single-turn inference with no tool fan-out, nor to batch offline scoring where no per-task SLO is enforced. ## Core Distinction The failure mode is not "the SLO was breached." It is that the SLO was *attributed to the wrong span*, and the misattribution is systematic rather than noisy. Two orthogonal quantities get conflated: the **critical path** (the longest dependency chain of wall-clock time from task admission to terminal state) and the **budget path** (the chain of spans that consumed the largest share of the task's token allowance). In a linear agent loop these coincide. In a fan-out task graph they diverge, and the divergence is the boundary condition. When an orchestrator spawns N parallel sub-agents — say, a retrieval subtree, a code-execution subtree, and a verification subtree — the critical path is whichever subtree has the longest serial latency. The budget path is whichever subtree has the highest aggregate token consumption. These are independent variables. A verifier subtree that makes twelve sequential cheap calls (low tokens, high serial latency) owns the critical path. A retrieval subtree that makes three calls each stuffing 40k tokens of context (high tokens, low latency) owns the budget path. An observability system that reports "p99 latency attributed to the slowest span" and "cost attributed to the task root" collapses both into a single number and destroys the signal needed to fix either. ## What Was Observed Across a corpus of task graphs from a research-agent deployment, the following trace pattern recurred. A root agent admitted a task, emitted a plan, and dispatched three children under a `parallel` join with a 30s wall-clock deadline. The join used `asyncio.gather` with a timeout wrapper. Telemetry recorded: - Child A (retrieval): 3 spans, 2.1s wall, 118,400 tokens total. - Child B (code exec): 9 spans, 4.8s wall, 14,200 tokens total. - Child C (verifier): 12 spans, 27.9s wall, 9,600 tokens total. The join completed at 28.1s. The SLO — p95 task latency under 25s — fired. The per-span latency attribution pointed at Child C's twelfth span, a single LLM call that took 6.2s. Operators investigated that call, found it well within its own per-call SLO, and closed the incident as noise. The actual breach was structural: Child C's 12 serial spans each had a p50 of ~2.3s, and the *sum* crossed the deadline. No individual span was slow. The critical path was a sum, not a maximum, and the attribution logic only looked at maxima. Simultaneously, the token-cost SLO — 100k tokens per task graph — fired. Attribution pointed at the root span, which had "consumed" 118,400 tokens because the aggregator summed children into the parent. The actual consumer was Child A's second span, a retrieval call that re-fetched a 40k-token document corpus after a cache miss caused by a non-deterministic query-embedding perturbation. The root span consumed 1,800 tokens of its own. Two SLOs fired. Both were attributed to spans that were not the cause. The remediation that followed — raising the per-call latency ceiling and adding a root-level token cap — addressed neither root cause and, worse, masked the next occurrence: the serial-verifier pattern recurred with 14 spans and the root cap simply truncated the retrieval subtree mid-fetch, producing a partial-context answer that passed the verifier because the verifier only checked schema conformance. ## Condition of Validity The misattribution is guaranteed to occur, not merely possible, when all three of the following hold: 1. **Fan-out with heterogeneous span cost distributions.** At least two sibling subtrees whose per-span token distributions differ by more than an order of magnitude, and whose per-span latency distributions differ in *shape* (one heavy-tailed, one near-constant). 2. **Aggregation-by-containment.** The telemetry pipeline attributes child cost to the parent span (the standard OpenTelemetry parent-child rollup) without preserving the distinction between "this span's own cost" and "cost of descendants." Once rolled up, the root span's number is a sum, and sums are not attributable. 3. **Critical-path computation by max, not by sum.** The latency SLO evaluator walks the span tree and flags the span with the largest `duration`, rather than computing the longest root-to-leaf path by cumulative duration. For serial chains this under-reports by a factor equal to chain length. When any one of these is absent, the failure does not manifest as misattribution. If fan-out is homogeneous, critical path and budget path coincide. If telemetry preserves own-vs-descendant cost, budget attribution is recoverable post hoc. If critical path is computed correctly, the serial-chain breach is caught at the chain, not the leaf. The invariant that must hold: **for every task graph, the observability record must carry (a) the cumulative-duration critical path as an ordered span list, (b) the top-k spans by own-token consumption, and (c) the explicit join semantics (parallel vs serial) at every internal node.** Without (c), neither (a) nor (b) can be recomputed after the fact, because the span tree alone does not distinguish a 12-span serial chain from a 12-way parallel fan-in that happened to serialize under a lock. ## Decision Boundary The boundary is this: **attribute an SLO breach to a span only if that span is on the critical path AND its own-cost (not rolled-up cost) exceeds its subtree's median span cost by the breach margin.** Otherwise the breach is structural — it belongs to an internal join node or to the aggregation logic, not to any leaf. Concretely, when a latency SLO fires: - Compute the critical path as the max over root-to-leaf cumulative durations. If the breach is on a serial chain of length L, the breach is owned by the *chain's parent join node*, and the remediation is span-count reduction, not per-call tuning. - If the breach is on a single span whose duration exceeds the SLO margin on its own, attribute to that span. - If neither — the breach is distributed across the fan-out — the SLO definition itself is wrong for this graph shape and must be re-scoped to per-subtree budgets. When a token-cost SLO fires: - Rank spans by own-token consumption, not rolled-up. If the top span's own cost is under 30% of the budget, the overrun is diffuse and the remediation is context-window discipline across the subtree, not a single-call fix. - If the top span's own cost exceeds the budget by itself, attribute to that span and check for cache-miss or re-fetch pathologies (the retrieval re-fetch above is the canonical case). The decision boundary is not a threshold on the SLO value. It is a threshold on the *concentration* of the breach across spans. A breach concentrated in one span is a span bug. A breach distributed across a chain is a topology bug. A breach distributed across a fan-out is a budget-model bug. These require three different fixes and the taxonomy must separate them before remediation begins. ## Operational Effect The operational consequence is that SLO dashboards built on rolled-up parent spans produce *anti-signal*: they point operators at the highest-numbered span, which is always the root, which is never the cause. Teams that trust these dashboards converge on root-level caps and per-call ceiling raises — both of which suppress the symptom while leaving the topology that generates it intact. The serial-verifier pattern survives a root cap because the cap truncates the *retrieval* subtree (the high-token one) and leaves the verifier chain untouched; the next task graph then fails verification silently because the truncated context passed a schema-only check. The corrective is to make the observability record carry the three fields named in the Condition of Validity, and to make the SLO evaluator refuse to emit an attribution unless the concentration test passes. An unattributed breach is more useful than a misattributed one: it forces the operator to read the graph shape rather than the top-line number. The failure-mode taxonomy that follows from this is three-valued — span-concentrated, chain-distributed, fanout-distributed — and each value maps to a distinct remediation class. Collapsing the taxonomy to a single "SLO breached" event is the mechanism by which the misattribution propagates from telemetry into incident response and back into the system as a wrong fix. ```python from dataclasses import dataclass, field from typing import Optional class MisattributedSLOTelemetry(RuntimeError): """Raised when an SLO breach cannot be attributed to a single span because the telemetry lacks own-vs-descendant cost separation or join semantics, or because the breach is structural (chain/fanout).""" pass @dataclass class Span: span_id: str parent_id: Optional[str] duration_s: float own_tokens: int rolled_tokens: int # includes descendants; -1 if not rolled up join: str = "serial" # "serial" | "parallel" at this node children: list = field(default_factory=list) def attribute_latency_breach(root: Span, slo_s: float) -> str: # Critical path = max root-to-leaf cumulative duration. def critical_path(span, acc): acc = acc + span.duration_s if not span.children: return acc, [span.span_id] best = (0.0, []) for c in span.children: d, path = critical_path(c, acc) if d > best[0]: best = (d, path) return best total, path = critical_path(root, 0.0) if total <= slo_s: return "no-breach" # Concentration test: is the breach owned by a single span on the path? span_by_id = {s.span_id: s for s in _walk(root)} leaf = span_by_id[path[-1]] if leaf.duration_s >= (total - slo_s) and len(path) == 2: return f"span-concentrated:{leaf.span_id}" # If the path passes through a serial chain of length > 2, the breach # is owned by the chain's parent join node, not any leaf. if len(path) > 2: parent = span_by_id[path[-2]] if parent.join == "serial": raise MisattributedSLOTelemetry( f"latency breach on serial chain of length {len(path)}; " f"owning node is join {parent.span_id}, not leaf {leaf.span_id}" ) return f"fanout-distributed:path={path}" def attribute_token_breach(root: Span, budget: int) -> str: if root.rolled_tokens < 0: raise MisattributedSLOTelemetry( "token rollup missing; cannot separate own vs descendant cost" ) spans = _walk(root) top = max(spans, key=lambda s: s.own_tokens) overrun = root.rolled_tokens - budget if overrun <= 0: return "no-breach" if top.own_tokens >= overrun: # Check for re-fetch pathology: same span_id prefix fetched twice. return f"span-concentrated:{top.span_id}:own={top.own_tokens}" if top.own_tokens < 0.3 * budget: raise MisattributedSLOTelemetry( f"token overrun {overrun} is diffuse; top span {top.span_id} " f"owns only {top.own_tokens}/{budget}; remediation is subtree " f"context discipline, not a single-call cap" ) return f"chain-distributed:top={top.span_id}" def _walk(span): yield span for c in span.children: yield from _walk(c) ```